in modules/rampart-core/src/main/java/org/apache/rampart/util/RampartUtil.java [790:879]
public static String getToken(RampartMessageData rmd, OMElement rstTemplate,
String issuerEpr, String action, Policy issuerPolicy) throws RampartException {
try {
//First check whether the user has provided the token
MessageContext msgContext = rmd.getMsgContext();
String customTokeId = (String) msgContext
.getProperty(RampartMessageData.KEY_CUSTOM_ISSUED_TOKEN);
if(customTokeId != null) {
return customTokeId;
} else {
Axis2Util.useDOOM(false);
STSClient client = new STSClient(rmd.getMsgContext()
.getConfigurationContext());
// Set request action
client.setAction(action);
client.setVersion(rmd.getWstVersion());
client.setRstTemplate(rstTemplate);
// Set crypto information
Crypto crypto = RampartUtil.getSignatureCrypto(rmd.getPolicyData().getRampartConfig(),
rmd.getMsgContext().getAxisService().getClassLoader());
CallbackHandler cbh = RampartUtil.getPasswordCB(rmd);
client.setCryptoInfo(crypto, cbh);
// Get service policy
Policy servicePolicy = rmd.getServicePolicy();
// Get service epr
String servceEprAddress = rmd.getMsgContext()
.getOptions().getTo().getAddress();
//If addressing version can be found set it
Object addrVersionNs = msgContext.getProperty(AddressingConstants.WS_ADDRESSING_VERSION);
if(addrVersionNs != null) {
client.setAddressingNs((String)addrVersionNs);
}
Options options = new Options();
options.setUserName(rmd.getMsgContext().getOptions().getUserName());
options.setPassword(rmd.getMsgContext().getOptions().getPassword());
/* The commons httpclient 3.x code isn't compatible with 4.x
and there doesn't seem to be test coverage for it.
Leaving it commented out for now. The Protocol
class works differently now.
if (msgContext.getProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER) != null) {
Protocol protocolHandler =
(Protocol)msgContext.getProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER);;
options.setProperty(HTTPConstants.CUSTOM_PROTOCOL_HANDLER, protocolHandler);
}
*/
if (msgContext.getParameter(WSHandlerConstants.PW_CALLBACK_REF) != null ) {
Parameter pwCallback = msgContext.getParameter(WSHandlerConstants.PW_CALLBACK_REF);
client.addParameter(pwCallback);
}
client.setOptions(options);
//Set soap version
if (msgContext.isSOAP11()) {
client.setSoapVersion(SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
} else {
client.setSoapVersion(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
}
//Make the request
org.apache.rahas.Token rst =
client.requestSecurityToken(servicePolicy,
issuerEpr,
issuerPolicy,
servceEprAddress);
//Add the token to token storage
rst.setState(Token.ISSUED);
rmd.getTokenStorage().add(rst);
Axis2Util.useDOOM(true);
return rst.getId();
}
} catch (Exception e) {
throw new RampartException("errorInObtainingToken", e);
}
}