setup = true;
}
}
protected PasswordAuthentication getPasswordAuthentication() {
PasswordAuthentication auth = null;
if (wrapped != null) {
try {
for (Field f : Authenticator.class.getDeclaredFields()) {
if (!Modifier.isStatic(f.getModifiers())) {
f.setAccessible(true);
f.set(wrapped, f.get(this));
}
}
Method m = Authenticator.class.getMethod("getPasswordAuthentication");
m.setAccessible(true);
auth = (PasswordAuthentication)m.invoke(wrapped);
} catch (Throwable t) {
//ignore
}
}
if (auth == null) {
Message m = PhaseInterceptorChain.getCurrentMessage();
Exchange exchange = m.getExchange();
Conduit conduit = exchange.getConduit(m);
if (conduit instanceof HTTPConduit) {
HTTPConduit httpConduit = (HTTPConduit)conduit;
if (getRequestorType() == RequestorType.PROXY
&& httpConduit.getProxyAuthorization() != null) {
String un = httpConduit.getProxyAuthorization().getUserName();
String pwd = httpConduit.getProxyAuthorization().getPassword();
if (un != null && pwd != null) {
auth = new PasswordAuthentication(un, pwd.toCharArray());
}
} else if (getRequestorType() == RequestorType.SERVER
&& httpConduit.getAuthorization() != null) {
String un = httpConduit.getAuthorization().getUserName();
String pwd = httpConduit.getAuthorization().getPassword();
if (un != null && pwd != null) {
auth = new PasswordAuthentication(un, pwd.toCharArray());
}
}
}
}
return auth;