Search in sources :

Example 6 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XACMLExportImport method exportXACML.

/**
     * Performs an export of all Policies found in the Privilege Manager that match the
     * provided filters.
     *
     * @param realm Non null realm.
     * @param admin Non null admin subject to authenticate as.
     * @param filters Non null, but maybe empty filters to select Privileges against.
     * @return A non null but possibly empty collection of Policies.
     * @throws EntitlementException If there was any problem with the generation of Policies.
     */
public PolicySet exportXACML(String realm, Subject admin, List<String> filters) throws EntitlementException {
    PrivilegeManager pm = privilegeManagerFactory.createReferralPrivilegeManager(realm, admin);
    Set<SearchFilter> filterSet = new HashSet<SearchFilter>();
    if (filters != null) {
        for (String filter : filters) {
            SearchFilter searchFilter = searchFilterFactory.getFilter(filter);
            message("Export: Search Filter: {0}", searchFilter);
            filterSet.add(searchFilter);
        }
    }
    Set<String> privilegeNames = pm.searchNames(filterSet);
    message("Export: Privilege Matches {0}", privilegeNames.size());
    PrivilegeSet privilegeSet = new PrivilegeSet();
    for (String name : privilegeNames) {
        Privilege privilege = pm.findByName(name, admin);
        message("Export: Privilege {0}", privilege.getName());
        privilegeSet.addPrivilege(privilege);
    }
    PolicySet policySet = xacmlReaderWriter.toXACML(realm, privilegeSet);
    message("Export: Complete");
    return policySet;
}
Also used : PrivilegeManager(com.sun.identity.entitlement.PrivilegeManager) IPrivilegeManager(com.sun.identity.entitlement.IPrivilegeManager) SearchFilter(com.sun.identity.entitlement.util.SearchFilter) IPrivilege(com.sun.identity.entitlement.IPrivilege) Privilege(com.sun.identity.entitlement.Privilege) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) HashSet(java.util.HashSet)

Example 7 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XACMLPrivilegeUtils method policySetToPrivileges.

public static Set<Privilege> policySetToPrivileges(PolicySet policySet) throws EntitlementException {
    if (policySet == null) {
        return null;
    }
    Set<Privilege> privileges = new HashSet<Privilege>();
    Set<Policy> policies = getPoliciesFromPolicySet(policySet);
    if (policies != null) {
        for (Policy policy : policies) {
            Privilege p = policyToPrivilege(policy);
            privileges.add(p);
        }
    }
    return privileges;
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) XACMLOpenSSOPrivilege(com.sun.identity.entitlement.opensso.XACMLOpenSSOPrivilege) Privilege(com.sun.identity.entitlement.Privilege) ReferralPrivilege(com.sun.identity.entitlement.ReferralPrivilege) HashSet(java.util.HashSet)

Example 8 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XACMLPrivilegeUtils method writeXMLToStream.

public static void writeXMLToStream(PolicySet policySet, OutputStream outputStream) throws EntitlementException {
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(XACMLConstants.XACML3_CORE_PKG);
        JAXBElement<PolicySet> policySetElement = objectFactory.createPolicySet(policySet);
        Marshaller marshaller = jaxbContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.marshal(policySetElement, outputStream);
    } catch (JAXBException je) {
        PrivilegeManager.debug.error("JAXBException while mapping privilege to policy:", je);
        throw new EntitlementException(EntitlementException.UNABLE_TO_SERIALIZE_OBJECT, je);
    }
}
Also used : EntitlementException(com.sun.identity.entitlement.EntitlementException) Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet)

Example 9 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XACMLPrivilegeUtils method addPolicyToPolicySet.

public static PolicySet addPolicyToPolicySet(Policy policy, PolicySet policySet) throws JAXBException {
    if (policySet == null || policy == null) {
        return policySet;
    }
    JAXBContext jaxbContext = JAXBContext.newInstance(XACMLConstants.XACML3_CORE_PKG);
    List<JAXBElement<?>> pList = policySet.getPolicySetOrPolicyOrPolicySetIdReference();
    JAXBElement<Policy> policyElement = objectFactory.createPolicy(policy);
    pList.add(policyElement);
    return policySet;
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement)

Example 10 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XACMLPrivilegeUtilsTest method shouldAddPolicyToPolicySet.

@Test
public void shouldAddPolicyToPolicySet() throws JAXBException {
    //Given
    Policy policy = new Policy();
    PolicySet policySet = new PolicySet();
    //When
    XACMLPrivilegeUtils.addPolicyToPolicySet(policy, policySet);
    //Then
    assertPolicySetContainsSameSinglePolicy(policySet, policy);
}
Also used : Policy(com.sun.identity.entitlement.xacml3.core.Policy) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Test(org.testng.annotations.Test)

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