use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class PolicyIndexTest method storeAndRetrieve.
@Test
public void storeAndRetrieve() throws SSOException, PolicyException, EntitlementException, Exception {
SSOToken adminToken = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
PolicyManager pm = new PolicyManager(adminToken, "/");
Set<String> hostIndexes = new HashSet<String>();
Set<String> pathIndexes = new HashSet<String>();
Set<String> parentPathIndexes = new HashSet<String>();
hostIndexes.add("http://www.sun.com");
pathIndexes.add("/private");
parentPathIndexes.add("/");
ResourceSearchIndexes indexes = new ResourceSearchIndexes(hostIndexes, pathIndexes, parentPathIndexes);
PrivilegeIndexStore pis = PrivilegeIndexStore.getInstance(SubjectUtils.createSubject(adminToken), "/");
for (Iterator<IPrivilege> i = pis.search("/", indexes, Collections.EMPTY_SET, false); i.hasNext(); ) {
IPrivilege eval = i.next();
if (!(eval instanceof Privilege)) {
throw new Exception("incorrect deserialized policy, wrong type");
}
Privilege p = (Privilege) eval;
if (!p.getEntitlement().getResourceName().equals(URL_RESOURCE)) {
throw new Exception("incorrect deserialized policy");
}
}
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method privilegesToPolicySetInternal.
private static PolicySet privilegesToPolicySetInternal(String realm, Collection<Privilege> privileges) throws JAXBException {
if (privileges == null) {
return null;
}
Set<Policy> policies = new HashSet<Policy>();
for (Privilege privilege : privileges) {
Policy policy = privilegeToPolicy(privilege);
policies.add(policy);
}
PolicySet policySet = policiesToPolicySetInternal(realm, policies);
return policySet;
}
use of com.sun.identity.entitlement.Privilege 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);
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldIgnoreAdvice.
@Test
public void shouldIgnoreAdvice() throws Exception {
// Given
Map<String, List<String>> advice = Collections.singletonMap("test", Arrays.asList("one", "two"));
JsonValue content = buildJson(field("advice", advice));
// When
Privilege result = parser.parsePolicy(POLICY_NAME, content);
// Then
assertThat(result.getEntitlement().getAdvices()).isNullOrEmpty();
}
use of com.sun.identity.entitlement.Privilege in project OpenAM by OpenRock.
the class JsonPolicyParserTest method shouldPrintCreationDateInIsoFormatButWithMilliseconds.
@Test
public void shouldPrintCreationDateInIsoFormatButWithMilliseconds() throws Exception {
// Given
Privilege policy = new StubPrivilege();
Date createdDate = new Date(123456789l);
policy.setCreationDate(createdDate.getTime());
// When
JsonValue result = parser.printPolicy(policy);
// Then
assertThat(result.get("creationDate").asString()).isEqualTo(DateUtils.toUTCDateFormatWithMilliseconds(createdDate));
}
Aggregations