use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class OperationPluginTest method testPluginWithRole.
private void testPluginWithRole(String role) throws Exception {
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
HashMap<String, Set<String>> perms = new HashMap<>();
Set<String> roles = new HashSet<>();
roles.add(role);
perms.put("Roles", roles);
properties.put(PolicyPlugin.OPERATION_SECURITY, perms);
CreateRequestImpl request = new CreateRequestImpl(new ArrayList<>(), properties);
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class), properties);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(new ArrayList<>(), "", properties);
DeleteRequestImpl deleteRequest = new DeleteRequestImpl(new String[] { "" }, properties);
ResourceRequestById resourceRequestById = new ResourceRequestById("", properties);
plugin.processPreCreate(request);
plugin.processPreQuery(queryRequest);
plugin.processPreUpdate(updateRequest, new HashMap<>());
plugin.processPreDelete(deleteRequest);
plugin.processPreResource(resourceRequestById);
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class OperationPluginTest method noPolicyRequestTest.
@Test
public void noPolicyRequestTest() throws Exception {
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
CreateRequestImpl request = new CreateRequestImpl(new ArrayList<>(), properties);
plugin.processPreCreate(request);
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class SecurityPluginTest method testNominalCaseCreateWithNonResourceMetacard.
@Test
public void testNominalCaseCreateWithNonResourceMetacard() throws Exception {
Subject mockSubject = setupMockSubject();
ThreadContext.bind(mockSubject);
MetacardImpl metacardWithTags = new MetacardImpl();
Set<String> setOfTags = new HashSet<String>();
setOfTags.add("workspace");
metacardWithTags.setTags(setOfTags);
CreateRequest request = new CreateRequestImpl(metacardWithTags);
SecurityPlugin plugin = new SecurityPlugin(subjectIdentity);
request = plugin.processPreCreate(request);
assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
assertThat(request.getMetacards().size(), is(1));
assertThat(request.getMetacards().get(0).getAttribute(Metacard.POINT_OF_CONTACT), is(nullValue()));
}
use of ddf.catalog.operation.impl.CreateRequestImpl 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);
}
use of ddf.catalog.operation.impl.CreateRequestImpl in project ddf by codice.
the class PluginTest method testCreateBadTransform.
@Test(expected = PluginExecutionException.class)
public void testCreateBadTransform() throws PluginExecutionException, CatalogTransformerException, IOException, IngestException, SourceUnavailableException {
// given
when(transformer.transform(isA(Metacard.class), isA(Map.class))).thenThrow(CatalogTransformerException.class);
CreateResponse createResponse = new CreateResponseImpl(new CreateRequestImpl(metacard), null, Arrays.asList(metacard));
// when
plugin.process(createResponse);
}
Aggregations