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.getDeclaredMethod("getPasswordAuthentication");
m.setAccessible(true);
auth = (PasswordAuthentication)m.invoke(wrapped);
} catch (Throwable t) {
//ignore
}
}
if (auth != null) {
return auth;
}
Message m = PhaseInterceptorChain.getCurrentMessage();
if (m != null) {
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());
}
}
}
}
// else PhaseInterceptorChain.getCurrentMessage() is null,