Search in sources :

Example 46 with UpdateRequestImpl

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);
}
Also used : Serializable(java.io.Serializable) HashSet(java.util.HashSet) Set(java.util.Set) Query(ddf.catalog.operation.Query) HashMap(java.util.HashMap) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) HashSet(java.util.HashSet)

Example 47 with UpdateRequestImpl

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);
}
Also used : SubjectUtils(ddf.security.service.impl.SubjectUtils) Serializable(java.io.Serializable) FilterPlugin(ddf.catalog.security.filter.plugin.FilterPlugin) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PrincipalCollection(org.apache.shiro.subject.PrincipalCollection) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResultImpl(ddf.catalog.data.impl.ResultImpl) Security(org.codice.ddf.security.impl.Security) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) CollectionPermission(ddf.security.permission.CollectionPermission) Permission(org.apache.shiro.authz.Permission) KeyValueCollectionPermission(ddf.security.permission.KeyValueCollectionPermission) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) SimplePrincipalCollection(org.apache.shiro.subject.SimplePrincipalCollection) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) DefaultSecurityManager(org.apache.shiro.mgt.DefaultSecurityManager) DelegatingSubject(org.apache.shiro.subject.support.DelegatingSubject) Subject(ddf.security.Subject) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Metacard(ddf.catalog.data.Metacard) DeleteResponseImpl(ddf.catalog.operation.impl.DeleteResponseImpl) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) ResourceRequest(ddf.catalog.operation.ResourceRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) DeleteRequest(ddf.catalog.operation.DeleteRequest) Principal(java.security.Principal) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 48 with UpdateRequestImpl

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());
}
Also used : Metacard(ddf.catalog.data.Metacard) UpdateRequest(ddf.catalog.operation.UpdateRequest) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) URI(java.net.URI) Date(java.util.Date) Test(org.junit.Test)

Example 49 with UpdateRequestImpl

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();
}
Also used : UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) Before(org.junit.Before)

Example 50 with UpdateRequestImpl

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");
}
Also used : AbstractMap(java.util.AbstractMap) Serializable(java.io.Serializable) Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) UpdateRequestImpl(ddf.catalog.operation.impl.UpdateRequestImpl) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Aggregations

UpdateRequestImpl (ddf.catalog.operation.impl.UpdateRequestImpl)57 Metacard (ddf.catalog.data.Metacard)42 ArrayList (java.util.ArrayList)35 Test (org.junit.Test)34 UpdateRequest (ddf.catalog.operation.UpdateRequest)28 HashMap (java.util.HashMap)28 Serializable (java.io.Serializable)26 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)21 UpdateResponse (ddf.catalog.operation.UpdateResponse)19 IngestException (ddf.catalog.source.IngestException)13 AbstractMap (java.util.AbstractMap)13 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 CatalogFramework (ddf.catalog.CatalogFramework)11 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)10 CreateRequestImpl (ddf.catalog.operation.impl.CreateRequestImpl)10 List (java.util.List)10 Result (ddf.catalog.data.Result)9 URI (java.net.URI)9 Entry (java.util.Map.Entry)9