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);
}
}
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));
}
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));
}
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);
}
}
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);
}
Aggregations