Search in sources :

Example 1 with Disposition

use of org.restlet.data.Disposition in project OpenAM by OpenRock.

the class XacmlServiceTest method testDispositionOfSubSubRealmExport.

@Test
public void testDispositionOfSubSubRealmExport() throws Exception {
    //given
    query.add(XacmlService.QUERY_PARAM_STRING, "test1");
    query.add(XacmlService.QUERY_PARAM_STRING, "test2");
    PolicySet policySet = new PolicySet();
    doReturn(policySet).when(importExport).exportXACML(eq("/"), any(Subject.class), any(List.class));
    //when
    Representation result = service.exportXACML("/sub1/sub2");
    Disposition disposition = result.getDisposition();
    assertThat(disposition.getFilename()).isEqualTo("sub1-sub2-realm-policies.xml");
    assertThat(disposition.getType()).isEqualTo(disposition.TYPE_ATTACHMENT);
}
Also used : Disposition(org.restlet.data.Disposition) List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with Disposition

use of org.restlet.data.Disposition 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 3 with Disposition

use of org.restlet.data.Disposition in project OpenAM by OpenRock.

the class XacmlServiceTest method testDispositionOfRootRealmExport.

@Test
public void testDispositionOfRootRealmExport() throws Exception {
    //given
    query.add(XacmlService.QUERY_PARAM_STRING, "test1");
    query.add(XacmlService.QUERY_PARAM_STRING, "test2");
    PolicySet policySet = new PolicySet();
    doReturn(policySet).when(importExport).exportXACML(eq("/"), any(Subject.class), any(List.class));
    //when
    Representation result = service.exportXACML("/");
    Disposition disposition = result.getDisposition();
    assertThat(disposition.getFilename()).isEqualTo("realm-policies.xml");
    assertThat(disposition.getType()).isEqualTo(disposition.TYPE_ATTACHMENT);
}
Also used : Disposition(org.restlet.data.Disposition) List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with Disposition

use of org.restlet.data.Disposition in project OpenAM by OpenRock.

the class XacmlServiceTest method testDispositionOfSubRealmExport.

@Test
public void testDispositionOfSubRealmExport() throws Exception {
    //given
    query.add(XacmlService.QUERY_PARAM_STRING, "test1");
    query.add(XacmlService.QUERY_PARAM_STRING, "test2");
    PolicySet policySet = new PolicySet();
    doReturn(policySet).when(importExport).exportXACML(eq("/"), any(Subject.class), any(List.class));
    //when
    Representation result = service.exportXACML("/sub");
    Disposition disposition = result.getDisposition();
    assertThat(disposition.getFilename()).isEqualTo("sub-realm-policies.xml");
    assertThat(disposition.getType()).isEqualTo(disposition.TYPE_ATTACHMENT);
}
Also used : Disposition(org.restlet.data.Disposition) List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) PolicySet(com.sun.identity.entitlement.xacml3.core.PolicySet) Subject(javax.security.auth.Subject) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PolicySet (com.sun.identity.entitlement.xacml3.core.PolicySet)4 Disposition (org.restlet.data.Disposition)4 JacksonRepresentation (org.restlet.ext.jackson.JacksonRepresentation)4 Representation (org.restlet.representation.Representation)4 List (java.util.List)3 Subject (javax.security.auth.Subject)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Test (org.testng.annotations.Test)3 EntitlementException (com.sun.identity.entitlement.EntitlementException)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 ArrayList (java.util.ArrayList)1 ResourceException (org.forgerock.json.resource.ResourceException)1 VisibleForTesting (org.forgerock.util.annotations.VisibleForTesting)1 Status (org.restlet.data.Status)1 OutputRepresentation (org.restlet.representation.OutputRepresentation)1 ResourceException (org.restlet.resource.ResourceException)1