Search in sources :

Example 6 with ClientBuilderFactory

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));
}
Also used : ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 7 with ClientBuilderFactory

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;
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Security(org.codice.ddf.security.impl.Security) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) Subject(org.apache.shiro.subject.Subject) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 8 with ClientBuilderFactory

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();
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) Serializable(java.io.Serializable) SecurityManager(ddf.security.service.SecurityManager) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 9 with ClientBuilderFactory

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();
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) Serializable(java.io.Serializable) SecurityManager(ddf.security.service.SecurityManager) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 10 with ClientBuilderFactory

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);
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) SecureCxfClientFactory(org.codice.ddf.cxf.client.SecureCxfClientFactory) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) ArrayList(java.util.ArrayList) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) AttributeDescriptorImpl(ddf.catalog.data.impl.AttributeDescriptorImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SearchResource(org.codice.ddf.confluence.api.SearchResource) MetacardType(ddf.catalog.data.MetacardType) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) AttributeRegistry(ddf.catalog.data.AttributeRegistry) EncryptionService(ddf.security.encryption.EncryptionService) PermissionsImpl(ddf.security.permission.impl.PermissionsImpl) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

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