Search in sources :

Example 1 with ClientBuilderFactory

use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.

the class DownloadsStatusEventListenerTest method testGetDownloadStatus.

@Test
public void testGetDownloadStatus() throws URISyntaxException, DownloadException, InterruptedException, IOException {
    File downloadSrcFile = new File(this.getClass().getResource("/125bytes.txt").toURI());
    File downloadFile = prepareDownloadFile(downloadSrcFile);
    MetacardImpl testMetacard = new MetacardImpl();
    testMetacard.setId("easyas123");
    testMetacard.setResourceURI(downloadFile.toURI());
    testMetacard.setResourceSize("125");
    ClientBuilderFactory clientBuilderFactory = new ClientBuilderFactoryImpl();
    URLResourceReader testURLResourceReader = new URLResourceReader(clientBuilderFactory);
    testURLResourceReader.setRootResourceDirectories(new HashSet<String>(Arrays.asList(localResourcePath.toString())));
    List<ResourceReader> testResourceReaderList = Collections.singletonList((ResourceReader) testURLResourceReader);
    Map<String, Serializable> tmpMap = Collections.emptyMap();
    Map<String, Integer> idToBytes = new HashMap<String, Integer>();
    testGetDownloadStatusHelper(null, null, null);
    testDownloadManager.download(mock(ResourceRequest.class), testMetacard, new LocalResourceRetriever(testResourceReaderList, testMetacard.getResourceURI(), null, tmpMap));
    TimeUnit.SECONDS.sleep(2);
    testGetDownloadStatusHelper(idToBytes, DownloadManagerState.DownloadState.COMPLETED.name(), downloadFile.getName());
}
Also used : URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ClientBuilderFactoryImpl(org.codice.ddf.cxf.client.impl.ClientBuilderFactoryImpl) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) LocalResourceRetriever(ddf.catalog.resourceretriever.LocalResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) File(java.io.File) Test(org.junit.Test)

Example 2 with ClientBuilderFactory

use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.

the class CswSubscriptionEndpointTest method setUp.

@Before
public void setUp() throws Exception {
    systemKeystoreFile = temporaryFolder.newFile("serverKeystore.jks");
    FileOutputStream systemKeyOutStream = new FileOutputStream(systemKeystoreFile);
    InputStream systemKeyStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverKeystore.jks");
    IOUtils.copy(systemKeyStream, systemKeyOutStream);
    systemTruststoreFile = temporaryFolder.newFile("serverTruststore.jks");
    FileOutputStream systemTrustOutStream = new FileOutputStream(systemTruststoreFile);
    InputStream systemTrustStream = CswSubscriptionEndpointTest.class.getResourceAsStream("/serverTruststore.jks");
    IOUtils.copy(systemTrustStream, systemTrustOutStream);
    System.setProperty(SecurityConstants.KEYSTORE_TYPE, "jks");
    System.setProperty(SecurityConstants.TRUSTSTORE_TYPE, "jks");
    System.setProperty("ddf.home", "");
    System.setProperty(SecurityConstants.KEYSTORE_PATH, systemKeystoreFile.getAbsolutePath());
    System.setProperty(SecurityConstants.TRUSTSTORE_PATH, systemTruststoreFile.getAbsolutePath());
    System.setProperty(SecurityConstants.KEYSTORE_PASSWORD, password);
    System.setProperty(SecurityConstants.TRUSTSTORE_PASSWORD, password);
    eventProcessor = mock(EventProcessor.class);
    mockInputManager = mock(TransformerManager.class);
    mockContext = mock(BundleContext.class);
    mockMimeTypeManager = mock(TransformerManager.class);
    mockSchemaManager = mock(TransformerManager.class);
    validator = mock(Validator.class);
    queryFactory = mock(CswQueryFactory.class);
    query = mock(QueryRequest.class);
    when(queryFactory.getQuery(any(GetRecordsType.class))).thenReturn(query);
    serviceRegistration = mock(ServiceRegistration.class);
    subscriptionReference = mock(ServiceReference.class);
    bundle = mock(Bundle.class);
    osgiFilter = mock(Filter.class);
    configAdminRef = mock(ServiceReference.class);
    configAdmin = mock(ConfigurationAdmin.class);
    config = mock(Configuration.class);
    SecureCxfClientFactory mockFactory = mock(SecureCxfClientFactory.class);
    clientBuilderFactory = mock(ClientBuilderFactory.class);
    ClientBuilder<WebClient> clientBuilder = new ClientBuilderImpl<WebClient>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<WebClient> build() {
            return mockFactory;
        }
    };
    when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
    Configuration[] configArry = { config };
    defaultRequest = createDefaultGetRecordsRequest();
    subscription = new CswSubscription(mockMimeTypeManager, defaultRequest.get202RecordsType(), query, clientBuilderFactory, security);
    when(osgiFilter.toString()).thenReturn(FILTER_STR);
    doReturn(serviceRegistration).when(mockContext).registerService(eq(Subscription.class.getName()), any(Subscription.class), any(Dictionary.class));
    doReturn(configAdminRef).when(mockContext).getServiceReference(eq(ConfigurationAdmin.class.getName()));
    when(serviceRegistration.getReference()).thenReturn(subscriptionReference);
    doReturn(bundle).when(subscriptionReference).getBundle();
    when(subscriptionReference.getBundle()).thenReturn(bundle);
    when(bundle.getBundleId()).thenReturn(bundleId);
    when(mockContext.createFilter(anyString())).thenReturn(osgiFilter);
    when(mockContext.getService(eq(configAdminRef))).thenReturn(configAdmin);
    when(mockContext.getService(eq(subscriptionReference))).thenReturn(subscription);
    when(configAdmin.listConfigurations(eq(FILTER_STR))).thenReturn(configArry);
    when(configAdmin.createFactoryConfiguration(anyString(), isNull())).thenReturn(config);
    cswSubscriptionEndpoint = new CswSubscriptionEndpointStub(eventProcessor, mockMimeTypeManager, mockSchemaManager, mockInputManager, validator, queryFactory, mockContext, clientBuilderFactory, security);
}
Also used : Dictionary(java.util.Dictionary) Configuration(org.osgi.service.cm.Configuration) SecurityManager(ddf.security.service.SecurityManager) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Subscription(ddf.catalog.event.Subscription) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ServiceRegistration(org.osgi.framework.ServiceRegistration) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) TransformerManager(org.codice.ddf.spatial.ogc.csw.catalog.common.transformer.TransformerManager) QueryRequest(ddf.catalog.operation.QueryRequest) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) WebClient(org.apache.cxf.jaxrs.client.WebClient) ServiceReference(org.osgi.framework.ServiceReference) Filter(org.osgi.framework.Filter) FileOutputStream(java.io.FileOutputStream) EventProcessor(ddf.catalog.event.EventProcessor) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) CswSubscription(org.codice.ddf.spatial.ogc.csw.catalog.endpoint.event.CswSubscription) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 3 with ClientBuilderFactory

use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.

the class WfsSourceTest method setUpMocks.

private void setUpMocks(final List<String> supportedGeos, final String srsName, final int results, final int hits) throws WfsException {
    SecureCxfClientFactory<ExtendedWfs> mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    clientBuilderFactory = mock(ClientBuilderFactory.class);
    ClientBuilder<ExtendedWfs> clientBuilder = new ClientBuilderImpl<ExtendedWfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<ExtendedWfs> build() {
            return mockFactory;
        }
    };
    when(clientBuilderFactory.<ExtendedWfs>getClientBuilder()).thenReturn(clientBuilder);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    mockCapabilities.setFilterCapabilities(new FilterCapabilities());
    mockCapabilities.getFilterCapabilities().setSpatialCapabilities(new SpatialCapabilitiesType());
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setSpatialOperators(new SpatialOperatorsType());
    if (CollectionUtils.isNotEmpty(supportedGeos)) {
        mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getSpatialOperators().getSpatialOperator().addAll(supportedGeos.stream().map(opName -> {
            SpatialOperatorType spatialOperatorType = new SpatialOperatorType();
            spatialOperatorType.setName(SpatialOperatorNameType.fromValue(opName));
            return spatialOperatorType;
        }).collect(Collectors.toList()));
    }
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().setGeometryOperands(new GeometryOperandsType());
    mockCapabilities.getFilterCapabilities().getSpatialCapabilities().getGeometryOperands().getGeometryOperand().addAll(Arrays.asList(Wfs11Constants.POLYGON, Wfs11Constants.POINT));
    sampleFeatures = new ArrayList<>();
    mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
    for (int ii = 0; ii < results; ii++) {
        FeatureTypeType feature = new FeatureTypeType();
        QName qName;
        if (ii == 0) {
            qName = new QName("SampleFeature" + ii);
        } else {
            qName = new QName("http://example.com", "SampleFeature" + ii, "Prefix" + ii);
        }
        sampleFeatures.add(qName);
        feature.setName(qName);
        if (null != srsName) {
            feature.setDefaultSRS(srsName);
        }
        mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
    }
    List<Metacard> metacards = new ArrayList<>(results);
    for (int i = 0; i < results; i++) {
        MetacardImpl mc = new MetacardImpl();
        mc.setId("ID_" + (i + 1));
        metacards.add(mc);
    }
    when(mockWfs.getFeature(withResultType(ResultTypeType.HITS))).thenReturn(new WfsFeatureCollectionImpl(hits));
    when(mockWfs.getFeature(withResultType(ResultTypeType.RESULTS))).thenReturn(new WfsFeatureCollectionImpl(results, metacards));
    final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
    doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
    source = new WfsSource(clientBuilderFactory, encryptionService, mockScheduler);
    source.setId(WFS_ID);
    source.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    source.setContext(mockContext);
    source.setWfsMetacardTypeRegistry(mockWfsMetacardTypeRegistry);
    source.setMetacardTypeEnhancers(Collections.emptyList());
    source.setMetacardMappers(metacardMappers);
    source.setPollInterval(10);
    source.setWfsUrl(SAMPLE_WFS_URL);
    source.setSupportsStartIndex(false);
    source.setForceAllGeometryOperands(forceAllGeometryOperands);
    source.init();
}
Also used : SecurityManager(ddf.security.service.SecurityManager) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) ArrayList(java.util.ArrayList) SpatialCapabilitiesType(net.opengis.filter.v_1_1_0.SpatialCapabilitiesType) FilterCapabilities(net.opengis.filter.v_1_1_0.FilterCapabilities) SpatialOperatorsType(net.opengis.filter.v_1_1_0.SpatialOperatorsType) WfsFeatureCollectionImpl(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsFeatureCollectionImpl) GeometryOperandsType(net.opengis.filter.v_1_1_0.GeometryOperandsType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v110.catalog.common.GetCapabilitiesRequest) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) FeatureTypeType(net.opengis.wfs.v_1_1_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_1_1_0.FeatureTypeListType) QName(javax.xml.namespace.QName) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) SpatialOperatorType(net.opengis.filter.v_1_1_0.SpatialOperatorType) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 4 with ClientBuilderFactory

use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.

the class CrlGeneratorTest method testGettingDemCrlFromUrl.

@Test
public void testGettingDemCrlFromUrl() throws Exception {
    ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
    CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin);
    crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
    crlGenerator.setCrlLocationUrl("https://testurl:8993");
    crlGenerator.setCrlByUrlEnabled(true);
    crlGenerator.run();
    InputStream inputStream = new FileInputStream(new File(Paths.get(CrlGenerator.crlFileLocation + CrlGenerator.DEM_CRL).toString()));
    byte[] encoded = new byte[inputStream.available()];
    inputStream.read(encoded);
    assertTrue(Arrays.equals(demEncodedCrl, encoded));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) File(java.io.File) FileInputStream(java.io.FileInputStream) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 5 with ClientBuilderFactory

use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.

the class CrlGeneratorTest method testSetCrlByUrlEnabled.

@Test
public void testSetCrlByUrlEnabled() {
    ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
    ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
    CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin, scheduler);
    crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
    crlGenerator.setCrlByUrlEnabled(false);
    Mockito.verify(scheduler, times(0)).submit(any(Callable.class));
    crlGenerator.setCrlByUrlEnabled(true);
    Mockito.verify(scheduler, times(0)).submit(any(Callable.class));
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Callable(java.util.concurrent.Callable) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Aggregations

ClientBuilderFactory (org.codice.ddf.cxf.client.ClientBuilderFactory)14 SecurityLogger (ddf.security.audit.SecurityLogger)13 Test (org.junit.Test)8 SecurityManager (ddf.security.service.SecurityManager)7 ClientBuilderImpl (org.codice.ddf.cxf.client.impl.ClientBuilderImpl)7 OAuthSecurity (org.codice.ddf.cxf.oauth.OAuthSecurity)7 SamlSecurity (org.codice.ddf.security.jaxrs.SamlSecurity)7 WebClient (org.apache.cxf.jaxrs.client.WebClient)4 Serializable (java.io.Serializable)3 SecureCxfClientFactory (org.codice.ddf.cxf.client.SecureCxfClientFactory)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)2 ResourceReader (ddf.catalog.resource.ResourceReader)2 EncryptionService (ddf.security.encryption.EncryptionService)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2 InputStream (java.io.InputStream)2 URI (java.net.URI)2 ArrayList (java.util.ArrayList)2 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)2