Search in sources :

Example 21 with PolicyResponse

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

the class RegistryPolicyPluginTest method testBlackListPostQuery.

@Test
public void testBlackListPostQuery() throws Exception {
    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"));
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
    PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.operationPolicy().size(), is(0));
    assertThat(response.itemPolicy().size(), is(0));
    rpp.setRegistryEntryIds(Collections.singleton("1234567890abcdefg987654321"));
    response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.itemPolicy(), equalTo(rpp.getBypassAccessPolicy()));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 22 with PolicyResponse

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

the class RegistryPolicyPluginTest method testNoRegistryBypassPermissions.

@Test
public void testNoRegistryBypassPermissions() throws Exception {
    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"));
    RegistryPolicyPlugin rpp = createRegistryPlugin();
    rpp.setRegistryBypassPolicyStrings(null);
    PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
    assertThat(response.itemPolicy().isEmpty(), is(true));
}
Also used : Metacard(ddf.catalog.data.Metacard) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) ResultImpl(ddf.catalog.data.impl.ResultImpl) PolicyResponse(ddf.catalog.plugin.PolicyResponse) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 23 with PolicyResponse

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

the class WorkspaceSharingPolicyPluginTest method testOwnerOnCreate.

@Test
public void testOwnerOnCreate() throws Exception {
    String email = "a@b.c";
    WorkspaceMetacardImpl workspace = new WorkspaceMetacardImpl();
    workspace.setOwner(email);
    PolicyResponse response = plugin.processPreCreate(workspace, properties);
    assertThat(response.itemPolicy(), is(Collections.emptyMap()));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 24 with PolicyResponse

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

the class WorkspaceSharingPolicyPluginTest method testOwnerOnUpdate.

@Test
public void testOwnerOnUpdate() throws Exception {
    String email = "a@b.c";
    WorkspaceMetacardImpl workspace = new WorkspaceMetacardImpl();
    workspace.setOwner(email);
    PolicyResponse response = plugin.processPreUpdate(workspace, properties);
    assertThat(response.itemPolicy(), is(ImmutableMap.of(Core.METACARD_OWNER, ImmutableSet.of(email))));
}
Also used : PolicyResponse(ddf.catalog.plugin.PolicyResponse) WorkspaceMetacardImpl(org.codice.ddf.catalog.ui.metacard.workspace.WorkspaceMetacardImpl) Test(org.junit.Test)

Example 25 with PolicyResponse

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

the class MetacardAttributeSecurityPolicyPluginTest method testUnusedMethods.

@Test
public void testUnusedMethods() throws StopProcessingException {
    PolicyResponse policyResponse = plugin.processPreQuery(mock(Query.class), new HashMap<>());
    assertThat(policyResponse.itemPolicy().size(), is(0));
    policyResponse = plugin.processPreResource(mock(ResourceRequest.class));
    assertThat(policyResponse.itemPolicy().size(), is(0));
}
Also used : Query(ddf.catalog.operation.Query) PolicyResponse(ddf.catalog.plugin.PolicyResponse) 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