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);
}
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));
}
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();
}
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);
}
Aggregations