Search in sources :

Example 16 with PolicySet

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;
}
Also used : InputSource(org.xml.sax.InputSource) JAXBContext(javax.xml.bind.JAXBContext) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet)

Example 17 with PolicySet

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

Example 18 with PolicySet

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;
}
Also used : Status(org.restlet.data.Status) EntitlementException(com.sun.identity.entitlement.EntitlementException) OutputRepresentation(org.restlet.representation.OutputRepresentation) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Disposition(org.restlet.data.Disposition) ResourceException(org.restlet.resource.ResourceException) ResourceException(org.forgerock.json.resource.ResourceException) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) OutputRepresentation(org.restlet.representation.OutputRepresentation) Representation(org.restlet.representation.Representation) IOException(java.io.IOException) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) VisibleForTesting(org.forgerock.util.annotations.VisibleForTesting)

Example 19 with PolicySet

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

Example 20 with PolicySet

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.");
}
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)

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