Search in sources :

Example 31 with SubjectContext

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

the class PolicyRequestFactoryTest method shouldRetrieveTreeRequest.

@Test
public void shouldRetrieveTreeRequest() throws EntitlementException {
    // When...
    given(subjectContext.getCallerSubject()).willReturn(restSubject);
    Map<String, Object> properties = new HashMap<String, Object>();
    properties.put("resource", "/resource/a");
    given(actionRequest.getContent()).willReturn(JsonValue.json(properties));
    // Given...
    Context context = buildContextStructure("/abc");
    PolicyRequest request = factory.buildRequest(PolicyAction.TREE_EVALUATE, context, actionRequest);
    // Then...
    assertThat(request).isNotNull();
    assertThat(request.getRealm()).isEqualTo("/abc");
    assertThat(request).isInstanceOfAny(TreePolicyRequest.class);
    TreePolicyRequest treeRequest = (TreePolicyRequest) request;
    assertThat(treeRequest.getResource()).isEqualTo("/resource/a");
    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) TreePolicyRequest(org.forgerock.openam.entitlement.rest.model.json.TreePolicyRequest) 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 32 with SubjectContext

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

the class PolicyResourceEvaluationTest method shouldMakeTreeEvaluation.

@Test
public void shouldMakeTreeEvaluation() throws EntitlementException {
    // Given...
    given(request.getAction()).willReturn("evaluateTree");
    Context context = buildContextStructure("/abc");
    given(requestFactory.buildRequest(PolicyAction.TREE_EVALUATE, context, request)).willReturn(policyRequest);
    given(policyRequest.getRestSubject()).willReturn(restSubject);
    given(policyRequest.getApplication()).willReturn("some-application");
    given(factory.getEvaluator(restSubject, "some-application")).willReturn(evaluator);
    given(policyRequest.getApplication()).willReturn("some-application");
    given(policyRequest.getRealm()).willReturn("/abc");
    List<Entitlement> decisions = Arrays.asList(new Entitlement());
    given(evaluator.routePolicyRequest(policyRequest)).willReturn(decisions);
    JsonValue jsonDecision = JsonValue.json(array());
    given(parser.printEntitlements(decisions)).willReturn(jsonDecision);
    // When...
    Promise<ActionResponse, ResourceException> promise = policyResource.actionCollection(context, request);
    // Then...
    verify(request).getAction();
    verify(requestFactory).buildRequest(PolicyAction.TREE_EVALUATE, context, request);
    verify(policyRequest).getRestSubject();
    verify(policyRequest, times(2)).getApplication();
    verify(policyRequest).getRealm();
    verify(factory).getEvaluator(restSubject, "some-application");
    verify(evaluator).routePolicyRequest(policyRequest);
    verify(parser).printEntitlements(decisions);
    assertThat(promise).succeeded().withContent().isEqualTo(jsonDecision);
    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) JsonValue(org.forgerock.json.JsonValue) ResourceException(org.forgerock.json.resource.ResourceException) Entitlement(com.sun.identity.entitlement.Entitlement) ActionResponse(org.forgerock.json.resource.ActionResponse) Test(org.testng.annotations.Test)

Example 33 with SubjectContext

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

the class PrivilegePolicyStoreProviderTest method shouldUseRealmAndSubjectFromContext.

@Test
public void shouldUseRealmAndSubjectFromContext() {
    // Given
    SubjectContext subjectContext = mock(SubjectContext.class);
    Subject subject = new Subject();
    String realm = "/test realm";
    given(subjectContext.getCallerSubject()).willReturn(subject);
    RealmContext context = new RealmContext(subjectContext);
    context.setSubRealm(realm, realm);
    PrivilegeManager manager = mock(PrivilegeManager.class);
    given(mockFactory.get(realm, subject)).willReturn(manager);
    // When
    PolicyStore store = testProvider.getPolicyStore(context);
    // Then
    verify(mockFactory).get(realm, subject);
    assertThat(store).isNotNull().isInstanceOf(PrivilegePolicyStore.class);
}
Also used : RealmContext(org.forgerock.openam.rest.RealmContext) SubjectContext(org.forgerock.openam.rest.resource.SubjectContext) PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) Subject(javax.security.auth.Subject) 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