use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testReadRegistryOperations.
@Test
public void testReadRegistryOperations() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
rpp.setReadAccessPolicyStrings(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.processPostQuery(new ResultImpl(mcard), null);
assertThat(response.itemPolicy(), equalTo(rpp.getReadAccessPolicy()));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testRemoteCudOperations.
@Test
public void testRemoteCudOperations() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
rpp.setCreateAccessPolicyStrings(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"));
HashMap<String, Serializable> props = new HashMap<>();
props.put("local-destination", false);
PolicyResponse response = rpp.processPreCreate(mcard, props);
assertThat(response.operationPolicy().size(), is(0));
response = rpp.processPreUpdate(mcard, props);
assertThat(response.operationPolicy().size(), is(0));
response = rpp.processPreDelete(Collections.singletonList(mcard), props);
assertThat(response.operationPolicy().size(), is(0));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testDisabledRegistry.
@Test
public void testDisabledRegistry() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
rpp.setRegistryDisabled(true);
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.getBypassAccessPolicy()));
response = rpp.processPreUpdate(mcard, null);
assertThat(response.operationPolicy(), equalTo(rpp.getBypassAccessPolicy()));
response = rpp.processPreDelete(Collections.singletonList(mcard), null);
assertThat(response.operationPolicy(), equalTo(rpp.getBypassAccessPolicy()));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testWhiteListPostQuery.
@Test
public void testWhiteListPostQuery() 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.setWhiteList(true);
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
assertThat(response.operationPolicy().size(), is(0));
assertThat(response.itemPolicy(), equalTo(rpp.getBypassAccessPolicy()));
rpp.setRegistryEntryIds(Collections.singleton("1234567890abcdefg987654321"));
response = rpp.processPostQuery(new ResultImpl(mcard), null);
assertThat(response.itemPolicy().size(), is(0));
}
use of ddf.catalog.plugin.PolicyResponse in project ddf by codice.
the class RegistryPolicyPluginTest method testNonRegistryMcardTypes.
@Test
public void testNonRegistryMcardTypes() throws Exception {
RegistryPolicyPlugin rpp = createRegistryPlugin();
rpp.setRegistryBypassPolicyStrings(Collections.singletonList("role=system-admin"));
Metacard mcard = new MetacardImpl();
mcard.setAttribute(new AttributeImpl(Metacard.TAGS, "some.type"));
mcard.setAttribute(new AttributeImpl(Metacard.ID, "1234567890abcdefg987654321"));
PolicyResponse response = rpp.processPostQuery(new ResultImpl(mcard), null);
assertThat(response.itemPolicy().isEmpty(), is(true));
response = rpp.processPreCreate(mcard, null);
assertThat(response.operationPolicy().isEmpty(), is(true));
response = rpp.processPreUpdate(mcard, null);
assertThat(response.operationPolicy().isEmpty(), is(true));
response = rpp.processPreDelete(Collections.singletonList(mcard), null);
assertThat(response.operationPolicy().isEmpty(), is(true));
Metacard mcard2 = new MetacardImpl();
mcard2.setAttribute(new AttributeImpl(Metacard.ID, "abcdefghijklmnop1234567890"));
response = rpp.processPostQuery(new ResultImpl(mcard2), null);
assertThat(response.itemPolicy().isEmpty(), is(true));
}
Aggregations