use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldResultInEquivalentPrivilegesWhenValidPrivilegeSetSerializedToXACMLThenDeserialized.
@Test
public void shouldResultInEquivalentPrivilegesWhenValidPrivilegeSetSerializedToXACMLThenDeserialized() throws EntitlementException {
//Given
Set<Privilege> privileges = createArbitraryPrivilegeSet(now);
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
List<Policy> policies = getPoliciesFromPolicySet(policySet);
List<Privilege> deserializedPrivileges = new ArrayList<Privilege>();
for (Policy policy : policies) {
//When
deserializedPrivileges.add(XACMLPrivilegeUtils.policyToPrivilege(policy));
}
//Then
assertAllPrivilegesEquivalent(deserializedPrivileges, privileges);
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldReturnXACMLPolicySetWhenGivenValidPrivilegeSet.
@Test
public void shouldReturnXACMLPolicySetWhenGivenValidPrivilegeSet() throws EntitlementException {
//Given
Set<Privilege> privileges = createArbitraryPrivilegeSet(now);
//When
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
//Then
assertPolicySetContentsMatchPrivilegesContent(policySet, privileges);
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method assertPolicySetContentsMatchPrivilegesContent.
private void assertPolicySetContentsMatchPrivilegesContent(PolicySet policySet, Set<Privilege> privileges) {
if (privileges != null && !privileges.isEmpty()) {
assertTrue(policySet != null, "Expected PolicySet to not be null.");
}
List<Policy> policies = getPoliciesFromPolicySet(policySet);
assertEquals(policies.size(), privileges.size(), "Mismatch between number of Policy elements in PolicySet, " + "and number of original Privileges.");
List<String> policyIdList = new ArrayList<String>();
for (Policy policy : policies) {
policyIdList.add(policy.getPolicyId());
}
List<String> privilegeIdList = new ArrayList<String>();
for (Privilege privilege : privileges) {
privilegeIdList.add(privilege.getName());
}
assertTrue(policyIdList.containsAll(privilegeIdList), "Not all Privilege names were included in the " + "PolicySet.");
assertTrue(privilegeIdList.containsAll(policyIdList), "Extra names were added to the PolicySet which were " + "not in the list of Privilege names.");
List<String> descriptionList = new ArrayList<String>();
for (Policy policy : policies) {
descriptionList.add(policy.getDescription());
}
for (Privilege privilege : privileges) {
String description = privilege.getDescription();
assertTrue(descriptionList.contains(description), "Privilege with description '" + description + "' not " + "found in PolicySet.");
}
String privilegesVersion = formatMillisecondsAsTimestamp(now);
for (Policy policy : policies) {
assertEquals(policy.getVersion().getValue(), privilegesVersion, "Policy found with version not matching " + "Privilege creation date.");
}
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldNotAddNullToPolicySetAndSoShouldLeavePolicySetUnchanged.
@Test
public void shouldNotAddNullToPolicySetAndSoShouldLeavePolicySetUnchanged() throws JAXBException {
//Given
Policy policy = null;
PolicySet policySet = new PolicySet();
//When
XACMLPrivilegeUtils.addPolicyToPolicySet(policy, policySet);
//Then
assertEquals(policySet.getPolicySetOrPolicyOrPolicySetIdReference().size(), 0, "Expected PolicySet to remain " + "empty as a result of not adding null to the empty PolicySet.");
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class FactoryMethods method getPoliciesFromPolicySet.
public static List<Policy> getPoliciesFromPolicySet(PolicySet policySet) {
List<JAXBElement<?>> policySetOrPolicyOrPolicySetIdReference = policySet.getPolicySetOrPolicyOrPolicySetIdReference();
List<Policy> policies = new ArrayList<Policy>();
for (JAXBElement element : policySetOrPolicyOrPolicySetIdReference) {
policies.add((Policy) element.getValue());
}
return policies;
}
Aggregations