use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldParseSimpleSubjects.
@Test
public void shouldParseSimpleSubjects() throws Exception {
// Given
JsonValue content = buildJson(field("subject", object(field("type", "AuthenticatedUsers"))));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getSubject()).isInstanceOf(AuthenticatedUsers.class);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldCorrectlyParseConditionTypes.
@Test
public void shouldCorrectlyParseConditionTypes() throws Exception {
// Given
String scope = "givenName";
JsonValue content = buildJson(field("condition", object(field("type", "OAuth2Scope"), field("requiredScopes", array(scope)))));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getCondition()).isInstanceOf(OAuth2ScopeCondition.class);
assertThat(((OAuth2ScopeCondition) result.getCondition()).getRequiredScopes()).isEqualTo(Collections.singleton(scope));
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldUsePassedNameIfJsonNameIsMissing.
@Test
public void shouldUsePassedNameIfJsonNameIsMissing() throws Exception {
// Given
String name = "resourceName";
JsonValue content = buildJson(null);
// When
Privilege result = parser.parsePolicy(name, content);
// Then
assertThat(result.getName()).isEqualTo(name);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldIgnoreTTLForPolicies.
@Test
public void shouldIgnoreTTLForPolicies() throws Exception {
// Given
long ttl = 1234l;
JsonValue content = buildJson(field("ttl", ttl));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getEntitlement().getTTL()).isNotSameAs(ttl);
}
use of com.sun.identity.entitlement.Privilege 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);
}
Aggregations