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