Search in sources :

Example 31 with SessionInfo

use of com.iplanet.dpro.session.share.SessionInfo in project OpenAM by OpenRock.

the class JwtSessionMapperTest method throwsExceptionIfSignatureVerificationOfPlaintextJwtFails.

@Test(expectedExceptions = JwtRuntimeException.class)
public void throwsExceptionIfSignatureVerificationOfPlaintextJwtFails() {
    // Given
    SessionInfo inputSessionInfo = newExampleSessionInfo();
    JwtSessionMapper jwtSessionMapper = new JwtSessionMapper(JwsAlgorithm.HS256, new SigningManager().newHmacSigningHandler("SHARED_SECRET".getBytes(Charset.forName("UTF-8"))), // Possibly a little kludgy but the code flow should be the same
    new SigningManager().newHmacSigningHandler("INVALID_KEY".getBytes(Charset.forName("UTF-8"))), null);
    // When
    String plaintextJwt = jwtSessionMapper.asJwt(inputSessionInfo);
    jwtSessionMapper.fromJwt(plaintextJwt);
// Then
// expect InvalidJwtException
}
Also used : SessionInfo(com.iplanet.dpro.session.share.SessionInfo) SigningManager(org.forgerock.json.jose.jws.SigningManager) Test(org.testng.annotations.Test)

Example 32 with SessionInfo

use of com.iplanet.dpro.session.share.SessionInfo in project OpenAM by OpenRock.

the class JwtSessionMapperTest method canRoundtripSessionInfoAsSignedEncryptedJwtUsingDifferentAlgs.

@Test
public void canRoundtripSessionInfoAsSignedEncryptedJwtUsingDifferentAlgs() throws IOException {
    // Given
    SessionInfo inputSessionInfo = newExampleSessionInfo();
    KeyPair keyPair = newKeyPair();
    JwtSessionMapper jwtSessionMapper = new JwtSessionMapperBuilder().signedUsingHS256("SHARED_SECRET").encryptedUsingKeyPair(keyPair).build();
    // When
    String jwtString = jwtSessionMapper.asJwt(inputSessionInfo);
    SessionInfo outputSessionInfo = jwtSessionMapper.fromJwt(jwtString);
    // Then
    assertEquals(inputSessionInfo, outputSessionInfo);
}
Also used : KeyPair(java.security.KeyPair) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) Test(org.testng.annotations.Test)

Example 33 with SessionInfo

use of com.iplanet.dpro.session.share.SessionInfo in project OpenAM by OpenRock.

the class Session method getValidSessions.

/**
     * Returns all the valid sessions for a particular Session Service URL. If a
     * user is not allowed to access the Sessions of the input Session Server,
     * it will return null.
     *
     * @param svcurl Session Service URL.
     * @exception SessionException
     */
private SearchResults getValidSessions(URL svcurl, String pattern) throws SessionException {
    try {
        int[] status = { 0 };
        List<SessionInfo> infos = null;
        boolean isLocal = false;
        if (sessionService != null && sessionService.isLocalSessionService(svcurl)) {
            infos = sessionService.getValidSessions(this, pattern, status);
            isLocal = true;
        } else {
            SessionRequest sreq = new SessionRequest(SessionRequest.GetValidSessions, sessionID.toString(), false);
            if (pattern != null) {
                sreq.setPattern(pattern);
            }
            SessionResponse sres = requests.getSessionResponseWithRetry(svcurl, sreq, this);
            infos = sres.getSessionInfo();
            status[0] = sres.getStatus();
        }
        Map<String, Session> sessions = new HashMap<String, Session>();
        Session session = null;
        for (SessionInfo info : infos) {
            SessionID sid = new SessionID(info.getSessionID());
            session = new Session(sid, isLocal);
            session.sessionServiceURL = svcurl;
            session.update(info);
            sessions.put(info.getSessionID(), session);
        }
        return new SearchResults(sessions.size(), sessions.keySet(), status[0], sessions);
    } catch (Exception ex) {
        sessionDebug.error("Session:getValidSession : ", ex);
        throw new SessionException(SessionBundle.rbName, "getValidSessionsError", null);
    }
}
Also used : HashMap(java.util.HashMap) SessionInfo(com.iplanet.dpro.session.share.SessionInfo) SearchResults(com.sun.identity.common.SearchResults) SessionRequest(com.iplanet.dpro.session.share.SessionRequest) ThreadPoolException(com.iplanet.am.util.ThreadPoolException) SSOException(com.iplanet.sso.SSOException) SessionResponse(com.iplanet.dpro.session.share.SessionResponse)

Example 34 with SessionInfo

use of com.iplanet.dpro.session.share.SessionInfo in project OpenAM by OpenRock.

the class SessionNotificationHandler method processNotification.

/**
     * Process the notification.
     *
     * @param snot Session Notification object.
     */
private void processNotification(SessionNotification snot, boolean isLocal) {
    SessionInfo info = snot.getSessionInfo();
    sessionDebug.message("SESSION NOTIFICATION : " + info.toXMLString());
    if (!info.getState().equals("valid")) {
        if (isLocal) {
            sessionCache.removeLocalSID(info);
        } else {
            sessionCache.removeRemoteSID(info);
        }
        return;
    }
    SessionID sid = new SessionID(info.getSessionID());
    Session session = sessionCache.readSession(sid);
    try {
        if (session == null) {
            // a new session is created
            return;
        }
        session.update(info);
    } catch (Exception e) {
        sessionDebug.error("SessionNotificationHandler:processNotification : ", e);
        sessionCache.removeSID(sid);
        return;
    }
    SessionEvent evt = new SessionEvent(session, snot.getNotificationType(), snot.getNotificationTime());
    SessionEvent.invokeListeners(evt);
}
Also used : SessionInfo(com.iplanet.dpro.session.share.SessionInfo)

Example 35 with SessionInfo

use of com.iplanet.dpro.session.share.SessionInfo in project OpenAM by OpenRock.

the class MonitoredOperations method refresh.

/**
     * {@inheritDoc}
     */
@Override
public SessionInfo refresh(Session session, boolean reset) throws SessionException {
    final long start = System.nanoTime();
    final SessionInfo response = sessionOperations.refresh(session, reset);
    sessionMonitoringStore.storeRefreshTime(System.nanoTime() - start, monitorType);
    return response;
}
Also used : SessionInfo(com.iplanet.dpro.session.share.SessionInfo)

Aggregations

SessionInfo (com.iplanet.dpro.session.share.SessionInfo)42 Test (org.testng.annotations.Test)18 SessionException (com.iplanet.dpro.session.SessionException)8 SessionID (com.iplanet.dpro.session.SessionID)6 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)5 SessionRequest (com.iplanet.dpro.session.share.SessionRequest)4 InternalSession (com.iplanet.dpro.session.service.InternalSession)3 Session (com.iplanet.dpro.session.Session)2 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)2 SSOException (com.iplanet.sso.SSOException)2 URL (java.net.URL)2 KeyPair (java.security.KeyPair)2 HashMap (java.util.HashMap)2 SigningManager (org.forgerock.json.jose.jws.SigningManager)2 StatelessSession (org.forgerock.openam.sso.providers.stateless.StatelessSession)2 ThreadPoolException (com.iplanet.am.util.ThreadPoolException)1 SessionTimedOutException (com.iplanet.dpro.session.SessionTimedOutException)1 SessionOperations (com.iplanet.dpro.session.operations.SessionOperations)1 Action (com.iplanet.services.naming.ServiceListeners.Action)1 SSOToken (com.iplanet.sso.SSOToken)1