Search in sources :

Example 1 with ClientBuilderImpl

use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl 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 ClientBuilderImpl

use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl 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 3 with ClientBuilderImpl

use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.

the class SecureCxfClientFactoryTest method testHttpsClientWithSystemProperty.

@Test
public void testHttpsClientWithSystemProperty() {
    PropertyResolver mockPropertyResolver = mock(PropertyResolver.class);
    when(mockPropertyResolver.getResolvedString()).thenReturn(SECURE_ENDPOINT);
    SecureCxfClientFactory<IDummy> secureCxfClientFactory = new ClientBuilderImpl<IDummy>(null, samlSecurity, securityLogger, securityManager).endpoint(SECURE_ENDPOINT).interfaceClass(IDummy.class).entityProviders(null).interceptor(null).disableCnCheck(false).allowRedirects(false).propertyResolver(mockPropertyResolver).build();
    Client unsecuredClient = WebClient.client(secureCxfClientFactory.getClient());
    assertThat(unsecuredClient.getBaseURI().toASCIIString(), is(SECURE_ENDPOINT));
    verify(mockPropertyResolver).getResolvedString();
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) PropertyResolver(org.codice.ddf.configuration.PropertyResolver) WebClient(org.apache.cxf.jaxrs.client.WebClient) Client(org.apache.cxf.jaxrs.client.Client) Test(org.junit.Test)

Example 4 with ClientBuilderImpl

use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.

the class SecureCxfClientFactoryTest method testSecureWebClient.

@Test
public void testSecureWebClient() {
    SecureCxfClientFactory<IDummy> secureCxfClientFactory = new ClientBuilderImpl<IDummy>(null, samlSecurity, securityLogger, securityManager).endpoint(SECURE_ENDPOINT).interfaceClass(IDummy.class).useSamlEcp(true).build();
    WebClient client = secureCxfClientFactory.getWebClient();
    assertThat(hasEcpEnabled(client), is(true));
    assertThat(client.getBaseURI().toASCIIString().equals(SECURE_ENDPOINT), is(true));
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 5 with ClientBuilderImpl

use of org.codice.ddf.cxf.client.impl.ClientBuilderImpl in project ddf by codice.

the class SecureCxfClientFactoryTest method validateConduit.

@Test
public void validateConduit() {
    IDummy clientForSubject = new ClientBuilderImpl<IDummy>(null, samlSecurity, securityLogger, securityManager).endpoint(SECURE_ENDPOINT).interfaceClass(IDummy.class).entityProviders(null).interceptor(null).disableCnCheck(true).allowRedirects(true).build().getClient();
    HTTPConduit httpConduit = WebClient.getConfig(WebClient.client(clientForSubject)).getHttpConduit();
    assertThat(httpConduit.getTlsClientParameters().isDisableCNCheck(), is(true));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) Test(org.junit.Test)

Aggregations

ClientBuilderImpl (org.codice.ddf.cxf.client.impl.ClientBuilderImpl)12 SecurityLogger (ddf.security.audit.SecurityLogger)9 SecurityManager (ddf.security.service.SecurityManager)9 OAuthSecurity (org.codice.ddf.cxf.oauth.OAuthSecurity)9 SamlSecurity (org.codice.ddf.security.jaxrs.SamlSecurity)9 WebClient (org.apache.cxf.jaxrs.client.WebClient)7 ClientBuilderFactory (org.codice.ddf.cxf.client.ClientBuilderFactory)7 Test (org.junit.Test)5 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)3 URI (java.net.URI)3 SecureCxfClientFactory (org.codice.ddf.cxf.client.SecureCxfClientFactory)3 Before (org.junit.Before)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 QName (javax.xml.namespace.QName)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Metacard (ddf.catalog.data.Metacard)1 EventProcessor (ddf.catalog.event.EventProcessor)1