Search in sources :

Example 1 with ProxyAuthorizationPolicy

use of org.apache.cxf.configuration.security.ProxyAuthorizationPolicy in project camel by apache.

the class ServiceNowClient method configureProxyAuthorizationPolicy.

private static void configureProxyAuthorizationPolicy(CamelContext context, ServiceNowConfiguration configuration, WebClient client) throws Exception {
    ProxyAuthorizationPolicy proxyPolicy = configuration.getProxyAuthorizationPolicy();
    if (proxyPolicy == null) {
        String username = configuration.getProxyUserName();
        String password = configuration.getProxyPassword();
        if (username != null && password != null) {
            proxyPolicy = new ProxyAuthorizationPolicy();
            proxyPolicy.setAuthorizationType("Basic");
            proxyPolicy.setUserName(username);
            proxyPolicy.setPassword(password);
        }
    }
    if (proxyPolicy != null) {
        WebClient.getConfig(client).getHttpConduit().setProxyAuthorization(proxyPolicy);
    }
}
Also used : ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)

Example 2 with ProxyAuthorizationPolicy

use of org.apache.cxf.configuration.security.ProxyAuthorizationPolicy in project jbossws-cxf by jbossws.

the class HTTPProxyTestCaseForked method testHttpProxy.

@Test
@RunAsClient
public void testHttpProxy() throws Exception {
    if (checkNativeLibraries()) {
        initProxyServer();
    } else {
        return;
    }
    final String testHost = "unreachable-testHttpProxy";
    HelloWorld port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    final String hi = "Hi!";
    // first try without setting up the proxy -> request fails because the host is not known/reachable
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains(testHost));
    }
    // then setup the proxy, but provide no authentication/authorization info -> request fails because of HTTP 407
    setProxySystemProperties();
    port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains("407: Proxy Authentication Required"));
    }
    // finally setup everything
    port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    ProxyAuthorizationPolicy policy = new ProxyAuthorizationPolicy();
    policy.setAuthorizationType("Basic");
    policy.setUserName(PROXY_USER);
    policy.setPassword(PROXY_PWD);
    conduit.setProxyAuthorization(policy);
    assertEquals(hi, port.echo(hi));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PrintStream(java.io.PrintStream) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 3 with ProxyAuthorizationPolicy

use of org.apache.cxf.configuration.security.ProxyAuthorizationPolicy in project jbossws-cxf by jbossws.

the class HTTPProxyTestCaseForked method testHttpProxyUsingHTTPClientPolicy.

@Test
@RunAsClient
public void testHttpProxyUsingHTTPClientPolicy() throws Exception {
    if (checkNativeLibraries()) {
        initProxyServer();
    } else {
        return;
    }
    final String testHost = "unreachable-testHttpProxyUsingHTTPClientPolicy";
    HelloWorld port = getPort(getResourceURL("jaxws/cxf/httpproxy/HelloWorldService.wsdl"), testHost);
    final String hi = "Hi!";
    // first try without setting up the proxy -> request fails because the host is not known/reachable
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains(testHost));
    }
    // then setup the proxy, but provide no authentication/authorization info -> request fails because of HTTP 407
    Client client = ClientProxy.getClient(port);
    HTTPConduit conduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy clientPolicy = conduit.getClient();
    clientPolicy.setProxyServerType(ProxyServerType.HTTP);
    clientPolicy.setProxyServer(getServerHost());
    clientPolicy.setProxyServerPort(proxyPort);
    try {
        port.echo(hi);
        fail("Exception expected");
    } catch (Exception e) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        e.printStackTrace(new PrintStream(baos));
        assertTrue(baos.toString().contains("407: Proxy Authentication Required"));
    }
    // finally setup authorization info too
    ProxyAuthorizationPolicy authPolicy = new ProxyAuthorizationPolicy();
    authPolicy.setAuthorizationType("Basic");
    authPolicy.setUserName(PROXY_USER);
    authPolicy.setPassword(PROXY_PWD);
    conduit.setProxyAuthorization(authPolicy);
    assertEquals(hi, port.echo(hi));
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) PrintStream(java.io.PrintStream) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Client(org.apache.cxf.endpoint.Client) MalformedURLException(java.net.MalformedURLException) RunAsClient(org.jboss.arquillian.container.test.api.RunAsClient) Test(org.junit.Test) JBossWSTest(org.jboss.wsf.test.JBossWSTest)

Example 4 with ProxyAuthorizationPolicy

use of org.apache.cxf.configuration.security.ProxyAuthorizationPolicy in project tomee by apache.

the class HTTPConduit method setHeadersByAuthorizationPolicy.

/**
 * This call places HTTP Header strings into the headers that are relevant
 * to the Authorization policies that are set on this conduit by
 * configuration.
 * <p>
 * An AuthorizationPolicy may also be set on the message. If so, those
 * policies are merged. A user name or password set on the messsage
 * overrides settings in the AuthorizationPolicy is retrieved from the
 * configuration.
 * <p>
 * The precedence is as follows:
 * 1. AuthorizationPolicy that is set on the Message, if exists.
 * 2. Authorization from AuthSupplier, if exists.
 * 3. AuthorizationPolicy set/configured for conduit.
 *
 * REVISIT: Since the AuthorizationPolicy is set on the message by class, then
 * how does one override the ProxyAuthorizationPolicy which is the same
 * type?
 *
 * @param message
 * @param currentURI
 */
protected void setHeadersByAuthorizationPolicy(Message message, URI currentURI) {
    Headers headers = new Headers(message);
    AuthorizationPolicy effectiveAuthPolicy = getEffectiveAuthPolicy(message);
    String authString = authSupplier.getAuthorization(effectiveAuthPolicy, currentURI, message, null);
    if (authString != null) {
        headers.setAuthorization(authString);
    }
    String proxyAuthString = proxyAuthSupplier.getAuthorization(proxyAuthorizationPolicy, currentURI, message, null);
    if (proxyAuthString != null) {
        headers.setProxyAuthorization(proxyAuthString);
    }
}
Also used : ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) AuthorizationPolicy(org.apache.cxf.configuration.security.AuthorizationPolicy)

Example 5 with ProxyAuthorizationPolicy

use of org.apache.cxf.configuration.security.ProxyAuthorizationPolicy in project cxf by apache.

the class HTTPProxyAuthConduitTest method configureProxy.

public void configureProxy(Client client) {
    HTTPConduit cond = (HTTPConduit) client.getConduit();
    HTTPClientPolicy pol = cond.getClient();
    if (pol == null) {
        pol = new HTTPClientPolicy();
        cond.setClient(pol);
    }
    pol.setProxyServer("localhost");
    pol.setProxyServerPort(PROXY_PORT);
    ProxyAuthorizationPolicy auth = new ProxyAuthorizationPolicy();
    auth.setUserName("CXF");
    auth.setPassword("password");
    cond.setProxyAuthorization(auth);
}
Also used : HTTPConduit(org.apache.cxf.transport.http.HTTPConduit) ProxyAuthorizationPolicy(org.apache.cxf.configuration.security.ProxyAuthorizationPolicy) HTTPClientPolicy(org.apache.cxf.transports.http.configuration.HTTPClientPolicy)

Aggregations

ProxyAuthorizationPolicy (org.apache.cxf.configuration.security.ProxyAuthorizationPolicy)11 HTTPClientPolicy (org.apache.cxf.transports.http.configuration.HTTPClientPolicy)6 AuthorizationPolicy (org.apache.cxf.configuration.security.AuthorizationPolicy)5 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 PrintStream (java.io.PrintStream)2 MalformedURLException (java.net.MalformedURLException)2 URISyntaxException (java.net.URISyntaxException)2 Client (org.apache.cxf.endpoint.Client)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 CertConstraints (org.apache.cxf.transport.https.CertConstraints)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 JBossWSTest (org.jboss.wsf.test.JBossWSTest)2 Test (org.junit.Test)2 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)1 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)1 ClientConfiguration (org.apache.cxf.jaxrs.client.ClientConfiguration)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1