use of ddf.catalog.operation.impl.UpdateRequestImpl 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.UpdateRequestImpl 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.UpdateRequestImpl in project ddf by codice.
the class MetacardGroomerPluginTest method testUpdateByAlternativeIdentifier.
@Test
public void testUpdateByAlternativeIdentifier() throws PluginExecutionException, StopProcessingException, URISyntaxException {
Date snapshotOfNow = new Date();
Metacard inputMetacard = getStandardMetacard(null);
URI[] uris = new URI[1];
uris[0] = new URI(SAMPLE_ID);
UpdateRequestImpl inputRequest = new UpdateRequestImpl(uris, Arrays.asList(copy(inputMetacard)));
UpdateRequest returnedRequest = plugin.process(inputRequest);
assertNotNull(returnedRequest);
assertThat(returnedRequest.getUpdates().size(), is(1));
Metacard outputMetacard = returnedRequest.getUpdates().get(0).getValue();
assertThat(inputMetacard.getId(), is(outputMetacard.getId()));
assertEquals(DEFAULT_TITLE, outputMetacard.getTitle());
assertEquals(DEFAULT_LOCATION, outputMetacard.getLocation());
assertEquals(DEFAULT_TYPE, outputMetacard.getContentTypeName());
assertEquals(DEFAULT_VERSION, outputMetacard.getContentTypeVersion());
assertThat(outputMetacard.getMetadata(), is(DEFAULT_METADATA));
assertThat(outputMetacard.getCreatedDate().getTime(), is(inputMetacard.getCreatedDate().getTime()));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime(), equalTo(((Date) inputMetacard.getAttribute(Core.METACARD_CREATED).getValue()).getTime()));
assertThat(outputMetacard.getModifiedDate().getTime(), is(equalTo(inputMetacard.getModifiedDate().getTime())));
assertThat(((Date) outputMetacard.getAttribute(Core.METACARD_MODIFIED).getValue()).getTime(), is(greaterThanOrEqualTo(snapshotOfNow.getTime())));
assertEquals(inputMetacard.getEffectiveDate(), outputMetacard.getEffectiveDate());
assertEquals(inputMetacard.getExpirationDate(), outputMetacard.getExpirationDate());
assertTrue(Arrays.equals(inputMetacard.getThumbnail(), outputMetacard.getThumbnail()));
assertEquals(inputMetacard.getLocation(), outputMetacard.getLocation());
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class PointOfContactUpdatePluginTest method setup.
@Before
public void setup() throws Exception {
listOfUpdatedMetacards = getListOfUpdatedMetacards();
updateRequestInput = new UpdateRequestImpl(new String[] { RESOURCE_ID1, RESOURCE_ID2, REGISTRY_ID }, listOfUpdatedMetacards);
existingMetacards = getPreviousMetacardsWithPointOfContact();
}
use of ddf.catalog.operation.impl.UpdateRequestImpl in project ddf by codice.
the class SecurityAuditPluginTest method testChangedAttributeNotInAuditConfigIsNotAudited.
@Test
public void testChangedAttributeNotInAuditConfigIsNotAudited() throws StopProcessingException {
MetacardImpl existingMetacard = new MetacardImpl();
MetacardImpl updateMetacard = new MetacardImpl();
existingMetacard.setAttribute(Metacard.METADATA, "A test string");
updateMetacard.setAttribute(Metacard.METADATA, "A different test string");
existingMetacard.setAttribute(Metacard.ID, "test");
updateMetacard.setAttribute(Metacard.ID, "test");
List<Map.Entry<Serializable, Metacard>> updateMetacards = new ArrayList<>();
updateMetacards.add(new AbstractMap.SimpleEntry<Serializable, Metacard>(metacardKey, updateMetacard));
Map<String, Metacard> existingMetacards = new HashMap<>();
existingMetacards.put(metacardKey, existingMetacard);
UpdateRequestImpl updateRequest = new UpdateRequestImpl(updateMetacards, Metacard.METADATA, null);
securityAuditPlugin.processPreUpdate(updateRequest, existingMetacards);
verify(securityAuditPlugin, never()).auditMetacardUpdate(Metacard.METADATA, "test", "A test string", "A different test string");
}
Aggregations