stsProperties.setRealmParser(new CustomRealmParser());
issueOperation.setStsProperties(stsProperties);
// Set signature properties in SAMLRealm B
Map<String, SAMLRealm> samlRealms = provider.getRealmMap();
SAMLRealm realm = samlRealms.get("B");
realm.setSignatureCrypto(crypto);
realm.setCallbackHandler(new PasswordCallbackHandler());
// Mock up a request
RequestSecurityTokenType request = new RequestSecurityTokenType();
JAXBElement<String> tokenType =
new JAXBElement<String>(
QNameConstants.TOKEN_TYPE, String.class, WSConstants.WSS_SAML_TOKEN_TYPE
);
request.getAny().add(tokenType);
request.getAny().add(createAppliesToElement("http://dummy-service.com/dummy"));
// Mock up message context
MessageImpl msg = new MessageImpl();
WrappedMessageContext msgCtx = new WrappedMessageContext(msg);
msgCtx.put("url", "https");
msgCtx.put(
SecurityContext.class.getName(),
createSecurityContext(new CustomTokenPrincipal("alice"))
);
WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgCtx);
// Issue a token - this will fail as the SAMLRealm configuration is inconsistent
// no signature alias defined
try {
issueOperation.issue(request, webServiceContext);
fail("Failure expected on no encryption name");
} catch (STSException ex) {
// expected
}
realm.setSignatureAlias("mystskey");
// Issue a token
RequestSecurityTokenResponseCollectionType response =
issueOperation.issue(request, webServiceContext);
List<RequestSecurityTokenResponseType> securityTokenResponse =