use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method streamToPolicySet.
public static PolicySet streamToPolicySet(InputStream stream) throws JAXBException {
//FIXME: remove
PrivilegeManager.debug.error("XACMLProvilegeUtils.streamToPolicySet(), core_pkg:" + XACMLConstants.XACML3_CORE_PKG);
if (stream == null) {
return null;
}
JAXBContext jc = JAXBContext.newInstance(XACMLConstants.XACML3_CORE_PKG);
Unmarshaller um = jc.createUnmarshaller();
JAXBElement je = (JAXBElement) um.unmarshal(XMLUtils.createSAXSource(new InputSource(stream)));
PolicySet ps = (PolicySet) je.getValue();
return ps;
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtils method getPoliciesFromPolicySet.
public static Set<Policy> getPoliciesFromPolicySet(PolicySet policySet) {
if (policySet == null) {
return null;
}
Set<Policy> policies = new HashSet<Policy>();
List<JAXBElement<?>> choiceList = policySet.getPolicySetOrPolicyOrPolicySetIdReference();
for (JAXBElement jaxe : choiceList) {
if (jaxe.getDeclaredType().equals(Policy.class)) {
Policy p = (Policy) jaxe.getValue();
policies.add(p);
}
}
return policies;
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XacmlService method exportXACML.
/**
* This version of exportXACML here for testing - it saves trying to mock the static getRealmFromRequest
* @param realm The realm
* @return Representation object wrapping the converted XACML
*/
@VisibleForTesting
Representation exportXACML(String realm) {
List<String> filters = new ArrayList<String>(Arrays.asList(getQuery().getValuesArray(QUERY_PARAM_STRING)));
PolicySet policySet;
try {
if (!checkPermission("READ")) {
throw new ResourceException(new Status(FORBIDDEN));
}
policySet = importExport.exportXACML(realm, getAdminToken(), filters);
getResponse().setStatus(Status.SUCCESS_OK);
} catch (EntitlementException e) {
debug.warning("Reading Policies failed", e);
throw new ResourceException(new Status(INTERNAL_ERROR, e.getLocalizedMessage(getRequestLocale()), null, null));
}
final PolicySet finalPolicySet = policySet;
Representation result = new OutputRepresentation(XACMLServiceEndpointApplication.APPLICATION_XML_XACML3) {
@Override
public void write(OutputStream outputStream) throws IOException {
try {
XACMLPrivilegeUtils.writeXMLToStream(finalPolicySet, outputStream);
} catch (EntitlementException e) {
throw new IOException(e);
}
}
};
// OPENAM-4974
Disposition disposition = new Disposition();
disposition.setType(Disposition.TYPE_ATTACHMENT);
disposition.setFilename(getPolicyAttachmentFileName(realm));
result.setDisposition(disposition);
return result;
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class FactoryMethods method getArbitraryPrivilegeAsPolicy.
public static Policy getArbitraryPrivilegeAsPolicy(long now) throws EntitlementException {
Set<Privilege> privileges = createArbitraryPrivilegeSet(now);
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
return (Policy) policySet.getPolicySetOrPolicyOrPolicySetIdReference().get(0).getValue();
}
use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.
the class XACMLPrivilegeUtilsTest method shouldReturnNullWhenGivenNullAsPrivilegeSet.
@Test
public void shouldReturnNullWhenGivenNullAsPrivilegeSet() {
//Given
Set<Privilege> privileges = null;
//When
PolicySet policySet = XACMLPrivilegeUtils.privilegesToPolicySet("/", privileges);
//Then
assertNull(policySet, "Expected PolicySet to be null.");
}
Aggregations