log.debug("User : " + user);
}
// If NoPassword property is set we don't need to set the password
if (token.isNoPassword()) {
WSSecUsernameToken utBuilder = new WSSecUsernameToken();
utBuilder.setUserInfo(user, null);
utBuilder.setPasswordType(null);
if (rmd.getConfig() != null) {
utBuilder.setWsConfig(rmd.getConfig());
}
return utBuilder;
}
//Get the password
//First check options object for a password
String password = options.getPassword();
if(password == null || password.length() == 0) {
//Then try to get the password from the given callback handler
CallbackHandler handler = RampartUtil.getPasswordCB(rmd);
if(handler == null) {
//If the callback handler is missing
throw new RampartException("cbHandlerMissing");
}
WSPasswordCallback[] cb = { new WSPasswordCallback(user,
WSPasswordCallback.USERNAME_TOKEN) };
try {
handler.handle(cb);
} catch (Exception e) {
throw new RampartException("errorInGettingPasswordForUser",
new String[]{user}, e);
}
//get the password
password = cb[0].getPassword();
}
if (log.isDebugEnabled()) {
log.debug("Password : " + password);
}
if(password != null && !"".equals(password)) {
//If the password is available then build the token
WSSecUsernameToken utBuilder = new WSSecUsernameToken();
if(rmd.getConfig() != null) {
utBuilder.setWsConfig(rmd.getConfig());
}
if (token.isHashPassword()) {
utBuilder.setPasswordType(WSConstants.PASSWORD_DIGEST);
} else {
utBuilder.setPasswordType(WSConstants.PASSWORD_TEXT);
}
utBuilder.setUserInfo(user, password);
return utBuilder;
} else {
//If there's no password then throw an exception
throw new RampartException("noPasswordForUser",