private void setHeadersByAuthorizationPolicy(
Message message,
URL url,
Map<String, List<String>> headers
) {
AuthorizationPolicy authPolicy = getAuthorization();
HttpBasicAuthSupplier.UserPass userpass = null;
if (basicAuthSupplier != null) {
userpass = basicAuthSupplier.getPreemptiveUserPass(
getConduitName(), url, message);
}
AuthorizationPolicy newPolicy = message.get(AuthorizationPolicy.class);
String userName = null;
String passwd = null;
if (null != newPolicy) {
userName = newPolicy.getUserName();
passwd = newPolicy.getPassword();
}
if (userName == null
&& userpass != null) {
userName = userpass.getUserid();
passwd = userpass.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));
}
}
}