use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class CrlGeneratorTest method testGettingPemCrlFromUrl.
@Test
public void testGettingPemCrlFromUrl() throws Exception {
ClientBuilderFactory clientBuilderFactory = getCxfClient(getCRL());
CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin);
crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
crlGenerator.setCrlLocationUrl("https://testurl:8993");
crlGenerator.setCrlByUrlEnabled(true);
crlGenerator.run();
byte[] encoded = Files.readAllBytes(Paths.get(CrlGenerator.crlFileLocation + CrlGenerator.PEM_CRL));
assertTrue(Arrays.equals(getCRL(), encoded));
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class CswSourceTest method getCswSource.
private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService, Permissions permissions) {
CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService, permissions);
cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
SecureCxfClientFactory<Csw> mockFactory = mock(SecureCxfClientFactory.class);
doReturn(csw).when(mockFactory).getClient();
doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
doReturn(csw).when(mockFactory).getClientForSystemSubject(any(Subject.class));
ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
ClientBuilder<Csw> clientBuilder = new ClientBuilderImpl<Csw>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {
@Override
public SecureCxfClientFactory<Csw> build() {
return mockFactory;
}
};
when(clientBuilderFactory.<Csw>getClientBuilder()).thenReturn(clientBuilder);
CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, clientBuilderFactory, encryptionService, new Security(), permissions);
cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
cswSource.setFilterBuilder(builder);
cswSource.setContext(context);
cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
cswSource.setAvailabilityTask(mockAvailabilityTask);
cswSource.configureCswSource();
return cswSource;
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class URLResourceReaderTest method testGetWebClientWithOauth.
@Test
public void testGetWebClientWithOauth() throws URISyntaxException {
SecureCxfClientFactory<WebClient> cxfClientFactory = mock(SecureCxfClientFactory.class);
when(cxfClientFactory.getWebClient()).thenReturn(mock(WebClient.class));
ClientBuilderFactory 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 cxfClientFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
URLResourceReader urlResourceReader = new URLResourceReader(mimeTypeMapper, clientBuilderFactory);
Map<String, Serializable> properties = ImmutableMap.of("id", "mysource", "oauthDiscoveryUrl", "https://keycloak:8080/discovery-url", "oauthClientId", "client-id", "oauthClientSecret", "client-secret", "oauthFlow", "code");
urlResourceReader.getWebClient(new URI("https://myurl.com"), properties);
verify(clientBuilderFactory, times(1)).getClientBuilder();
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class URLResourceReaderTest method testGetWebClientWithUsernameAndPassword.
@Test
public void testGetWebClientWithUsernameAndPassword() throws URISyntaxException {
SecureCxfClientFactory<WebClient> cxfClientFactory = mock(SecureCxfClientFactory.class);
when(cxfClientFactory.getWebClient()).thenReturn(mock(WebClient.class));
ClientBuilderFactory 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 cxfClientFactory;
}
};
when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
URLResourceReader urlResourceReader = new URLResourceReader(mimeTypeMapper, clientBuilderFactory);
Map<String, Serializable> properties = ImmutableMap.of("username", "myusername", "password", "mypassword");
urlResourceReader.getWebClient(new URI("https://myurl.com"), properties);
verify(clientBuilderFactory, times(1)).getClientBuilder();
}
use of org.codice.ddf.cxf.client.ClientBuilderFactory in project ddf by codice.
the class ConfluenceSourceTest method setup.
@Before
public void setup() {
MetacardType type = new MetacardTypeImpl("confluence", MetacardImpl.BASIC_METACARD.getAttributeDescriptors());
transformer = new ConfluenceInputTransformer(type, Collections.emptyList());
encryptionService = mock(EncryptionService.class);
reader = mock(ResourceReader.class);
factory = mock(SecureCxfClientFactory.class);
clientBuilderFactory = mock(ClientBuilderFactory.class);
client = mock(SearchResource.class);
registry = mock(AttributeRegistry.class);
clientResponse = mock(Response.class);
when(factory.getClient()).thenReturn(client);
doReturn(clientResponse).when(client).search(anyString(), isNull(), isNull(), anyString(), anyInt(), anyInt(), anyBoolean());
when(encryptionService.decryptValue(anyString())).thenReturn("decryptedPass");
when(registry.lookup("attrib1")).thenReturn(Optional.of(new AttributeDescriptorImpl("attrib1", true, true, true, false, BasicTypes.STRING_TYPE)));
when(registry.lookup("attrib2")).thenReturn(Optional.of(new AttributeDescriptorImpl("attrib2", true, true, true, true, BasicTypes.STRING_TYPE)));
confluence = new TestConfluenceSource(adapter, encryptionService, transformer, reader, registry, factory, clientBuilderFactory);
confluence.setSecurityLogger(mock(SecurityLogger.class));
confluence.setPermissions(new PermissionsImpl());
confluence.setAvailabilityPollInterval(1);
confluence.setConfigurationPid("configPid");
confluence.setEndpointUrl("https://confluence/rest/api/content");
confluence.setExpandedSections(Collections.singletonList("expandedField"));
confluence.setUsername("username");
confluence.setPassword("password");
confluence.setIncludeArchivedSpaces(false);
List<String> additionalAttributes = new ArrayList<>();
additionalAttributes.add("attrib1=val1");
additionalAttributes.add("attrib2=val1,val2,val3");
confluence.setAttributeOverrides(additionalAttributes);
}
Aggregations