Search in sources :

Example 1 with Security

use of org.codice.ddf.security.Security in project ddf by codice.

the class HistorianTest method setup.

@Before
public void setup() {
    historian = new Historian();
    uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    historian.setUuidGenerator(uuidGenerator);
    catalogProvider = mock(CatalogProvider.class);
    historian.setCatalogProviders(Collections.singletonList(catalogProvider));
    storageProvider = new InMemoryStorageProvider();
    historian.setStorageProviders(Collections.singletonList(storageProvider));
    historian.setMetacardTypes(Collections.singletonList(MetacardImpl.BASIC_METACARD));
    SubjectIdentity subjectIdentity = mock(SubjectIdentity.class);
    when(subjectIdentity.getUniqueIdentifier(any())).thenReturn("test");
    historian.setSubjectIdentity(subjectIdentity);
    SubjectOperations subjectOperations = mock(SubjectOperations.class);
    when(subjectOperations.getEmailAddress(any(Subject.class))).thenReturn("test@test.com");
    when(subjectOperations.getName(any(Subject.class))).thenReturn("test");
    historian.setSubjectOperations(subjectOperations);
    historian.setSecurityLogger(mock(SecurityLogger.class));
    Security security = mock(Security.class);
    Subject subject = mock(MockSubject.class);
    when(subject.execute(any(Callable.class))).thenCallRealMethod();
    when(security.runAsAdmin(any(PrivilegedAction.class))).thenReturn(subject);
    historian.setSecurity(security);
}
Also used : SubjectOperations(ddf.security.SubjectOperations) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) CatalogProvider(ddf.catalog.source.CatalogProvider) PrivilegedAction(java.security.PrivilegedAction) SubjectIdentity(ddf.security.SubjectIdentity) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) Callable(java.util.concurrent.Callable) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 2 with Security

use of org.codice.ddf.security.Security in project ddf by codice.

the class ReindexCommandTest method testReindex.

@Test
public void testReindex() throws Exception {
    ThreadContext.bind(mock(Subject.class));
    SolrClient cloudClient = mock(SolrClient.class);
    NamedList<Object> pingStatus = new NamedList<>();
    pingStatus.add("status", "OK");
    when(cloudClient.isAvailable()).thenReturn(true);
    QueryResponse hitCountResponse = mock(QueryResponse.class);
    SolrDocumentList hitCountResults = mock(SolrDocumentList.class);
    when(hitCountResults.getNumFound()).thenReturn(1L);
    when(hitCountResponse.getResults()).thenReturn(hitCountResults);
    SolrDocument doc = new SolrDocument();
    doc.put("id_txt", "1234");
    SolrDocumentList dataDocumentList = new SolrDocumentList();
    dataDocumentList.add(doc);
    dataDocumentList.setNumFound(1L);
    QueryResponse dataResponse = mock(QueryResponse.class);
    when(dataResponse.getResults()).thenReturn(dataDocumentList);
    when(dataResponse.getNextCursorMark()).thenReturn("cursor1234");
    SolrDocumentList emptyDocList = new SolrDocumentList();
    dataDocumentList.add(doc);
    QueryResponse emptyResponse = mock(QueryResponse.class);
    when(emptyResponse.getResults()).thenReturn(emptyDocList);
    when(cloudClient.query(any(SolrQuery.class))).thenReturn(hitCountResponse, dataResponse, emptyResponse);
    SolrMetacardClientImpl solrMetacardClient = mock(SolrMetacardClientImpl.class);
    when(solrMetacardClient.createMetacard(any())).thenReturn(getTestMetacard());
    CreateResponse createResponse = mock(CreateResponse.class);
    CatalogFramework catalogFramework = mock(CatalogFramework.class);
    when(catalogFramework.create(any(CreateRequest.class))).thenReturn(createResponse);
    Security security = mock(Security.class);
    Subject subject = mock(Subject.class);
    when(security.runAsAdmin(any())).thenReturn(subject);
    when(subject.execute(any(Callable.class))).thenAnswer(c -> ((Callable) c.getArguments()[0]).call());
    ReindexCommand command = new ReindexCommand();
    command.setSolrjClient(cloudClient);
    command.setMetacardClient(solrMetacardClient);
    command.setNumThread(1);
    command.setCollection("catalog");
    command.setSolrHost("http://localhost:8994/solr");
    command.setCatalogFramework(catalogFramework);
    command.security = security;
    command.execute();
    verify(catalogFramework, times(1)).create(any(CreateRequest.class));
}
Also used : NamedList(org.apache.solr.common.util.NamedList) CreateResponse(ddf.catalog.operation.CreateResponse) CreateRequest(ddf.catalog.operation.CreateRequest) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Security(org.codice.ddf.security.Security) Subject(ddf.security.Subject) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Callable(java.util.concurrent.Callable) SolrDocument(org.apache.solr.common.SolrDocument) SolrClient(org.codice.solr.client.solrj.SolrClient) SolrMetacardClientImpl(ddf.catalog.source.solr.SolrMetacardClientImpl) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Test(org.junit.Test)

Example 3 with Security

use of org.codice.ddf.security.Security in project ddf by codice.

the class CatalogFeatureIndexerTest method setUp.

@Before
public void setUp() throws SecurityServiceException, InvocationTargetException, FeatureExtractionException, UnsupportedQueryException, SourceUnavailableException, FederationException {
    Security security = mock(Security.class);
    doAnswer(invocation -> {
        Callable callback = (Callable) invocation.getArguments()[0];
        callback.call();
        return null;
    }).when(security).runWithSubjectOrElevate(any(Callable.class));
    featureExtractor = mock(FeatureExtractor.class);
    doAnswer(invocation -> {
        FeatureExtractor.ExtractionCallback callback = (FeatureExtractor.ExtractionCallback) invocation.getArguments()[1];
        callback.extracted(getExampleFeature());
        return null;
    }).when(featureExtractor).pushFeaturesToExtractionCallback(eq(RESOURCE_PATH), any(FeatureExtractor.ExtractionCallback.class));
    catalogFramework = mock(CatalogFramework.class);
    CatalogHelper catalogHelper = new CatalogHelper(FILTER_BUILDER);
    featureIndexer = new CatalogFeatureIndexer(catalogFramework, catalogHelper, generateMetacardType(), security);
    featureIndexer.setSecurity(security);
    QueryResponse queryResponse = mock(QueryResponse.class);
    Result result = mock(Result.class);
    when(result.getMetacard()).thenReturn(getExampleMetacard());
    when(queryResponse.getResults()).thenReturn(Collections.singletonList(result));
    when(catalogFramework.query(any())).thenReturn(queryResponse);
    exampleMetacard = getExampleMetacard();
}
Also used : FeatureExtractor(org.codice.ddf.spatial.geocoding.FeatureExtractor) QueryResponse(ddf.catalog.operation.QueryResponse) CatalogFramework(ddf.catalog.CatalogFramework) Security(org.codice.ddf.security.Security) Callable(java.util.concurrent.Callable) Result(ddf.catalog.data.Result) Before(org.junit.Before)

Example 4 with Security

use of org.codice.ddf.security.Security in project ddf by codice.

the class AbstractIntegrationTest method initFacades.

@SuppressWarnings({ "squid:S2696" /* writing to static ddfHome to share state between test methods */
})
@PostTestConstruct
public void initFacades() {
    RestAssured.config = RestAssuredConfig.config().xmlConfig(XmlConfig.xmlConfig().namespaceAware(false));
    ddfHome = System.getProperty(DDF_HOME_PROPERTY);
    adminConfig = new AdminConfig(configAdmin);
    Security security = new org.codice.ddf.security.impl.Security();
    ((org.codice.ddf.security.impl.Security) security).setSecurityLogger(new SecurityLoggerImpl(new SubjectUtils()));
    // This proxy runs the service manager as the system subject
    serviceManager = (ServiceManager) Proxy.newProxyInstance(AbstractIntegrationTest.class.getClassLoader(), ServiceManagerImpl.class.getInterfaces(), new ServiceManagerProxy(new ServiceManagerImpl(metatype, adminConfig, bundleContext, bundleService, features), security));
    catalogBundle = new CatalogBundle(serviceManager, adminConfig);
    securityPolicy = new SecurityPolicyConfigurator(serviceManager, configAdmin);
    urlResourceReaderConfigurator = new UrlResourceReaderConfigurator(configAdmin);
    console = new KarafConsole(bundleContext, features, sessionFactory);
}
Also used : SecurityLoggerImpl(ddf.security.audit.impl.SecurityLoggerImpl) SubjectUtils(ddf.security.service.impl.SubjectUtils) UrlResourceReaderConfigurator(org.codice.ddf.itests.common.config.UrlResourceReaderConfigurator) Security(org.codice.ddf.security.Security) SecurityPolicyConfigurator(org.codice.ddf.itests.common.security.SecurityPolicyConfigurator) PostTestConstruct(org.codice.ddf.test.common.annotations.PostTestConstruct)

Aggregations

Security (org.codice.ddf.security.Security)4 Callable (java.util.concurrent.Callable)3 CatalogFramework (ddf.catalog.CatalogFramework)2 Subject (ddf.security.Subject)2 Before (org.junit.Before)2 Result (ddf.catalog.data.Result)1 CreateRequest (ddf.catalog.operation.CreateRequest)1 CreateResponse (ddf.catalog.operation.CreateResponse)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 CatalogProvider (ddf.catalog.source.CatalogProvider)1 SolrMetacardClientImpl (ddf.catalog.source.solr.SolrMetacardClientImpl)1 SubjectIdentity (ddf.security.SubjectIdentity)1 SubjectOperations (ddf.security.SubjectOperations)1 SecurityLogger (ddf.security.audit.SecurityLogger)1 SecurityLoggerImpl (ddf.security.audit.impl.SecurityLoggerImpl)1 SubjectUtils (ddf.security.service.impl.SubjectUtils)1 PrivilegedAction (java.security.PrivilegedAction)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1