Search in sources :

Example 51 with SSOTokenContext

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

the class SubjectTypesResourceTest method shouldThrowErrorWthInvalidCondition.

@Test
public void shouldThrowErrorWthInvalidCondition() throws JsonMappingException {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    ReadRequest mockRequest = mock(ReadRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, "invalidCondition", mockRequest);
    //then
    assertThat(promise).failedWithException().isInstanceOf(NotFoundException.class);
}
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) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 52 with SSOTokenContext

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

the class SubjectTypesResourceTest method testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved.

@Test
public void testSuccessfulJsonificationAndReadAndSubjectNamePropertyRemoved() throws Exception {
    //given
    SSOTokenContext mockSubjectContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSubjectContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSubjectContext.getCallerSubject()).willReturn(mockSubject);
    ReadRequest mockRequest = mock(ReadRequest.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
    //then
    assertThat(promise).succeeded().withContent().hasString("title");
    assertThat(promise).succeeded().withContent().stringAt("title").isEqualTo(TEST_CONDITION_WITH_NAME);
    assertThat(promise).succeeded().withContent().hasBoolean("logical");
    assertThat(promise).succeeded().withContent().booleanAt("logical").isFalse();
    assertThat(promise.get().getContent().get("config").getObject().toString()).isEqualTo("{\"type\":\"object\",\"properties\":{}}");
}
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) ResourceResponse(org.forgerock.json.resource.ResourceResponse) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) EntitlementSubject(com.sun.identity.entitlement.EntitlementSubject) Subject(javax.security.auth.Subject) LogicalSubject(com.sun.identity.entitlement.LogicalSubject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 53 with SSOTokenContext

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

the class STSPublishServiceAuthzModule method isSoapSTSAgent.

private boolean isSoapSTSAgent(Context context) throws ResourceException {
    SSOTokenContext tokenContext = context.asContext(SSOTokenContext.class);
    String userId;
    SSOToken token;
    try {
        token = tokenContext.getCallerSSOToken();
        userId = token.getPrincipal().getName();
    } catch (SSOException e) {
        if (debug.messageEnabled()) {
            debug.message("STSPublishServiceAuthzModule :: Unable to obtain SSOToken or principal", e);
        }
        throw ResourceException.getException(HttpURLConnection.HTTP_UNAUTHORIZED, e.getMessage());
    }
    if (agentIdentity.isSoapSTSAgent(token)) {
        if (debug.messageEnabled()) {
            debug.message("STSPublishServiceAuthzModule :: User " + userId + " accepted as Soap STS Agent.");
        }
        return true;
    } else {
        if (debug.messageEnabled()) {
            debug.message("STSPublishServiceAuthzModule :: User " + userId + " is not a Soap STS Agent.");
        }
        return false;
    }
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOException(com.iplanet.sso.SSOException)

Example 54 with SSOTokenContext

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

the class RestRouterIT method mockRequiredContexts.

private Context mockRequiredContexts() {
    final HttpContext httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("Accept-Language", Arrays.asList("en"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    SecurityContext securityContext = new SecurityContext(mockContext(httpContext), null, null);
    return new SSOTokenContext(mock(Debug.class), null, securityContext) {

        @Override
        public Subject getCallerSubject() {
            return new Subject();
        }

        @Override
        public SSOToken getCallerSSOToken() {
            SSOToken token = mock(SSOToken.class);
            try {
                given(token.getProperty(Constants.AM_CTX_ID)).willReturn("TRACKING_ID");
                given(token.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willReturn("USER_ID");
            } catch (SSOException e) {
            // won't happen - it's a mock
            }
            return token;
        }
    };
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) SSOException(com.iplanet.sso.SSOException) Debug(com.sun.identity.shared.debug.Debug) Subject(javax.security.auth.Subject)

Example 55 with SSOTokenContext

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

the class AdminOnlyAuthzModuleTest method shouldErrorInvalidContext.

@Test
public void shouldErrorInvalidContext() throws Exception {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    SSOToken mockSSOToken = mock(SSOToken.class);
    given(mockSSOTokenContext.getCallerSSOToken()).willReturn(mockSSOToken);
    given(mockSSOToken.getProperty(Constants.UNIVERSAL_IDENTIFIER)).willThrow(new SSOException(""));
    //when
    Promise<AuthorizationResult, ResourceException> result = testModule.authorize(mockSSOTokenContext);
    //then
    assertFalse(result.get().isAuthorized());
}
Also used : SSOToken(com.iplanet.sso.SSOToken) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOException(com.iplanet.sso.SSOException) ResourceException(org.forgerock.json.resource.ResourceException) AuthorizationResult(org.forgerock.authz.filter.api.AuthorizationResult) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

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