Search in sources :

Example 11 with ClientBuilderImpl

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

the class OcspCheckerTest method setup.

@Before
public void setup() throws Exception {
    MockitoAnnotations.initMocks(this);
    when(goodWebClient.type(anyString())).thenReturn(goodWebClient);
    when(goodWebClient.accept(anyString())).thenReturn(goodWebClient);
    when(goodWebClient.post(any())).thenReturn(goodResponse);
    when(revokedWebClient.type(anyString())).thenReturn(revokedWebClient);
    when(revokedWebClient.accept(anyString())).thenReturn(revokedWebClient);
    when(revokedWebClient.post(any())).thenReturn(revokedResponse);
    when(unknownWebClient.type(anyString())).thenReturn(unknownWebClient);
    when(unknownWebClient.accept(anyString())).thenReturn(unknownWebClient);
    when(unknownWebClient.post(any())).thenReturn(unknownResponse);
    when(brokenWebClient.type(anyString())).thenReturn(brokenWebClient);
    when(brokenWebClient.accept(anyString())).thenReturn(brokenWebClient);
    when(brokenWebClient.post(any())).thenReturn(brokenResponse);
    when(goodSecureCxfClientFactory.getWebClient()).thenReturn(goodWebClient);
    when(revokedSecureCxfClientFactory.getWebClient()).thenReturn(revokedWebClient);
    when(unknownSecureCxfClientFactory.getWebClient()).thenReturn(unknownWebClient);
    when(brokenSecureCxfClientFactory.getWebClient()).thenReturn(brokenWebClient);
    when(goodResponse.getEntity()).then(getResourceStreamAsAnswer("goodOcspResponse.streamData"));
    when(revokedResponse.getEntity()).then(getResourceStreamAsAnswer("revokedOcspResponse.streamData"));
    when(unknownResponse.getEntity()).then(getResourceStreamAsAnswer("unknownOcspResponse.streamData"));
    when(brokenResponse.getEntity()).thenReturn(null);
    ClientBuilder<WebClient> clientBuilder = new ClientBuilderImpl<WebClient>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<WebClient> build() {
            try {
                if (inGoodList.matches(new URI(endpointUrl))) {
                    return goodSecureCxfClientFactory;
                }
                if (inRevokedList.matches(new URI(endpointUrl))) {
                    return revokedSecureCxfClientFactory;
                }
                if (inUnknownList.matches(new URI(endpointUrl))) {
                    return unknownSecureCxfClientFactory;
                }
                if (inBrokenList.matches(new URI(endpointUrl))) {
                    return brokenSecureCxfClientFactory;
                }
                return null;
            } catch (URISyntaxException e) {
                return null;
            }
        }
    };
    when(factory.<WebClient>getClientBuilder()).thenReturn(clientBuilder);
}
Also used : ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) URISyntaxException(java.net.URISyntaxException) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) SecurityLogger(ddf.security.audit.SecurityLogger) Before(org.junit.Before)

Example 12 with ClientBuilderImpl

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

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