Search in sources :

Example 26 with Session

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

the class AuthD method initAuthSession.

private Session initAuthSession() throws SSOException, SessionException {
    final Session authSession = getSessionService().getAuthenticationSession(defaultOrg, null);
    if (authSession == null) {
        debug.error("AuthD failed to get auth session");
        throw new SessionException(BUNDLE_NAME, "gettingSessionFailed", null);
    }
    String clientID = authSession.getClientID();
    authSession.setProperty("Principal", clientID);
    authSession.setProperty("Organization", defaultOrg);
    authSession.setProperty("Host", authSession.getID().getSessionServer());
    if (LDAPUtils.isDN(clientID)) {
        String id = "id=" + rdnValueFromDn(clientID) + ",ou=user," + ServiceManager.getBaseDN();
        authSession.setProperty(Constants.UNIVERSAL_IDENTIFIER, id);
    }
    return authSession;
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session) HttpSession(javax.servlet.http.HttpSession) InternalSession(com.iplanet.dpro.session.service.InternalSession)

Example 27 with Session

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

the class SessionCommand method getSessionList.

private List getSessionList(String name, String pattern) throws CLIException {
    IOutput output = getOutputWriter();
    List list = new ArrayList();
    try {
        String currentSessionHandler = curSession.getProperty(SESSION_HANDLE_PROP);
        SearchResults result = curSession.getValidSessions(name, null);
        String warning = getSearchResultWarningMessage(result);
        if (warning.length() > 0) {
            output.printlnMessage(warning);
        }
        Map<String, Session> sessions = (Map<String, Session>) result.getResultAttributes();
        boolean isCurrentSession = false;
        int i = 0;
        for (Iterator iter = (Iterator) sessions.values().iterator(); iter.hasNext(); ) {
            boolean isCurr = false;
            Session sess = (Session) iter.next();
            // need to check current session only if we have not found it.
            if (!isCurrentSession) {
                try {
                    isCurr = sess.getProperty(SESSION_HANDLE_PROP).equals(currentSessionHandler);
                } catch (SessionException se) {
                    throw new CLIException(se, ExitCodes.REQUEST_CANNOT_BE_PROCESSED);
                }
                isCurrentSession = isCurr;
            }
            String userId = sess.getProperty(USER_ID);
            if (userId != null) {
                userId = dnToName(userId);
                if (DisplayUtils.wildcardMatch(userId, pattern)) {
                    // -1 indicates that it is current session.
                    int idx = (isCurr) ? -1 : i++;
                    SessionData sData = createSessionData(idx, userId, sess);
                    if (idx == -1) {
                        list.add(0, sData);
                    } else {
                        list.add(sData);
                    }
                }
            }
        }
    } catch (SessionException se) {
        throw new CLIException(se, ExitCodes.INVALID_OPTION_VALUE);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) SessionException(com.iplanet.dpro.session.SessionException) SearchResults(com.sun.identity.common.SearchResults) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Session(com.iplanet.dpro.session.Session)

Example 28 with Session

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

the class StatelessOperationsTest method shouldCheckPermissionToDestroySession.

@Test
public void shouldCheckPermissionToDestroySession() throws Exception {
    // Given
    Session requester = mock(Session.class);
    // When
    statelessOperations.destroy(requester, mockSession);
    // Then
    verify(mockSessionService).checkPermissionToDestroySession(requester, sid);
}
Also used : Session(com.iplanet.dpro.session.Session) StatelessSession(org.forgerock.openam.sso.providers.stateless.StatelessSession) Test(org.testng.annotations.Test)

Example 29 with Session

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

the class StatelessOperationsTest method shouldNotBlacklistSessionOnDestroyIfNotAllowed.

@Test(expectedExceptions = SessionException.class, expectedExceptionsMessageRegExp = "test")
public void shouldNotBlacklistSessionOnDestroyIfNotAllowed() throws Exception {
    // Given
    Session requester = mock(Session.class);
    SessionException ex = new SessionException("test");
    willThrow(ex).given(mockSessionService).checkPermissionToDestroySession(requester, sid);
    // When
    try {
        statelessOperations.destroy(requester, mockSession);
    } finally {
        // Then
        verifyZeroInteractions(mockSessionBlacklist);
    }
}
Also used : SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session) StatelessSession(org.forgerock.openam.sso.providers.stateless.StatelessSession) Test(org.testng.annotations.Test)

Example 30 with Session

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

the class StatelessOperationsTest method shouldBlacklistSessionOnDestroyWhenAllowed.

@Test
public void shouldBlacklistSessionOnDestroyWhenAllowed() throws Exception {
    // Given
    Session requester = mock(Session.class);
    // When
    statelessOperations.destroy(requester, mockSession);
    // Then
    verify(mockSessionLogging).logEvent(mockSessionFactory.getSessionInfo(mockSession.getSessionID()), SessionEvent.DESTROY);
    verify(mockSessionBlacklist).blacklist(mockSession);
}
Also used : Session(com.iplanet.dpro.session.Session) StatelessSession(org.forgerock.openam.sso.providers.stateless.StatelessSession) Test(org.testng.annotations.Test)

Aggregations

Session (com.iplanet.dpro.session.Session)31 SessionException (com.iplanet.dpro.session.SessionException)22 SessionID (com.iplanet.dpro.session.SessionID)13 SSOException (com.iplanet.sso.SSOException)7 Test (org.testng.annotations.Test)7 Map (java.util.Map)5 InternalSession (com.iplanet.dpro.session.service.InternalSession)4 BeforeTest (org.testng.annotations.BeforeTest)4 SSOToken (com.iplanet.sso.SSOToken)3 SearchResults (com.sun.identity.common.SearchResults)3 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)3 HashMap (java.util.HashMap)3 StatelessSession (org.forgerock.openam.sso.providers.stateless.StatelessSession)3 URL (java.net.URL)2 Iterator (java.util.Iterator)2 SessionEvent (com.iplanet.dpro.session.SessionEvent)1 TokenRestriction (com.iplanet.dpro.session.TokenRestriction)1 SessionService (com.iplanet.dpro.session.service.SessionService)1 SessionInfo (com.iplanet.dpro.session.share.SessionInfo)1 SessionResponse (com.iplanet.dpro.session.share.SessionResponse)1