Search in sources :

Example 6 with Context

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

the class SessionResourceTest method actionInstanceShouldReturnNotSupportedForUnknownAction.

@Test
public void actionInstanceShouldReturnNotSupportedForUnknownAction() throws SSOException {
    //Given
    final Context context = mock(Context.class);
    final String resourceId = "SSO_TOKEN_ID";
    final ActionRequest request = mock(ActionRequest.class);
    given(request.getAction()).willReturn("unknown-action");
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).failedWithException().isExactlyInstanceOf(NotSupportedException.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) Test(org.testng.annotations.Test)

Example 7 with Context

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

the class SessionResourceTest method actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid.

@Test
public void actionCollectionShouldValidateSessionAndReturnTrueWhenSSOTokenValid() throws SSOException {
    //Given
    cookieResponse = "SSO_TOKEN_ID";
    final SSOTokenContext tokenContext = mock(SSOTokenContext.class);
    final Context context = ClientContext.newInternalClientContext(tokenContext);
    final ActionRequest request = mock(ActionRequest.class);
    final SSOToken ssoToken = mock(SSOToken.class);
    final SSOTokenID ssoTokenId = mock(SSOTokenID.class);
    given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
    given(tokenContext.getCallerSSOToken()).willReturn(ssoToken);
    given(ssoTokenManager.isValidToken(ssoToken)).willReturn(true);
    given(ssoToken.getTokenID()).willReturn(ssoTokenId);
    given(ssoTokenId.toString()).willReturn("SSO_TOKEN_ID");
    given(ssoTokenManager.createSSOToken(ssoTokenId.toString())).willReturn(ssoToken);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionCollection(context, request);
    //Then
    assertThat(promise).succeeded().withContent().booleanAt("valid").isTrue();
    assertThat(promise).succeeded().withContent().stringAt("uid").isEqualTo("demo");
    assertThat(promise).succeeded().withContent().stringAt("realm").isEqualTo("/");
}
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) SSOTokenID(com.iplanet.sso.SSOTokenID) SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Test(org.testng.annotations.Test)

Example 8 with Context

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

the class SessionResourceTest method actionInstanceShouldBeInactiveWhenSSOTokenInvalid.

@Test
public void actionInstanceShouldBeInactiveWhenSSOTokenInvalid() 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(false);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).succeeded().withContent().booleanAt("active").isFalse();
}
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 9 with Context

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

the class SessionResourceTest method actionInstanceShouldGiveMinusOneForIdleTimeWhenSSOTokenInvalid.

@Test
public void actionInstanceShouldGiveMinusOneForIdleTimeWhenSSOTokenInvalid() 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(GET_IDLE_ACTION_ID);
    given(ssoTokenManager.retrieveValidTokenWithoutResettingIdleTime("SSO_TOKEN_ID")).willReturn(ssoToken);
    given(ssoTokenManager.isValidToken(ssoToken, false)).willReturn(false);
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).succeeded().withContent().integerAt("idletime").isEqualTo(-1);
}
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 10 with Context

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

the class SessionResourceTest method actionInstanceShouldValidateSessionAndReturnTrueWhenSSOTokenValid.

@Test
public void actionInstanceShouldValidateSessionAndReturnTrueWhenSSOTokenValid() 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);
    final Principal principal = mock(Principal.class);
    given(request.getAction()).willReturn(VALIDATE_ACTION_ID);
    given(ssoTokenManager.createSSOToken("SSO_TOKEN_ID")).willReturn(ssoToken);
    given(ssoTokenManager.isValidToken(ssoToken)).willReturn(true);
    given(ssoToken.getPrincipal()).willReturn(principal);
    given(principal.getName()).willReturn("PRINCIPAL");
    //When
    Promise<ActionResponse, ResourceException> promise = sessionResource.actionInstance(context, resourceId, request);
    //Then
    assertThat(promise).succeeded().withContent().booleanAt("valid").isTrue();
    assertThat(promise).succeeded().withContent().stringAt("uid").isEqualTo("demo");
    assertThat(promise).succeeded().withContent().stringAt("realm").isEqualTo("/");
}
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) Principal(java.security.Principal) 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