use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class PolicyResourceEvaluationTest method shouldMakeBatchEvaluation.
@Test
public void shouldMakeBatchEvaluation() throws EntitlementException {
// Given...
given(request.getAction()).willReturn("evaluate");
Context context = buildContextStructure("/abc");
given(requestFactory.buildRequest(PolicyAction.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.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, requestFactory, policyRequest, factory, evaluator, parser);
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldNotPrintPolicyTTL.
@Test
public void shouldNotPrintPolicyTTL() throws Exception {
// Given
Privilege policy = new StubPrivilege();
policy.setEntitlement(new Entitlement());
policy.getEntitlement().setTTL(1234l);
// When
JsonValue result = parser.printPolicy(policy);
// Then
// TTL should not appear on the policy entitlement
assertThat(result.get("ttl").asLong()).isNull();
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class OpenProvisioning method createPolicy.
private void createPolicy(SSOToken adminToken) throws EntitlementException {
PrivilegeManager pMgr = new PolicyPrivilegeManager(applicationServiceFactory, resourceTypeService, constraintValidator);
pMgr.initialize("/", SubjectUtils.createSubject(adminToken));
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("CREATE", Boolean.TRUE);
actionValues.put("READ", Boolean.TRUE);
actionValues.put("UPDATE", Boolean.TRUE);
actionValues.put("DELETE", Boolean.TRUE);
Entitlement entitlement = new Entitlement(APPLICATION, "/OP/*", actionValues);
entitlement.setName("openProvisioningPrivilege");
UserSubject sbj = new OpenSSOUserSubject();
sbj.setID(jSmith.getUniversalId());
AttributeLookupCondition cond = new AttributeLookupCondition("$USER.postaladdress", "$RES.postaladdress");
Privilege privilege = Privilege.getNewInstance();
privilege.setName(PRIVILEGE_NAME);
privilege.setEntitlement(entitlement);
privilege.setSubject(sbj);
privilege.setCondition(cond);
pMgr.add(privilege);
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class PrivilegeUtils method privilegeToPolicy.
public static Policy privilegeToPolicy(String realm, Privilege privilege) throws PolicyException, SSOException, EntitlementException {
Policy policy = new Policy(privilege.getName());
policy.setDescription(privilege.getDescription());
if (privilege.getEntitlement() != null) {
Entitlement entitlement = privilege.getEntitlement();
Set<Rule> rules = entitlementToRule(realm, entitlement);
for (Rule rule : rules) {
policy.addRule(rule);
}
}
EntitlementSubject es = privilege.getSubject();
if ((es != null) && (es != Privilege.NOT_SUBJECT)) {
Subject sbj = eSubjectToEPSubject(es);
policy.addSubject(getSubjectName(es), sbj, false);
}
EntitlementCondition ec = privilege.getCondition();
if (ec != null) {
Condition cond = eConditionToEPCondition(ec);
policy.addCondition(getConditionName(ec), cond);
}
if (privilege.getResourceAttributes() != null) {
Map<String, ResponseProvider> nrps = resourceAttributesToResponseProviders(privilege.getResourceAttributes());
for (String rpName : nrps.keySet()) {
ResponseProvider responseProvider = nrps.get(rpName);
policy.addResponseProvider(rpName, responseProvider);
}
}
policy.setCreatedBy(privilege.getCreatedBy());
policy.setCreationDate(privilege.getCreationDate());
policy.setLastModifiedBy(privilege.getLastModifiedBy());
policy.setLastModifiedDate(privilege.getLastModifiedDate());
return policy;
}
use of com.sun.identity.entitlement.Entitlement in project OpenAM by OpenRock.
the class ListPolicyNamesTest method createPrivilege.
private void createPrivilege(String name) throws EntitlementException {
Map<String, Boolean> actionValues = new HashMap<String, Boolean>();
actionValues.put("GET", Boolean.TRUE);
actionValues.put("POST", Boolean.FALSE);
String resourceName = "http://www.listpolicynamestest.com:80";
Entitlement entitlement = new Entitlement(APPL_NAME, resourceName, actionValues);
entitlement.setName("ent1");
String user = "id=demo,ou=user," + ServiceManager.getBaseDN();
OpenSSOUserSubject usersubj = new OpenSSOUserSubject();
usersubj.setID(user);
Privilege priv = Privilege.getNewInstance();
priv.setName(name);
priv.setEntitlement(entitlement);
priv.setSubject(usersubj);
pm.addPrivilege(priv);
}
Aggregations