QNameConstants.TOKEN_TYPE, String.class, STSConstants.STATUS
);
request.getAny().add(tokenType);
// Get a SecurityContextToken via the SCTProvider
TokenProviderResponse providerResponse = createSCT();
Element sct = providerResponse.getToken();
Document doc = sct.getOwnerDocument();
sct = (Element)doc.appendChild(sct);
ValidateTargetType validateTarget = new ValidateTargetType();
validateTarget.setAny(sct);
JAXBElement<ValidateTargetType> validateTargetType =
new JAXBElement<ValidateTargetType>(
QNameConstants.VALIDATE_TARGET, ValidateTargetType.class, validateTarget
);
request.getAny().add(validateTargetType);
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
msgCtx.put(
SecurityContext.class.getName(),
createSecurityContext(new CustomTokenPrincipal("alice"))
);
WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgCtx);
// Validate a token
RequestSecurityTokenResponseType response =
validateOperation.validate(request, webServiceContext);
assertTrue(validateResponse(response));
// Now remove the token from the cache before validating again
tokenStore.remove(tokenStore.getToken(providerResponse.getTokenId()));
assertNull(tokenStore.getToken(providerResponse.getTokenId()));
response = validateOperation.validate(request, webServiceContext);
assertFalse(validateResponse(response));
}