Search in sources :

Example 1 with SubjectContext

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

the class PolicyResourceEvaluationTest method shouldHandleUnknownAction.

@Test
public void shouldHandleUnknownAction() {
    // Given...
    given(request.getAction()).willReturn("unknownAction");
    // When...
    Context context = buildContextStructure("/abc");
    policyResource.actionCollection(context, request);
    // Then...
    verify(request).getAction();
    //verify(jsonHandler).handleError(isA(NotSupportedException.class));
    verifyNoMoreInteractions(request, subjectContext, requestFactory, policyRequest, factory, evaluator, parser);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) Test(org.testng.annotations.Test)

Example 2 with SubjectContext

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

the class PolicyRequestFactoryTest method shouldRetrieveBatchRequest.

@Test
public void shouldRetrieveBatchRequest() throws EntitlementException {
    // When...
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("resources", Arrays.asList("/resource/a", "/resource/b"));
    given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
    // Given...
    Context context = buildContextStructure("/abc");
    PolicyRequest request = factory.buildRequest(PolicyAction.EVALUATE, context, actionRequest);
    // Then...
    assertThat(request).isNotNull();
    assertThat(request.getRealm()).isEqualTo("/abc");
    assertThat(request).isInstanceOfAny(BatchPolicyRequest.class);
    BatchPolicyRequest batchRequest = (BatchPolicyRequest) request;
    assertThat(batchRequest.getResources()).containsOnly("/resource/a", "/resource/b");
    verify(subjectContext).getCallerSubject();
    verify(actionRequest, times(2)).getContent();
    verifyNoMoreInteractions(subjectContext, actionRequest);
}
Also used : Context(org.forgerock.services.context.Context) ClientContext(org.forgerock.services.context.ClientContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) HashMap(java.util.HashMap) BatchPolicyRequest(org.forgerock.openam.entitlement.rest.model.json.BatchPolicyRequest) TreePolicyRequest(org.forgerock.openam.entitlement.rest.model.json.TreePolicyRequest) PolicyRequest(org.forgerock.openam.entitlement.rest.model.json.PolicyRequest) BatchPolicyRequest(org.forgerock.openam.entitlement.rest.model.json.BatchPolicyRequest) Test(org.testng.annotations.Test)

Example 3 with SubjectContext

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

the class PolicyRequestTest method shouldDefaultToApplication.

@Test
public void shouldDefaultToApplication() throws EntitlementException {
    // Given...
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    Map<String, Object> properties = new HashMap<String, Object>();
    given(actionRequest.getContent()).willReturn(json(properties));
    // When...
    Context context = buildContextStructure("/abc");
    PolicyRequest request = getRequest(context, actionRequest);
    // Then...
    assertThat(request).isNotNull();
    assertThat(request.getApplication()).isEqualTo("iPlanetAMWebAgentService");
    verify(subjectContext).getCallerSubject();
    verify(actionRequest).getContent();
    verifyNoMoreInteractions(subjectContext, actionRequest);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 4 with SubjectContext

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

the class ConditionTypesResourceTest method testSuccessfulJsonificationAndReadAndNamePropertyRemoved.

@Test
public void testSuccessfulJsonificationAndReadAndNamePropertyRemoved() throws JsonMappingException, ExecutionException, InterruptedException {
    //given
    SubjectContext mockSubjectContext = mock(SubjectContext.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> result = testResource.readInstance(mockServerContext, TEST_CONDITION_WITH_NAME, mockRequest);
    //then
    Map resultMap = result.get().getContent().asMap();
    assertThat(resultMap.containsKey("title")).isTrue();
    assertThat(resultMap.containsKey("config")).isTrue();
    assertThat(resultMap.containsKey("logical")).isTrue();
    assertThat(resultMap.get("title")).isEqualTo(TEST_CONDITION_WITH_NAME);
    assertThat(resultMap.get("logical")).isEqualTo(false);
    assertThat(resultMap.get("config")).isInstanceOf(JsonSchema.class);
    JsonSchema resultSchema = (JsonSchema) resultMap.get("config");
    assertThat(resultSchema.toString().equals("{\"type\":\"object\",\"properties\":{}}")).isTrue();
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) Map(java.util.Map) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Example 5 with SubjectContext

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

the class ConditionTypesResourceTest method testSuccessfulJsonificationAndLogicalIsCorrect.

@Test
public void testSuccessfulJsonificationAndLogicalIsCorrect() throws JsonMappingException, ExecutionException, InterruptedException {
    //given
    SubjectContext mockSubjectContext = mock(SubjectContext.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> result = testResource.readInstance(mockServerContext, TEST_LOGICAL_CONDITION, mockRequest);
    //then
    Map resultMap = result.get().getContent().asMap();
    assertThat(resultMap.containsKey("logical")).isTrue();
    assertThat(resultMap.get("logical")).isEqualTo(true);
}
Also used : ClientContext(org.forgerock.services.context.ClientContext) RealmContext(org.forgerock.openam.rest.RealmContext) Context(org.forgerock.services.context.Context) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) RealmContext(org.forgerock.openam.rest.RealmContext) ResourceResponse(org.forgerock.json.resource.ResourceResponse) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) JsonSchema(com.fasterxml.jackson.databind.jsonschema.JsonSchema) ResourceException(org.forgerock.json.resource.ResourceException) Map(java.util.Map) Subject(javax.security.auth.Subject) ReadRequest(org.forgerock.json.resource.ReadRequest) Test(org.testng.annotations.Test)

Aggregations

SubjectContext (org.forgerock.openam.rest.resource.SubjectContext)33 RealmContext (org.forgerock.openam.rest.RealmContext)31 Test (org.testng.annotations.Test)28 Context (org.forgerock.services.context.Context)27 ClientContext (org.forgerock.services.context.ClientContext)18 ResourceException (org.forgerock.json.resource.ResourceException)15 ResourceResponse (org.forgerock.json.resource.ResourceResponse)12 HashMap (java.util.HashMap)10 DelegationPermission (com.sun.identity.delegation.DelegationPermission)9 FilterChain (org.forgerock.json.resource.FilterChain)9 Router (org.forgerock.json.resource.Router)9 HashSet (java.util.HashSet)8 Subject (javax.security.auth.Subject)8 JsonValue (org.forgerock.json.JsonValue)8 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonSchema (com.fasterxml.jackson.databind.jsonschema.JsonSchema)7 ReadRequest (org.forgerock.json.resource.ReadRequest)6 SSOToken (com.iplanet.sso.SSOToken)4 ActionResponse (org.forgerock.json.resource.ActionResponse)4 Map (java.util.Map)3