Search in sources :

Example 26 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class ApplicationsResourceTest method reservedInternalAppIsMappedDuringQuery.

@Test
public void reservedInternalAppIsMappedDuringQuery() throws EntitlementException, IllegalAccessException, InstantiationException {
    // Override the creation of the application wrapper so to return a mocked version.
    applicationsResource = new ApplicationsResource(debug, applicationManagerWrapper, applicationTypeManagerWrapper, queryAttributes, resourceErrorHandler) {

        @Override
        protected ApplicationWrapper createApplicationWrapper(Application application, ApplicationTypeManagerWrapper type) {
            ApplicationWrapper wrapper = mock(ApplicationWrapper.class);
            String appName = application.getName();
            given(wrapper.getName()).willReturn(appName);
            try {
                JsonValue jsonValue = JsonValueBuilder.jsonValue().put("name", "agentProtectedApplication").build();
                given(wrapper.toJsonValue()).willReturn(jsonValue);
            } catch (EntitlementException e) {
                fail();
            }
            return wrapper;
        }
    };
    // Given...
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    realmContext.setSubRealm("abc", "abc");
    Context serverContext = ClientContext.newInternalClientContext(realmContext);
    QueryRequest request = mock(QueryRequest.class);
    given(request.getSortKeys()).willReturn(Arrays.asList(SortKey.ascendingOrder("name")));
    Subject subject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(subject);
    Set<String> appNames = asSet("iPlanetAMWebAgentService");
    given(applicationManagerWrapper.search(eq(subject), eq("/abc"), any(Set.class))).willReturn(appNames);
    Application app = mock(Application.class);
    given(applicationManagerWrapper.getApplication(eq(subject), eq("/abc"), eq("iPlanetAMWebAgentService"))).willReturn(app);
    given(app.getName()).willReturn("agentProtectedApplication");
    QueryResourceHandler handler = mock(QueryResourceHandler.class);
    given(handler.handleResource(any(ResourceResponse.class))).willReturn(true);
    // When...
    applicationsResource.queryCollection(serverContext, request, handler);
    // Then...
    verify(applicationManagerWrapper).search(eq(subject), eq("/abc"), any(Set.class));
    verify(applicationManagerWrapper).getApplication(eq(subject), eq("/abc"), anyString());
    ArgumentCaptor<ResourceResponse> resourceCapture = ArgumentCaptor.forClass(ResourceResponse.class);
    verify(handler).handleResource(resourceCapture.capture());
    ResourceResponse resource = resourceCapture.getValue();
    assertThat(resource.getId()).isEqualTo("agentProtectedApplication");
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) Context(org.forgerock.services.context.Context) Set(java.util.Set) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) ApplicationTypeManagerWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationTypeManagerWrapper) JsonValue(org.forgerock.json.JsonValue) Matchers.anyString(org.mockito.Matchers.anyString) Subject(javax.security.auth.Subject) EntitlementException(com.sun.identity.entitlement.EntitlementException) ApplicationWrapper(org.forgerock.openam.entitlement.rest.wrappers.ApplicationWrapper) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Application(com.sun.identity.entitlement.Application) Test(org.testng.annotations.Test)

Example 27 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class TrustedDevicesResourceTest method ctx.

private Context ctx() {
    SSOTokenContext ssoTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(ssoTokenContext);
    Context serverContext = ClientContext.newInternalClientContext(realmContext);
    return serverContext;
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext)

Example 28 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext 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 29 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class CoreTokenResourceAuthzModuleTest method shouldBlockAllAccessIfResourceDisabled.

@Test
public void shouldBlockAllAccessIfResourceDisabled() throws Exception {
    //given
    CoreTokenResourceAuthzModule testModule = new CoreTokenResourceAuthzModule(mockConfig, mockDebug, false);
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    //when
    Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
    //then
    assertFalse(result.get().isAuthorized());
}
Also used : SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 30 with SSOTokenContext

use of org.forgerock.openam.rest.resource.SSOTokenContext in project OpenAM by OpenRock.

the class OathDevicesResourceTest method ctx.

private Context ctx() throws SSOException {
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    given(mockSubjectContext.getCallerSSOToken()).willReturn(mock(SSOToken.class));
    return ClientContext.newInternalClientContext(new RealmContext(mock(SSOTokenContext.class)));
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext)

Aggregations

SSOTokenContext (org.forgerock.openam.rest.resource.SSOTokenContext)62 Test (org.testng.annotations.Test)52 ResourceException (org.forgerock.json.resource.ResourceException)43 RealmContext (org.forgerock.openam.rest.RealmContext)43 Context (org.forgerock.services.context.Context)39 Subject (javax.security.auth.Subject)38 ClientContext (org.forgerock.services.context.ClientContext)37 ResourceResponse (org.forgerock.json.resource.ResourceResponse)33 Matchers.anyString (org.mockito.Matchers.anyString)21 SSOToken (com.iplanet.sso.SSOToken)17 Application (com.sun.identity.entitlement.Application)16 EntitlementException (com.sun.identity.entitlement.EntitlementException)14 JsonValue (org.forgerock.json.JsonValue)13 BeforeTest (org.testng.annotations.BeforeTest)12 AuthorizationResult (org.forgerock.authz.filter.api.AuthorizationResult)11 QueryResourceHandler (org.forgerock.json.resource.QueryResourceHandler)9 QueryRequest (org.forgerock.json.resource.QueryRequest)8 Principal (java.security.Principal)7 CreateRequest (org.forgerock.json.resource.CreateRequest)7 QueryResponse (org.forgerock.json.resource.QueryResponse)7