Search in sources :

Example 1 with SecureCxfClientFactory

use of org.codice.ddf.cxf.client.SecureCxfClientFactory 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 2 with SecureCxfClientFactory

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

the class SolrRestTest method setUp.

@Before
public void setUp() {
    EncryptionService encryptionService = mock(EncryptionService.class);
    when(encryptionService.decrypt(anyString())).thenReturn("test");
    ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
    SecureCxfClientFactory secureCxfClientFactory = mock(SecureCxfClientFactory.class);
    ClientBuilder clientBuilder = new ClientBuilderImpl(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory build() {
            return secureCxfClientFactory;
        }
    };
    when(clientBuilderFactory.getClientBuilder()).thenReturn(clientBuilder);
    solrRest = new SolrRest(clientBuilderFactory, encryptionService);
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) EncryptionService(ddf.security.encryption.EncryptionService) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) ClientBuilder(org.codice.ddf.cxf.client.ClientBuilder) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 3 with SecureCxfClientFactory

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

the class WfsSourceTest method getWfsSource.

private WfsSource getWfsSource(final String schema, final FilterCapabilities filterCapabilities, final int numFeatures, final boolean throwExceptionOnDescribeFeatureType, boolean prefix, int numReturned) throws WfsException {
    mockFactory = mock(SecureCxfClientFactory.class);
    when(mockFactory.getClient()).thenReturn(mockWfs);
    ClientBuilder<Wfs> clientBuilder = new ClientBuilderImpl<Wfs>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<Wfs> build() {
            return mockFactory;
        }
    };
    when(mockClientBuilderFactory.<Wfs>getClientBuilder()).thenReturn(clientBuilder);
    // GetCapabilities Response
    when(mockWfs.getCapabilities(any(GetCapabilitiesRequest.class))).thenReturn(mockCapabilities);
    when(mockFeatureCollection.getMembers()).thenAnswer(new Answer<List<Metacard>>() {

        @Override
        public List<Metacard> answer(InvocationOnMock invocation) {
            // Create as many metacards as there are features
            List<Metacard> metacards = new ArrayList<>(numFeatures);
            for (int i = 0; i < numFeatures; i++) {
                MetacardImpl mc = new MetacardImpl();
                mc.setId("ID_" + (i + 1));
                metacards.add(mc);
            }
            return metacards;
        }
    });
    if (numReturned != NULL_NUM_RETURNED) {
        when(mockFeatureCollection.getNumberReturned()).thenReturn(BigInteger.valueOf(numReturned));
    } else {
        when(mockFeatureCollection.getNumberReturned()).thenReturn(null);
    }
    when(mockWfs.getFeature(any(GetFeatureType.class))).thenReturn(mockFeatureCollection);
    mockCapabilities.setFilterCapabilities(filterCapabilities);
    when(mockAvailabilityTask.isAvailable()).thenReturn(true);
    mockCapabilities.setFeatureTypeList(new FeatureTypeListType());
    for (int ii = 0; ii < numFeatures; ii++) {
        FeatureTypeType feature = new FeatureTypeType();
        QName qName;
        if (prefix) {
            qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii, "Prefix" + ii);
        } else {
            qName = new QName("http://example.com", SAMPLE_FEATURE_NAME + ii);
        }
        feature.setName(qName);
        feature.setDefaultCRS(GeospatialUtil.EPSG_4326_URN);
        mockCapabilities.getFeatureTypeList().getFeatureType().add(feature);
    }
    XmlSchema xmlSchema = null;
    if (StringUtils.isNotBlank(schema)) {
        XmlSchemaCollection schemaCollection = new XmlSchemaCollection();
        WfsUriResolver wfsUriResolver = new WfsUriResolver();
        wfsUriResolver.setGmlNamespace(Wfs20Constants.GML_3_2_NAMESPACE);
        wfsUriResolver.setWfsNamespace(Wfs20Constants.WFS_2_0_NAMESPACE);
        schemaCollection.setSchemaResolver(wfsUriResolver);
        xmlSchema = schemaCollection.read(new StreamSource(new ByteArrayInputStream(schema.getBytes())));
    }
    if (throwExceptionOnDescribeFeatureType) {
        when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenThrow(new WfsException(""));
    } else {
        when(mockWfs.describeFeatureType(any(DescribeFeatureTypeRequest.class))).thenReturn(xmlSchema);
    }
    final ScheduledFuture<?> mockAvailabilityPollFuture = mock(ScheduledFuture.class);
    doReturn(mockAvailabilityPollFuture).when(mockScheduler).scheduleWithFixedDelay(any(), anyInt(), anyInt(), any());
    WfsSource wfsSource = new WfsSource(mockClientBuilderFactory, encryptionService, mockScheduler);
    wfsSource.setContext(mockContext);
    wfsSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    wfsSource.setFeatureCollectionReader(mockReader);
    wfsSource.setMetacardToFeatureMapper(metacardMappers);
    wfsSource.setPollInterval(10);
    wfsSource.setWfsUrl(SAMPLE_WFS_URL);
    wfsSource.init();
    return wfsSource;
}
Also used : SecurityManager(ddf.security.service.SecurityManager) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) WfsUriResolver(org.codice.ddf.spatial.ogc.wfs.catalog.source.WfsUriResolver) List(java.util.List) ArrayList(java.util.ArrayList) GetFeatureType(net.opengis.wfs.v_2_0_0.GetFeatureType) GetCapabilitiesRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.GetCapabilitiesRequest) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) FeatureTypeType(net.opengis.wfs.v_2_0_0.FeatureTypeType) FeatureTypeListType(net.opengis.wfs.v_2_0_0.FeatureTypeListType) Wfs(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs) QName(javax.xml.namespace.QName) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) StreamSource(javax.xml.transform.stream.StreamSource) XmlSchemaCollection(org.apache.ws.commons.schema.XmlSchemaCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) XmlSchema(org.apache.ws.commons.schema.XmlSchema) ByteArrayInputStream(java.io.ByteArrayInputStream) WfsException(org.codice.ddf.spatial.ogc.wfs.catalog.common.WfsException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) DescribeFeatureTypeRequest(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.DescribeFeatureTypeRequest) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Aggregations

SecurityLogger (ddf.security.audit.SecurityLogger)3 SecurityManager (ddf.security.service.SecurityManager)3 SecureCxfClientFactory (org.codice.ddf.cxf.client.SecureCxfClientFactory)3 ClientBuilderImpl (org.codice.ddf.cxf.client.impl.ClientBuilderImpl)3 OAuthSecurity (org.codice.ddf.cxf.oauth.OAuthSecurity)3 SamlSecurity (org.codice.ddf.security.jaxrs.SamlSecurity)3 ClientBuilderFactory (org.codice.ddf.cxf.client.ClientBuilderFactory)2 Before (org.junit.Before)2 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 EventProcessor (ddf.catalog.event.EventProcessor)1 Subscription (ddf.catalog.event.Subscription)1 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 EncryptionService (ddf.security.encryption.EncryptionService)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 Dictionary (java.util.Dictionary)1 List (java.util.List)1