use of ddf.catalog.security.filter.plugin.FilterPlugin in project ddf by codice.
the class FilterPluginTest method testPluginFilterResourceNoStrategiesGood.
@Test
public void testPluginFilterResourceNoStrategiesGood() throws StopProcessingException {
plugin = new FilterPlugin(new Security());
plugin.setPermissions(new PermissionsImpl());
plugin.processPostResource(resourceResponse, getExactRolesMetacard());
}
use of ddf.catalog.security.filter.plugin.FilterPlugin in project ddf by codice.
the class FilterPluginTest method testPluginFilterNoStrategies.
@Test
public void testPluginFilterNoStrategies() {
plugin = new FilterPlugin(new Security());
plugin.setPermissions(new PermissionsImpl());
plugin.setSubjectOperations(new SubjectUtils());
plugin.setSecurityLogger(mock(SecurityLogger.class));
try {
QueryResponse response = plugin.processPostQuery(incomingResponse);
verifyFilterResponse(response);
} catch (StopProcessingException e) {
LOGGER.error("Stopped processing the redaction plugin", e);
}
}
use of ddf.catalog.security.filter.plugin.FilterPlugin in project ddf by codice.
the class FilterPluginTest method testNoRequestSubjectNoStrategies.
@Test(expected = StopProcessingException.class)
public void testNoRequestSubjectNoStrategies() throws Exception {
QueryResponseImpl response = new QueryResponseImpl(null);
plugin = new FilterPlugin(new Security());
plugin.processPostQuery(response);
fail("Plugin should have thrown exception when no subject was sent in.");
}
use of ddf.catalog.security.filter.plugin.FilterPlugin in project ddf by codice.
the class FilterPluginTest method testPluginFilterResourceNoStrategiesBad.
@Test(expected = StopProcessingException.class)
public void testPluginFilterResourceNoStrategiesBad() throws StopProcessingException {
plugin = new FilterPlugin(new Security());
plugin.setPermissions(new PermissionsImpl());
plugin.processPostResource(resourceResponse, getMoreRolesMetacard());
}
use of ddf.catalog.security.filter.plugin.FilterPlugin in project ddf by codice.
the class FilterPluginTest method setup.
@Before
public void setup() {
AuthorizingRealm realm = mock(AuthorizingRealm.class);
when(realm.getName()).thenReturn("mockRealm");
when(realm.isPermitted(any(PrincipalCollection.class), any(Permission.class))).then(makeDecision());
Collection<org.apache.shiro.realm.Realm> realms = new ArrayList<>();
realms.add(realm);
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(realms);
SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(new Principal() {
@Override
public String getName() {
return "testuser";
}
}, realm.getName());
Subject systemSubject = new MockSubject(manager, principalCollection);
plugin = new FilterPlugin(new Security()) {
@Override
protected Subject getSystemSubject() {
return systemSubject;
}
};
plugin.setPermissions(new PermissionsImpl());
plugin.setSubjectOperations(new SubjectUtils());
plugin.setSecurityLogger(mock(SecurityLogger.class));
QueryRequestImpl request = getSampleRequest();
Map<String, Serializable> properties = new HashMap<>();
Subject subject = new MockSubject(manager, principalCollection);
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
request.setProperties(properties);
incomingResponse = new QueryResponseImpl(request);
ResourceRequest resourceRequest = mock(ResourceRequest.class);
when(resourceRequest.getProperties()).thenReturn(properties);
resourceResponse = new ResourceResponseImpl(resourceRequest, mock(Resource.class));
resourceResponse.setProperties(properties);
DeleteRequest deleteRequest = mock(DeleteRequest.class);
when(deleteRequest.getProperties()).thenReturn(properties);
List<Metacard> deletedMetacards = new ArrayList<>();
deletedMetacards.add(getExactRolesMetacard());
deleteResponse = new DeleteResponseImpl(deleteRequest, properties, deletedMetacards);
List<Metacard> badDeletedMetacards = new ArrayList<>();
badDeletedMetacards.add(getMoreRolesMetacard());
badDeleteResponse = new DeleteResponseImpl(deleteRequest, properties, badDeletedMetacards);
createRequest = new CreateRequestImpl(getExactRolesMetacard());
createRequest.setProperties(properties);
badCreateRequest = new CreateRequestImpl(getMoreRolesMetacard());
badCreateRequest.setProperties(properties);
updateRequest = new UpdateRequestImpl(getExactRolesMetacard().getId(), getExactRolesMetacard());
updateRequest.setProperties(properties);
ResultImpl result1 = new ResultImpl(getMoreRolesMetacard());
ResultImpl result2 = new ResultImpl(getMissingRolesMetacard());
ResultImpl result3 = new ResultImpl(getExactRolesMetacard());
ResultImpl result4 = new ResultImpl(getNoRolesMetacard());
ResultImpl result5 = new ResultImpl(getNoSecurityAttributeMetacard());
incomingResponse.addResult(result1, false);
incomingResponse.addResult(result2, false);
incomingResponse.addResult(result3, false);
incomingResponse.addResult(result4, false);
incomingResponse.addResult(result5, true);
}
Aggregations