stsProperties.setCallbackHandler(new PasswordCallbackHandler());
stsProperties.setIssuer("STS");
issueOperation.setStsProperties(stsProperties);
// Mock up a request
RequestSecurityTokenType request = new RequestSecurityTokenType();
JAXBElement<String> tokenType =
new JAXBElement<String>(
QNameConstants.TOKEN_TYPE, String.class, WSConstants.WSS_SAML2_TOKEN_TYPE
);
request.getAny().add(tokenType);
JAXBElement<String> keyType =
new JAXBElement<String>(
QNameConstants.KEY_TYPE, String.class, STSConstants.SYMMETRIC_KEY_KEYTYPE
);
request.getAny().add(keyType);
JAXBElement<String> computedKey =
new JAXBElement<String>(
QNameConstants.COMPUTED_KEY_ALGORITHM, String.class, STSConstants.COMPUTED_KEY_PSHA1
);
request.getAny().add(computedKey);
request.getAny().add(createAppliesToElement("http://dummy-service.com/dummy"));
// 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);
// Now add Entropy
BinarySecretType binarySecretType = new BinarySecretType();
binarySecretType.setType(STSConstants.NONCE_TYPE);
binarySecretType.setValue(WSSecurityUtil.generateNonce(256 / 8));
JAXBElement<BinarySecretType> binarySecretTypeJaxb =
new JAXBElement<BinarySecretType>(
QNameConstants.BINARY_SECRET, BinarySecretType.class, binarySecretType
);
EntropyType entropyType = new EntropyType();
entropyType.getAny().add(binarySecretTypeJaxb);
JAXBElement<EntropyType> entropyJaxbType =
new JAXBElement<EntropyType>(QNameConstants.ENTROPY, EntropyType.class, entropyType);
request.getAny().add(entropyJaxbType);
RequestSecurityTokenResponseCollectionType response =
issueOperation.issue(request, webServiceContext);
List<RequestSecurityTokenResponseType> securityTokenResponse =
response.getRequestSecurityTokenResponse();