private void setHeadersByAuthorizationPolicy(
Message message,
URL url,
Map<String, List<String>> headers
) {
AuthorizationPolicy authPolicy = getAuthorization();
AuthorizationPolicy newPolicy = message.get(AuthorizationPolicy.class);
String authString = null;
if (authSupplier != null
&& (newPolicy == null
|| (!"Basic".equals(newPolicy.getAuthorizationType())
&& newPolicy.getAuthorization() == null))) {
authString = (String)message.get("AUTH_VALUE");
if (authString == null) {
authString = authSupplier.getPreemptiveAuthorization(
this, url, message);
} else {
message.remove("AUTH_VALUE");
}
if (authString != null) {
headers.put("Authorization",
createMutableList(authString));
}
return;
}
String userName = null;
String passwd = null;
if (null != newPolicy) {
userName = newPolicy.getUserName();
passwd = newPolicy.getPassword();
}
if (userName == null
&& authPolicy != null && authPolicy.isSetUserName()) {
userName = authPolicy.getUserName();
}
if (userName != null) {
if (passwd == null
&& authPolicy != null && authPolicy.isSetPassword()) {
passwd = authPolicy.getPassword();
}
setBasicAuthHeader(userName, passwd, headers);
} else if (authPolicy != null
&& authPolicy.isSetAuthorizationType()
&& authPolicy.isSetAuthorization()) {
String type = authPolicy.getAuthorizationType();
type += " ";
type += authPolicy.getAuthorization();
headers.put("Authorization",
createMutableList(type));
}
AuthorizationPolicy proxyAuthPolicy = getProxyAuthorization();
if (proxyAuthPolicy != null && proxyAuthPolicy.isSetUserName()) {
userName = proxyAuthPolicy.getUserName();
if (userName != null) {
passwd = "";
if (proxyAuthPolicy.isSetPassword()) {
passwd = proxyAuthPolicy.getPassword();
}
setProxyBasicAuthHeader(userName, passwd, headers);
} else if (proxyAuthPolicy.isSetAuthorizationType()
&& proxyAuthPolicy.isSetAuthorization()) {
String type = proxyAuthPolicy.getAuthorizationType();
type += " ";
type += proxyAuthPolicy.getAuthorization();
headers.put("Proxy-Authorization",
createMutableList(type));
}
}
}