String password;
password = handler.getPassword(reqData.getUsername(), actionToDo,
WSHandlerConstants.PW_CALLBACK_CLASS,
WSHandlerConstants.PW_CALLBACK_REF, reqData).getPassword();
WSSecUsernameToken builder = new WSSecUsernameToken();
builder.setWsConfig(reqData.getWssConfig());
if (reqData.isUseDerivedKey()) {
int iterations = reqData.getDerivedKeyIterations();
boolean useMac = reqData.isUseDerivedKeyForMAC();
builder.addDerivedKey(useMac, null, iterations);
} else {
builder.setPasswordType(reqData.getPwType()); // enhancement by Alberto Coletti
builder.setSecretKeyLength(reqData.getSecretKeyLength());
}
builder.setUserInfo(reqData.getUsername(), password);
builder.addCreated();
builder.addNonce();
builder.prepare(doc);
// Now prepare to sign.
// First step: Get a WS Signature object and set config parameters
// second step: set user data and algorithm parameters. This
// _must_ be done before we "prepare"
// third step: Call "prepare". This creates the internal WS Signature
// data structures, XML element, fills in the algorithms
// and other data.
// fourth step: Get the references. These references identify the parts
// of the document that will be included into the
// signature. If no references are given sign the message
// body by default.
// fifth step: compute the signature
//
// after "prepare" the Signature XML element is ready and may prepend
// this to the security header.
WSSecSignature sign = new WSSecSignature();
sign.setWsConfig(reqData.getWssConfig());
sign.setUsernameToken(builder);
sign.setKeyIdentifierType(WSConstants.UT_SIGNING);
if (reqData.getSigAlgorithm() != null) {
sign.setSignatureAlgorithm(reqData.getSigAlgorithm());
} else {
sign.setSignatureAlgorithm(XMLSignature.ALGO_ID_MAC_HMAC_SHA1);
}
sign.prepare(doc, null, reqData.getSecHeader());
// prepend in this order: first the Signature Element and then the
// UsernameToken Element. This way the server gets the UsernameToken
// first, can check it and are prepared to compute the Signature key.
sign.prependToHeader(reqData.getSecHeader());
builder.prependToHeader(reqData.getSecHeader());
Vector parts = null;
if (reqData.getSignatureParts().size() > 0) {
parts = reqData.getSignatureParts();
}