use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class OpenSSOApplicationPrivilegeManager method toApplicationPrivilege.
private ApplicationPrivilege toApplicationPrivilege(Privilege p) throws EntitlementException {
ApplicationPrivilege ap = new ApplicationPrivilege(p.getName());
ap.setDescription(p.getDescription());
ap.setCreatedBy(p.getCreatedBy());
ap.setCreationDate(p.getCreationDate());
ap.setLastModifiedBy(p.getLastModifiedBy());
ap.setLastModifiedDate(p.getLastModifiedDate());
Entitlement ent = p.getEntitlement();
Set<String> resourceNames = ent.getResourceNames();
Map<String, Set<String>> mapAppToRes = getApplicationPrivilegeResourceNames(resourceNames);
ap.setApplicationResources(mapAppToRes);
ap.setActionValues(getActionValues(ent.getActionValues()));
Set<SubjectImplementation> subjects = new HashSet<SubjectImplementation>();
if (p.getSubject() instanceof OrSubject) {
OrSubject orSubject = (OrSubject) p.getSubject();
for (EntitlementSubject es : orSubject.getESubjects()) {
if (es instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) es);
}
}
} else if (p.getSubject() instanceof SubjectImplementation) {
subjects.add((SubjectImplementation) p.getSubject());
}
ap.setSubject(subjects);
EntitlementCondition cond = p.getCondition();
if (cond instanceof SimpleTimeCondition) {
ap.setCondition(cond);
}
return ap;
}
use of com.sun.identity.entitlement.Entitlement 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 com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotPrintPolicyAttributes.
@Test
public void shouldNotPrintPolicyAttributes() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
policy.getEntitlement().setAttributes(Collections.singletonMap("one", CollectionUtils.asSet("two")));
// When
JsonValue result = parser.printPolicy(policy);
// Then
// Attributes should not appear on the policy entitlement
assertThat(result.get("attributes").asMapOfList(String.class)).isNullOrEmpty();
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintPolicyResourceSet.
@Test
public void shouldPrintPolicyResourceSet() throws Exception {
// Given
Privilege policy = new StubPrivilege();
Set<String> included = CollectionUtils.asSet("one", "two", "three");
Entitlement resources = new Entitlement();
resources.setResourceNames(included);
policy.setEntitlement(resources);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("resources").asList()).containsOnly(included.toArray());
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintPolicyActionValues.
@Test
public void shouldPrintPolicyActionValues() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("one", true);
actionValues.put("two", false);
policy.getEntitlement().setActionValues(actionValues);
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("actionValues").asMap(Boolean.class)).isEqualTo(actionValues);
}
Aggregations