Search in sources :

Example 11 with Context

use of org.forgerock.services.context.Context 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 12 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class SessionResourceTest method actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet.

@Test
public void actionCollectionShouldFailToValidateSessionWhenSSOTokenIdNotSet() {
    //Given
    final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
    final Context context = ClientContext.newInternalClientContext(tokenContext);
    final ActionRequest request = mock(ActionRequest.class);
    given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
    //Then
    assertThat(promise).failedWithException().isInstanceOf(BadRequestException.class);
}
Also used : 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) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Test(org.testng.annotations.Test)

Example 13 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class SessionResourceTest method actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid.

@Test
public void actionCollectionShouldLogoutSessionAndReturnEmptyJsonObjectWhenSSOTokenValid() throws SSOException {
    //Given
    cookieResponse = "SSO_TOKEN_ID";
    final AttributesContext attrContext = new AttributesContext(new SessionContext(new RootContext(), mock(Session.class)));
    final AdviceContext adviceContext = new AdviceContext(attrContext, Collections.<String>emptySet());
    final SecurityContext securityContext = new SecurityContext(adviceContext, null, null);
    final Context context = ClientContext.newInternalClientContext(new SSOTokenContext(mock(Debug.class), null, securityContext));
    final ActionRequest request = mock(ActionRequest.class);
    final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(request.getAction()).willReturn(LOGOUT_ACTION_ID);
    given(authUtilsWrapper.logout(ssoTokenId.toString(), null, null)).willReturn(true);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
    //Then
    assertThat(promise).succeeded().withContent().stringAt("result").isEqualTo("Successfully logged out");
}
Also used : RootContext(org.forgerock.services.context.RootContext) 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) SSOTokenID(com.iplanet.sso.SSOTokenID) AttributesContext(org.forgerock.services.context.AttributesContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SecurityContext(org.forgerock.services.context.SecurityContext) SessionContext(org.forgerock.http.session.SessionContext) Test(org.testng.annotations.Test)

Example 14 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class SessionResourceTest method actionInstanceShouldBeActiveWhenSSOTokenValid.

@Test
public void actionInstanceShouldBeActiveWhenSSOTokenValid() throws SSOException {
    //Given
    final Context context = mock(Context.class);
    final String resourceId = "SSO_TOKEN_ID";
    final ActionRequest request = mock(ActionRequest.class);
    final SSOToken ssoToken = mock(SSOToken.class);
    given(request.getAction()).willReturn(IS_ACTIVE_ACTION_ID);
    given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
    given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).succeeded().withContent().booleanAt("active").isTrue();
}
Also used : 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) Test(org.testng.annotations.Test)

Example 15 with Context

use of org.forgerock.services.context.Context in project OpenAM by OpenRock.

the class SessionResourceTest method actionInstanceShouldGiveIdleTimeWhenSSOTokenValid.

@Test
public void actionInstanceShouldGiveIdleTimeWhenSSOTokenValid() throws SSOException {
    final int IDLE = 50;
    //Given
    final Context context = mock(Context.class);
    final String resourceId = "SSO_TOKEN_ID";
    final ActionRequest request = mock(ActionRequest.class);
    final SSOToken ssoToken = mock(SSOToken.class);
    given(request.getAction()).willReturn(GET_IDLE_ACTION_ID);
    given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
    given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(true);
    given(ssoToken.getIdleTime()).willReturn((long) IDLE);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).succeeded().withContent().integerAt("idletime").isEqualTo(IDLE);
}
Also used : 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) Test(org.testng.annotations.Test)

Aggregations

Context (org.forgerock.services.context.Context)250 Test (org.testng.annotations.Test)231 RealmContext (org.forgerock.openam.rest.RealmContext)150 ResourceException (org.forgerock.json.resource.ResourceException)132 ClientContext (org.forgerock.services.context.ClientContext)120 SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)101 ResourceResponse (org.forgerock.json.resource.ResourceResponse)82 SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)76 RootContext (org.forgerock.services.context.RootContext)62 JsonValue (org.forgerock.json.JsonValue)56 QueryRequest (org.forgerock.json.resource.QueryRequest)54 ReadRequest (org.forgerock.json.resource.ReadRequest)50 AttributesContext (org.forgerock.services.context.AttributesContext)44 ActionRequest (org.forgerock.json.resource.ActionRequest)43 QueryResponse (org.forgerock.json.resource.QueryResponse)43 Subject (javax.security.auth.Subject)42 Matchers.anyString (org.mockito.Matchers.anyString)38 Request (org.forgerock.http.protocol.Request)37 UpdateRequest (org.forgerock.json.resource.UpdateRequest)36 DeleteRequest (org.forgerock.json.resource.DeleteRequest)35