Search in sources :

Example 26 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet 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 27 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet 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)

Example 28 with PolicySet

use of com.sun.identity.entitlement.xacml3.core.PolicySet in project OpenAM by OpenRock.

the class XacmlServiceTest method testExportXACML.

@Test
public void testExportXACML() 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();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    result.write(baos);
    String xml = new String(baos.toByteArray(), "UTF-8");
    //then
    assertThat(xml).contains("<ns2:PolicySet");
    assertThat(xml).contains("xmlns:ns2=\"urn:oasis:names:tc:xacml:3.0:core:schema:wd-17\"");
    verify(response).setStatus(Status.SUCCESS_OK);
    ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    verify(importExport).exportXACML(eq("/"), any(Subject.class), listCaptor.capture());
    assertThat(listCaptor.getValue()).containsExactly("test1", "test2");
}
Also used : List(java.util.List) JacksonRepresentation(org.restlet.ext.jackson.JacksonRepresentation) Representation(org.restlet.representation.Representation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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)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