in modules/rampart-core/src/main/java/org/apache/rampart/builder/BindingBuilder.java [243:335]
protected WSSecSignature getSignatureBuilder(RampartMessageData rmd, Token token,
String userCertAlias) throws RampartException {
RampartPolicyData rpd = rmd.getPolicyData();
WSSecSignature sig = new WSSecSignature(rmd.getSecHeader());
checkForX509PkiPath(sig, token);
if (log.isDebugEnabled()) {
log.debug("Token inclusion: " + token.getInclusion());
}
RampartUtil.setKeyIdentifierType(rmd, sig, token);
String user = null;
if (userCertAlias != null) {
user = userCertAlias;
}
// Get the user - First check whether userCertAlias present
RampartConfig rampartConfig = rpd.getRampartConfig();
if(rampartConfig == null) {
throw new RampartException("rampartConfigMissing");
}
if (user == null) {
user = rampartConfig.getUserCertAlias();
}
// If userCertAlias is not present, use user property as Alias
if (user == null) {
user = rampartConfig.getUser();
}
String password = null;
if(user != null && !"".equals(user)) {
if (log.isDebugEnabled()) {
log.debug("User : " + user);
}
//Get the password
CallbackHandler handler = RampartUtil.getPasswordCB(rmd);
if(handler == null) {
//If the callback handler is missing
throw new RampartException("cbHandlerMissing");
}
WSPasswordCallback[] cb = { new WSPasswordCallback(user,
WSPasswordCallback.SIGNATURE) };
try {
handler.handle(cb);
if(cb[0].getPassword() != null && !"".equals(cb[0].getPassword())) {
password = cb[0].getPassword();
if (log.isDebugEnabled()) {
log.debug("Password : " + password);
}
} else {
//If there's no password then throw an exception
throw new RampartException("noPasswordForUser",
new String[]{user});
}
} catch (IOException e) {
throw new RampartException("errorInGettingPasswordForUser",
new String[]{user}, e);
} catch (UnsupportedCallbackException e) {
throw new RampartException("errorInGettingPasswordForUser",
new String[]{user}, e);
}
} else {
log.debug("No user value specified in the configuration");
throw new RampartException("userMissing");
}
sig.setUserInfo(user, password);
AlgorithmSuite algorithmSuite = rpd.getAlgorithmSuite();
sig.setSignatureAlgorithm(algorithmSuite.getAsymmetricSignature());
sig.setSigCanonicalization(algorithmSuite.getInclusiveC14n());
sig.setDigestAlgo(algorithmSuite.getDigest());
try {
sig.prepare(RampartUtil.getSignatureCrypto(rampartConfig, rmd.getCustomClassLoader()));
} catch (WSSecurityException e) {
throw new RampartException("errorInSignatureWithX509Token", e);
}
return sig;
}