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;
}
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;
}
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);
}
}
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;
}
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);
}
Aggregations