Search in sources :

Example 46 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class XmlAttributeSecurityPolicyPluginTest method testProcessUnusedMethods.

@Test
public void testProcessUnusedMethods() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPreQuery(new QueryImpl(Filter.INCLUDE), new HashMap<>());
    org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
    policyResponse = plugin.processPreResource(new ResourceRequestById(""));
    org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(0));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) PolicyResponse(ddf.catalog.plugin.PolicyResponse) Test(org.junit.Test)

Example 47 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class XmlAttributeSecurityPolicyPluginTest method testProcessPreDelete.

@Test
public void testProcessPreDelete() throws StopProcessingException {
    MetacardImpl metacard1 = new MetacardImpl();
    metacard1.setMetadata(TEST_METADATA_3);
    PolicyResponse policyResponse = plugin.processPreDelete(Arrays.asList(metacard, metacard1), new HashMap<>());
    org.junit.Assert.assertThat(policyResponse.operationPolicy().entrySet().size(), Matchers.is(3));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 48 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class XmlAttributeSecurityPolicyPluginTest method testProcessQuery.

@Test
public void testProcessQuery() throws StopProcessingException, PluginExecutionException {
    Result mockResult = mock(Result.class);
    when(mockResult.getMetacard()).thenReturn(metacard);
    PolicyResponse policyResponse = plugin.processPostQuery(mockResult, new HashMap<>());
    org.junit.Assert.assertThat(policyResponse.itemPolicy().entrySet().size(), Matchers.is(3));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 49 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class RegistryPolicyPluginTest method testSecurityValueSet.

@Test
public void testSecurityValueSet() throws Exception {
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    Map<String, Set<String>> expectedPolicy = new HashMap<>();
    Set<String> firstSet = new HashSet<>();
    Set<String> secondSet = new HashSet<>();
    firstSet.add("Charles");
    firstSet.add("Haller");
    secondSet.add("Nikolaevna");
    secondSet.add("Alexandria");
    secondSet.add("Rasputin");
    expectedPolicy.put("David", firstSet);
    expectedPolicy.put("Illyana", secondSet);
    Metacard mcard = new MetacardImpl();
    mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
    mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
    List<Serializable> securityValues = new ArrayList<>();
    securityValues.add("David=Charles,Haller");
    securityValues.add("Illyana=Nikolaevna, Alexandria, Rasputin");
    mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.SECURITY_LEVEL, securityValues));
    PolicyResponse response = rpp.processPreCreate(mcard, null);
    assertThat(response.operationPolicy().size(), is(0));
    assertThat(response.itemPolicy().size(), is(2));
    assertThat(response.itemPolicy(), equalTo(expectedPolicy));
}
Also used : Serializable(java.io.Serializable) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ArrayList(java.util.ArrayList) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) PolicyResponse(ddf.catalog.plugin.PolicyResponse) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 50 with PolicyResponse

use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.

the class RegistryPolicyPluginTest method testCudRegistryOperations.

@Test
public void testCudRegistryOperations() throws Exception {
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
    rpp.setCreateAccessPolicyStrings(Collections.singletonList("role=guest"));
    rpp.setUpdateAccessPolicyStrings(Collections.singletonList("role=guest"));
    rpp.setDeleteAccessPolicyStrings(Collections.singletonList("role=guest"));
    Metacard mcard = new MetacardImpl();
    mcard.setAttribute(new AttributeImpl(Metacard.TAGS, RegistryConstants.REGISTRY_TAG));
    mcard.setAttribute(new AttributeImpl(RegistryObjectMetacardType.REGISTRY_ID, "validId"));
    mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
    PolicyResponse response = rpp.processPreCreate(mcard, null);
    assertThat(response.operationPolicy(), equalTo(rpp.getCreateAccessPolicy()));
    response = rpp.processPreUpdate(mcard, null);
    assertThat(response.operationPolicy(), equalTo(rpp.getUpdateAccessPolicy()));
    response = rpp.processPreDelete(Collections.singletonList(mcard), null);
    assertThat(response.operationPolicy(), equalTo(rpp.getDeleteAccessPolicy()));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

PolicyResponse (ddf.catalog.plugin.PolicyResponse)75 Test (org.junit.Test)64 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Metacard (ddf.catalog.data.Metacard)19 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)14 Serializable (java.io.Serializable)14 Set (java.util.Set)14 Result (ddf.catalog.data.Result)13 HashMap (java.util.HashMap)12 PolicyPlugin (ddf.catalog.plugin.PolicyPlugin)10 HashSet (java.util.HashSet)7 ResultImpl (ddf.catalog.data.impl.ResultImpl)6 ResourceResponse (ddf.catalog.operation.ResourceResponse)6 Query (ddf.catalog.operation.Query)5 StopProcessingException (ddf.catalog.plugin.StopProcessingException)4 ImmutableSet (com.google.common.collect.ImmutableSet)3 ResourceRequest (ddf.catalog.operation.ResourceRequest)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 OPERATION_TRANSACTION_KEY (ddf.catalog.Constants.OPERATION_TRANSACTION_KEY)2