Search in sources :

Example 1 with Session

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

the class PrivilegeAuthzModuleTest method setUp.

@BeforeMethod
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    final Map<String, PrivilegeDefinition> definitions = new HashMap<>();
    definitions.put("evaluate", PrivilegeDefinition.getInstance("evaluate", PrivilegeDefinition.Action.READ));
    definitions.put("blowup", PrivilegeDefinition.getInstance("destroy", PrivilegeDefinition.Action.MODIFY));
    given(session.getClientDomain()).willReturn("/abc");
    given(token.getTokenID()).willReturn(tokenID);
    given(coreWrapper.convertOrgNameToRealmName("realmdn")).willReturn("/abc");
    given(sessionCache.getSession(any(SessionID.class))).willReturn(session);
    module = new PrivilegeAuthzModule(evaluator, definitions, factory, sessionCache, coreWrapper);
    Session session = mock(Session.class);
    given(subjectContext.getCallerSession()).willReturn(session);
    given(session.getClientDomain()).willReturn("realmdn");
}
Also used : HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) SessionID(com.iplanet.dpro.session.SessionID) Session(com.iplanet.dpro.session.Session) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with Session

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

the class SessionCache method removeSID.

/**
     * Removes the <code>SessionID</code> from session table.
     *
     * @param sid Session ID.
     */
public void removeSID(SessionID sid) {
    if (sid == null || sid.isNull()) {
        return;
    }
    Session session = readSession(sid);
    if (session != null) {
        long eventTime = System.currentTimeMillis();
        // remove from sessionTable if there is no purge delay or it has elapsed
        if (session.getPurgeAt() <= eventTime) {
            deleteSession(sid);
            session.cancel();
        }
        // ensure session has destroyed state and observers are notified (exactly once)
        if (session.getRemoved().compareAndSet(false, true)) {
            session.setState(DESTROYED);
            SessionEvent event = new SessionEvent(session, SessionEvent.DESTROY, eventTime);
            SessionEvent.invokeListeners(event);
        }
    }
}
Also used : SessionEvent(com.iplanet.dpro.session.SessionEvent) Session(com.iplanet.dpro.session.Session)

Example 3 with Session

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

the class SessionCookies method getLBCookie.

/**
     * Returns load balancer cookie value for the Session.
     * @param  sid Session ID for load balancer cookie.
     * @return load balancer cookie value.
     * @throws SessionException if session is invalid.
     */
public String getLBCookie(SessionID sid) throws SessionException {
    String cookieValue = null;
    lbCookieName = SystemProperties.get(Constants.AM_LB_COOKIE_NAME, "amlbcookie");
    if (sessionDebug.messageEnabled()) {
        sessionDebug.message("Session.getLBCookie()" + "lbCookieName is:" + lbCookieName);
    }
    if (sid == null || StringUtils.isBlank(sid.toString())) {
        throw new SessionException(SessionBundle.rbName, "invalidSessionID", null);
    }
    if (SystemProperties.isServerMode()) {
        SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
        if (!sessionService.isSiteEnabled()) {
            cookieValue = WebtopNaming.getLBCookieValue(sid.getSessionServerID());
            return lbCookieName + "=" + cookieValue;
        }
    }
    if (RESET_LB_COOKIE_NAME) {
        if (SystemProperties.isServerMode()) {
            SessionService sessionService = InjectorHolder.getInstance(SessionService.class);
            if (sessionService.isSessionFailoverEnabled() && sessionService.isLocalSite(sid)) {
                cookieValue = WebtopNaming.getLBCookieValue(sessionService.getCurrentHostServer(sid));
            }
        } else {
            Session sess = sessionCache.readSession(sid);
            if (sess != null) {
                cookieValue = sess.getProperty(lbCookieName);
            }
        }
    }
    if (StringUtils.isBlank(cookieValue)) {
        cookieValue = WebtopNaming.getLBCookieValue(sid.getExtension().getPrimaryID());
    }
    return lbCookieName + "=" + cookieValue;
}
Also used : SessionService(com.iplanet.dpro.session.service.SessionService) SessionException(com.iplanet.dpro.session.SessionException) Session(com.iplanet.dpro.session.Session)

Example 4 with Session

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

the class MonitoredOperationsTest method setPropertyTest.

@Test
public void setPropertyTest() throws SessionException {
    //given
    Session mockSession = mock(Session.class);
    String name = "name";
    String value = "value";
    //when
    testMoniteredOperations.setProperty(mockSession, name, value);
    //then
    verify(mockSessionOperations, times(1)).setProperty(mockSession, name, value);
    verify(mockStore).storeSetPropertyTime(anyLong(), any(SessionMonitorType.class));
}
Also used : Session(com.iplanet.dpro.session.Session) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 5 with Session

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

the class MonitoredOperationsTest method logoutTest.

@Test
public void logoutTest() throws SessionException {
    //given
    Session mockSession = mock(Session.class);
    //when
    testMoniteredOperations.logout(mockSession);
    //then
    verify(mockSessionOperations, times(1)).logout(mockSession);
    verify(mockStore).storeLogoutTime(anyLong(), any(SessionMonitorType.class));
}
Also used : Session(com.iplanet.dpro.session.Session) BeforeTest(org.testng.annotations.BeforeTest) 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