Search in sources :

Example 11 with ClientBuilderFactory

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

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

the class CrlGeneratorTest method testHttpUrl.

@Test
public void testHttpUrl() {
    ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
    CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin);
    crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
    crlGenerator.setCrlLocationUrl("http://testurl:8993");
    crlGenerator.setCrlByUrlEnabled(true);
    crlGenerator.run();
    assertTrue(!PropertiesLoader.getInstance().loadProperties(CrlGenerator.issuerEncryptionPropertiesLocation).containsKey(CrlGenerator.CRL_PROPERTY_KEY));
    assertTrue(!PropertiesLoader.getInstance().loadProperties(CrlGenerator.issuerSignaturePropertiesLocation).containsKey(CrlGenerator.CRL_PROPERTY_KEY));
    assertTrue(!PropertiesLoader.getInstance().loadProperties(CrlGenerator.serverEncryptionPropertiesLocation).containsKey(CrlGenerator.CRL_PROPERTY_KEY));
    assertTrue(!PropertiesLoader.getInstance().loadProperties(CrlGenerator.serverSignaturePropertiesLocation).containsKey(CrlGenerator.CRL_PROPERTY_KEY));
}
Also used : ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

Example 13 with ClientBuilderFactory

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

the class CrlGeneratorTest method getCxfClient.

private ClientBuilderFactory getCxfClient(byte[] message) {
    Response response = mock(Response.class);
    when(response.getEntity()).thenReturn(new ByteArrayInputStream(message));
    WebClient webClient = mock(WebClient.class);
    when(webClient.get()).thenReturn(response);
    SecureCxfClientFactory<WebClient> secureCxfClientFactory = mock(SecureCxfClientFactory.class);
    when(secureCxfClientFactory.getWebClient()).thenReturn(webClient);
    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 secureCxfClientFactory;
        }
    };
    when(clientBuilderFactory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
    return clientBuilderFactory;
}
Also used : Response(javax.ws.rs.core.Response) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) ByteArrayInputStream(java.io.ByteArrayInputStream) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) WebClient(org.apache.cxf.jaxrs.client.WebClient) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 14 with ClientBuilderFactory

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

the class CrlGeneratorTest method testSetCrlLocationUrl.

@Test
public void testSetCrlLocationUrl() {
    ClientBuilderFactory clientBuilderFactory = getCxfClient(demEncodedCrl);
    ScheduledExecutorService scheduler = mock(ScheduledExecutorService.class);
    CrlGenerator crlGenerator = new CrlGenerator(clientBuilderFactory, eventAdmin, scheduler);
    crlGenerator.setSecurityLogger(mock(SecurityLogger.class));
    crlGenerator.setCrlByUrlEnabled(true);
    when(scheduler.scheduleAtFixedRate(crlGenerator, 0, 30, TimeUnit.MINUTES)).thenReturn(null);
    crlGenerator.setCrlLocationUrl("https://testurl:8993");
    Mockito.verify(scheduler, times(1)).scheduleAtFixedRate(crlGenerator, 0, 30, TimeUnit.MINUTES);
    // Will set handler value (not null)
    ScheduledFuture handler = mock(ScheduledFuture.class);
    when(scheduler.scheduleAtFixedRate(crlGenerator, 0, 30, TimeUnit.MINUTES)).thenReturn(handler);
    crlGenerator.setCrlLocationUrl("https://testurl:8993");
    // Next time we call setCrlLocationUrl, the first handler should be chanced
    crlGenerator.setCrlLocationUrl("https://testurl:8993");
    Mockito.verify(handler, times(1)).cancel(false);
}
Also used : ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) SecurityLogger(ddf.security.audit.SecurityLogger) Test(org.junit.Test)

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