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