Search in sources :

Example 1 with SessionQueryManager

use of org.forgerock.openam.core.rest.session.query.SessionQueryManager in project OpenAM by OpenRock.

the class SessionResourceTest method setUp.

@BeforeMethod
public void setUp() throws IdRepoException, SSOException {
    SessionQueryManager sessionQueryManager = mock(SessionQueryManager.class);
    ssoTokenManager = mock(SSOTokenManager.class);
    authUtilsWrapper = mock(AuthUtilsWrapper.class);
    propertyWhitelist = mock(SessionPropertyWhitelist.class);
    headerResponse = null;
    urlResponse = null;
    cookieResponse = null;
    given(mockContext.getCallerSSOToken()).willReturn(ssoToken);
    realmContext = new RealmContext(mockContext);
    amIdentity = new AMIdentity(DN.valueOf("id=demo,dc=example,dc=com"), null);
    configureWhitelist();
    sessionResource = new SessionResource(sessionQueryManager, ssoTokenManager, authUtilsWrapper, propertyWhitelist) {

        @Override
        AMIdentity getIdentity(SSOToken ssoToken) throws IdRepoException, SSOException {
            return amIdentity;
        }

        @Override
        String convertDNToRealm(String dn) {
            return "/";
        }

        @Override
        protected String getTokenIdFromHeader(Context context, String cookieName) {
            return headerResponse;
        }

        @Override
        protected String getTokenIdFromUrlParam(ActionRequest request) {
            return urlResponse;
        }

        @Override
        protected String getTokenIdFromCookie(Context context, String cookieName) {
            return cookieResponse;
        }
    };
}
Also used : SSOTokenManager(com.iplanet.sso.SSOTokenManager) RootContext(org.forgerock.services.context.RootContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SessionContext(org.forgerock.http.session.SessionContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) AttributesContext(org.forgerock.services.context.AttributesContext) SecurityContext(org.forgerock.services.context.SecurityContext) Context(org.forgerock.services.context.Context) SSOToken(com.iplanet.sso.SSOToken) RealmContext(org.forgerock.openam.rest.RealmContext) SessionResource(org.forgerock.openam.core.rest.session.SessionResource) IdRepoException(com.sun.identity.idm.IdRepoException) SSOException(com.iplanet.sso.SSOException) SessionQueryManager(org.forgerock.openam.core.rest.session.query.SessionQueryManager) AuthUtilsWrapper(org.forgerock.openam.authentication.service.AuthUtilsWrapper) AMIdentity(com.sun.identity.idm.AMIdentity) SessionPropertyWhitelist(org.forgerock.openam.session.SessionPropertyWhitelist) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 2 with SessionQueryManager

use of org.forgerock.openam.core.rest.session.query.SessionQueryManager in project OpenAM by OpenRock.

the class SessionResourceTest method shouldUseSessionQueryManagerForAllSessionsQuery.

@Test
public void shouldUseSessionQueryManagerForAllSessionsQuery() {
    // Given
    String badger = "badger";
    String weasel = "weasel";
    SessionQueryManager mockManager = mock(SessionQueryManager.class);
    QueryRequest request = mock(QueryRequest.class);
    given(request.getQueryId()).willReturn(SessionResource.KEYWORD_ALL);
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    SessionResource resource = spy(new SessionResource(mockManager, null, null, null));
    List<String> list = Arrays.asList(badger, weasel);
    doReturn(list).when(resource).getAllServerIds();
    // When
    resource.queryCollection(null, request, handler);
    // Then
    List<String> result = Arrays.asList(badger, weasel);
    verify(mockManager, times(1)).getAllSessions(result);
}
Also used : SessionResource(org.forgerock.openam.core.rest.session.SessionResource) SessionQueryManager(org.forgerock.openam.core.rest.session.query.SessionQueryManager) Test(org.testng.annotations.Test)

Example 3 with SessionQueryManager

use of org.forgerock.openam.core.rest.session.query.SessionQueryManager in project OpenAM by OpenRock.

the class SessionResourceTest method shouldQueryNamedServerInServerMode.

@Test
public void shouldQueryNamedServerInServerMode() {
    // Given
    String badger = "badger";
    SessionQueryManager mockManager = mock(SessionQueryManager.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    QueryRequest request = mock(QueryRequest.class);
    given(request.getQueryId()).willReturn(badger);
    SessionResource resource = spy(new SessionResource(mockManager, null, null, null));
    // When
    resource.queryCollection(null, request, mockHandler);
    // Then
    verify(resource, times(0)).getAllServerIds();
    List<String> result = Collections.singletonList(badger);
    verify(mockManager, times(1)).getAllSessions(result);
}
Also used : SessionResource(org.forgerock.openam.core.rest.session.SessionResource) SessionQueryManager(org.forgerock.openam.core.rest.session.query.SessionQueryManager) Test(org.testng.annotations.Test)

Aggregations

SessionResource (org.forgerock.openam.core.rest.session.SessionResource)3 SessionQueryManager (org.forgerock.openam.core.rest.session.query.SessionQueryManager)3 Test (org.testng.annotations.Test)2 SSOException (com.iplanet.sso.SSOException)1 SSOToken (com.iplanet.sso.SSOToken)1 SSOTokenManager (com.iplanet.sso.SSOTokenManager)1 AMIdentity (com.sun.identity.idm.AMIdentity)1 IdRepoException (com.sun.identity.idm.IdRepoException)1 SessionContext (org.forgerock.http.session.SessionContext)1 AuthUtilsWrapper (org.forgerock.openam.authentication.service.AuthUtilsWrapper)1 RealmContext (org.forgerock.openam.rest.RealmContext)1 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)1 SessionPropertyWhitelist (org.forgerock.openam.session.SessionPropertyWhitelist)1 AttributesContext (org.forgerock.services.context.AttributesContext)1 ClientContext (org.forgerock.services.context.ClientContext)1 Context (org.forgerock.services.context.Context)1 RootContext (org.forgerock.services.context.RootContext)1 SecurityContext (org.forgerock.services.context.SecurityContext)1 BeforeMethod (org.testng.annotations.BeforeMethod)1