in modules/rampart-trust/src/main/java/org/apache/rahas/impl/TokenCancelerImpl.java [53:153]
public SOAPEnvelope cancel(RahasData data) throws TrustException {
TokenCancelerConfig config = null;
if (this.configElement != null) {
config = TokenCancelerConfig.load(configElement.
getFirstChildWithName(SCTIssuerConfig.SCT_ISSUER_CONFIG));
}
// Look for the file
if (config == null && this.configFile != null) {
config = TokenCancelerConfig.load(this.configFile);
}
// Look for the param
if (config == null && this.configParamName != null) {
Parameter param = data.getInMessageContext().getParameter(this.configParamName);
if (param != null && param.getParameterElement() != null) {
config = TokenCancelerConfig.load(param.getParameterElement()
.getFirstChildWithName(SCTIssuerConfig.SCT_ISSUER_CONFIG));
} else {
throw new TrustException("expectedParameterMissing",
new String[]{this.configParamName});
}
}
if (config == null) {
throw new TrustException("missingConfiguration",
new String[]{SCTIssuerConfig.SCT_ISSUER_CONFIG
.getLocalPart()});
}
OMElement rstEle = data.getRstElement();
QName cancelTagetQName = new QName(data.getWstNs(), RahasConstants.CancelBindingLocalNames.CANCEL_TARGET);
OMElement cancelTargetEle = rstEle.getFirstChildWithName(cancelTagetQName);
if (cancelTargetEle == null) {
throw new TrustException("requiredElementNotFound",
new String[]{cancelTagetQName.toString()});
}
OMElement secTokenRefEle = cancelTargetEle
.getFirstChildWithName(new QName(WSConstants.WSSE_NS,
SecurityTokenReference.SECURITY_TOKEN_REFERENCE));
String tokenId;
if (secTokenRefEle != null) {
/*
<o:SecurityTokenReference
xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
<o:Reference URI="urn:uuid:8e6a3a95-fd1b-4c24-96d4-28e875025ff7"
ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" />
</o:SecurityTokenReference>
*/
OMElement referenceEle = secTokenRefEle.getFirstChildWithName(Reference.TOKEN);
if (referenceEle != null) {
OMAttribute uri = referenceEle.getAttribute(new QName(
RahasConstants.CancelBindingLocalNames.URI));
if (uri != null) {
tokenId = uri.getAttributeValue();
if (tokenId.charAt(0) == '#') {
tokenId = tokenId.substring(1);
}
} else {
throw new TrustException("cannotDetermineTokenId");
}
} else {
throw new TrustException("cannotDetermineTokenId");
}
} else {
// TODO: we need to handle situation where the token itself is contained within the
// TODO: <wst:CancelTarget> element
throw new TrustException("cannotDetermineTokenId");
}
// Cancel the token
MessageContext inMsgCtx = data.getInMessageContext();
TokenStorage tokenStore = TrustUtil.getTokenStore(inMsgCtx);
Token token = tokenStore.getToken(tokenId);
if (token == null) {
throw new TrustException("tokenNotFound", new String[]{tokenId});
}
token.setState(Token.CANCELLED);
tokenStore.update(token);
// Create the response SOAP Envelope
SOAPEnvelope responseEnv =
TrustUtil.
createSOAPEnvelope(inMsgCtx.getEnvelope().getNamespace().getNamespaceURI());
OMElement rstrElem;
int version = data.getVersion();
if (RahasConstants.VERSION_05_02 == version) {
rstrElem = TrustUtil
.createRequestSecurityTokenResponseElement(version, responseEnv.getBody());
} else {
OMElement rstrcElem = TrustUtil
.createRequestSecurityTokenResponseCollectionElement(
version, responseEnv.getBody());
rstrElem = TrustUtil.createRequestSecurityTokenResponseElement(version, rstrcElem);
}
TrustUtil.createRequestedTokenCanceledElement(version, rstrElem);
return responseEnv;
}