72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * The contents of this file are subject to the terms of the Common Development and
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Distribution License (the License). You may not use this file except in compliance with the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * specific language governing permission and limitations under the License.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * When distributing Covered Software, include this CDDL Header Notice in each file and include
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Header, with the fields enclosed by brackets [] replaced by your own identifying
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * information: "Portions copyright [year] [name of copyright owner]".
67486d6b1ecf210ee0fba21ef9298f4fb6213d2cTom Rumsey * Copyright 2014-2016 ForgeRock AS.
67486d6b1ecf210ee0fba21ef9298f4fb6213d2cTom Rumseyimport org.forgerock.openam.session.SessionConstants;
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Maddenimport org.forgerock.openam.sso.providers.stateless.StatelessSessionManager;
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnellimport com.iplanet.dpro.session.monitoring.MonitoredOperations;
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnellimport com.iplanet.dpro.session.monitoring.SessionMonitorType;
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnellimport com.iplanet.dpro.session.monitoring.SessionMonitoringStore;
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnellimport com.iplanet.dpro.session.operations.strategies.LocalOperations;
d0da70ccbba38b773e7a7cc71bc124b06206d201Robert Wapshottimport com.iplanet.dpro.session.operations.strategies.StatelessOperations;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Server based SessionOperationStrategy implementation.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * SessionOperations represent the available operations that can be performed on a Session,
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * which are applicable under a number of situations. These situations correspond to the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * number of situations Sessions can find themselves in.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * This strategy covers the following:
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * <b>local</b> - The Session is based on the current server and that server is responsible for
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * processing the request.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * <b>remote</b> - The Session is based on a remote server which will service the request and
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * respond with an appropriate response. This is performed by using a remote request and the
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * PLL signalling system.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * <b>CTS</b> - The Session is a remote session, however the Site appears to be down. The request
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * will be performed locally using the CTS instead.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Between these strategies, the users Session should be available during fail-over of a Site.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshottpublic class ServerSessionOperationStrategy implements SessionOperationStrategy {
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Madden private final StatelessSessionManager statelessSessionManager;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Guice initialised constructor.
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnell * @param local Required strategy.
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnell * @param store The store for session monitoring information.
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Madden * @param statelessSessionManager Required for JWT checks.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param debug Required for logging.
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey final StatelessSessionManager statelessSessionManager,
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey final @Named(SessionConstants.SESSION_DEBUG) Debug debug) {
6309b849c2de831a0eaed9c27b5794bed9bd8fd1Neil Madden this.statelessSessionManager = statelessSessionManager;
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Based on the Session, determine the appropriate SessionOperations strategy to select.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Local - For local Sessions which are hosted on the current Server.
2210fc30709625f254e6a6d5dc89c3bfefa48816Robert Wapshott * Remote - The Session is from a remote Site, and the Site is up.
2210fc30709625f254e6a6d5dc89c3bfefa48816Robert Wapshott * CTS - When cross talk is disabled, or if the Session is from a remote Site, which is down.
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey * @param sessionID Non null SessionID to use.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @return A non null SessionOperations implementation to use.
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey public SessionOperations getOperation(SessionID sessionID) {
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey return logAndWrap(sessionID, stateless, SessionMonitorType.STATELESS);
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey return logAndWrap(sessionID, local, SessionMonitorType.LOCAL);
a0e1846310a8366b5f92bc83ddba747707d42f3bTom Rumsey private boolean isStateless(SessionID sessionID) {
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey return statelessSessionManager.containsJwt(sessionID);
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * Inline logging function.
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey * @param sessionID Non null.
72450cb9c2ca854c6d3479832c2738196c1d3282Robert Wapshott * @param op Non null operation selected.
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnell * @param type
cc7c18212481f5e9ee508afe2ffcaecb6b9330f5Craig McDonnell * @return {code op}, wrapped in a MonitoredOperations.
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey private SessionOperations logAndWrap(SessionID sessionID, SessionOperations op, SessionMonitorType type) {
a90aba9cbcbb8e7fe95e45590d853959efe0d354Tom Rumsey debug.message(sessionID + ": " + op.getClass().getSimpleName() + " selected.");