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);
}
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);
}
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);
}
Aggregations