Search in sources :

Example 46 with SSOTokenContext

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

the class ResourceTypesResourceTest method setUp.

@BeforeMethod
public void setUp() throws ResourceException {
    callerSubject = new Subject();
    // to mock the HTTP method, we need the following contexts
    Context httpContext = new HttpContext(json(object(field(HttpContext.ATTR_HEADERS, Collections.singletonMap("method", Arrays.asList("PUT"))), field(HttpContext.ATTR_PARAMETERS, Collections.emptyMap()))), null);
    Context securityContext = new SecurityContext(httpContext, null, null);
    Context subjectContext = new SSOTokenContext(mock(Debug.class), null, securityContext) {

        @Override
        public Subject getCallerSubject() {
            return callerSubject;
        }
    };
    RealmContext realmContext = new RealmContext(subjectContext);
    realmContext.setSubRealm("/", "/");
    mockServerContext = ClientContext.newInternalClientContext(realmContext);
    resourceTypeService = mock(MockResourceTypeService.class);
    Debug debug = mock(Debug.class);
    resourceTypesResource = new ResourceTypesResource(debug, new EntitlementsExceptionMappingHandler(EntitlementRestGuiceModule.getEntitlementsErrorHandlers()), resourceTypeService);
    rawData.put("name", Collections.singleton("myResourceType"));
    rawData.put("description", Collections.singleton("myResourceType"));
    rawData.put("realm", Collections.singleton("/"));
    rawData.put("actions", Collections.singleton("CREATE"));
    rawData.put("patterns", Collections.singleton("http://example.com:80/*"));
    rawData.put("creationDate", Collections.singleton(String.valueOf(new Date().getTime())));
    rawData.put("lastModifiedDate", Collections.singleton(String.valueOf(new Date().getTime())));
}
Also used : SecurityContext(org.forgerock.services.context.SecurityContext) ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) HttpContext(org.forgerock.json.resource.http.HttpContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) HttpContext(org.forgerock.json.resource.http.HttpContext) SecurityContext(org.forgerock.services.context.SecurityContext) Subject(javax.security.auth.Subject) Debug(com.sun.identity.shared.debug.Debug) Date(java.util.Date) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 47 with SSOTokenContext

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

the class SubjectAttributesResourceV1Test method shouldPerformQueryForSubjectAttributes.

@Test
public void shouldPerformQueryForSubjectAttributes() throws Exception {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
    QueryRequest mockRequest = mock(QueryRequest.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    Set<String> attributes = new HashSet<>();
    attributes.add("attr");
    attributes.add("attr2");
    given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
    //when
    Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
    //then
    promise.getOrThrowUninterruptibly();
    ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
    verify(mockHandler, times(2)).handleResource(captor.capture());
}
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) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) Matchers.anyString(org.mockito.Matchers.anyString) Subject(javax.security.auth.Subject) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 48 with SSOTokenContext

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

the class SubjectTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.

@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() 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);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    JsonSchema mockSchema = mock(JsonSchema.class);
    given(mockMapper.generateJsonSchema((Class<?>) any(Class.class))).willReturn(mockSchema);
    //when
    Promise<ResourceResponse, ResourceException> promise = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
    //then
    assertThat(promise).succeeded().withContent().hasBoolean("logical");
    assertThat(promise).succeeded().withContent().booleanAt("logical").isTrue();
}
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) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) 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 49 with SSOTokenContext

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

the class SubjectAttributesResourceV1Test method shouldErrorWhenAttributeRetrievalFails.

@Test
public void shouldErrorWhenAttributeRetrievalFails() throws EntitlementException {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
    QueryRequest mockRequest = mock(QueryRequest.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    given(mockSAM.getAvailableSubjectAttributeNames()).willThrow(new EntitlementException(401));
    //when
    Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
    //then
    verify(mockDebug, times(1)).error(anyString());
    assertThat(promise).failedWithResourceException().withCode(ResourceException.INTERNAL_ERROR);
}
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) EntitlementException(com.sun.identity.entitlement.EntitlementException) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test)

Example 50 with SSOTokenContext

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

the class SubjectAttributesResourceV1Test method shouldReturnNoResultWhenNoAttributes.

@Test
public void shouldReturnNoResultWhenNoAttributes() throws Exception {
    //given
    SSOTokenContext mockSSOTokenContext = mock(SSOTokenContext.class);
    RealmContext realmContext = new RealmContext(mockSSOTokenContext);
    Context mockServerContext = ClientContext.newInternalClientContext(realmContext);
    Subject mockSubject = new Subject();
    given(mockSSOTokenContext.getCallerSubject()).willReturn(mockSubject);
    QueryRequest mockRequest = mock(QueryRequest.class);
    QueryResourceHandler mockHandler = mock(QueryResourceHandler.class);
    Set<String> attributes = new HashSet<>();
    given(mockSAM.getAvailableSubjectAttributeNames()).willReturn(attributes);
    //when
    Promise<QueryResponse, ResourceException> promise = subjectAttributesResource.queryCollection(mockServerContext, mockRequest, mockHandler);
    //then
    promise.getOrThrowUninterruptibly();
    ArgumentCaptor<ResourceResponse> captor = ArgumentCaptor.forClass(ResourceResponse.class);
    verify(mockHandler, never()).handleResource(captor.capture());
}
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) RealmContext(org.forgerock.openam.rest.RealmContext) QueryRequest(org.forgerock.json.resource.QueryRequest) Matchers.anyString(org.mockito.Matchers.anyString) Subject(javax.security.auth.Subject) SSOTokenContext(org.forgerock.openam.rest.resource.SSOTokenContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) QueryResponse(org.forgerock.json.resource.QueryResponse) ResourceException(org.forgerock.json.resource.ResourceException) QueryResourceHandler(org.forgerock.json.resource.QueryResourceHandler) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

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