Search in sources :

Example 21 with PolicySet

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);
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) ArrayList(java.util.ArrayList) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Privilege(com.sun.identity.entitlement.Privilege) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Test(org.testng.annotations.Test)

Example 22 with PolicySet

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);
}
Also used : ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Privilege(com.sun.identity.entitlement.Privilege) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Test(org.testng.annotations.Test)

Example 23 with PolicySet

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.");
    }
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) ArrayList(java.util.ArrayList) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) Privilege(com.sun.identity.entitlement.Privilege)

Example 24 with PolicySet

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.");
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Test(org.testng.annotations.Test)

Example 25 with 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;
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) ArrayList(java.util.ArrayList) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

PolicySet (com.sun.identity.entitlement.xacml3.core.PolicySet)23 Policy (com.sun.identity.entitlement.xacml3.core.Policy)12 Test (org.testng.annotations.Test)12 Privilege (com.sun.identity.entitlement.Privilege)9 ReferralPrivilege (com.sun.identity.entitlement.ReferralPrivilege)9 EntitlementException (com.sun.identity.entitlement.EntitlementException)5 HashSet (java.util.HashSet)5 JAXBContext (javax.xml.bind.JAXBContext)5 JAXBElement (javax.xml.bind.JAXBElement)5 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)5 Representation (org.restlet.representation.Representation)5 ArrayList (java.util.ArrayList)4 List (java.util.List)4 Subject (javax.security.auth.Subject)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 Disposition (org.restlet.data.Disposition)4 JAXBException (javax.xml.bind.JAXBException)3 XACMLOpenSSOPrivilege (com.sun.identity.entitlement.opensso.XACMLOpenSSOPrivilege)2 Target (com.sun.identity.entitlement.xacml3.core.Target)2 Version (com.sun.identity.entitlement.xacml3.core.Version)2