List<TokenProvider> providerList = new ArrayList<TokenProvider>();
providerList.add(new DummyTokenProvider());
issueOperation.setTokenProviders(providerList);
// Add Service
ServiceMBean service = new StaticService();
service.setEndpoints(Collections.singletonList("http://dummy-service.com/dummy"));
issueOperation.setServices(Collections.singletonList(service));
// Add STSProperties object
STSPropertiesMBean stsProperties = new StaticSTSProperties();
issueOperation.setStsProperties(stsProperties);
// Mock up a request
RequestSecurityTokenType request = new RequestSecurityTokenType();
JAXBElement<String> tokenType =
new JAXBElement<String>(
QNameConstants.TOKEN_TYPE, String.class, "UnknownTokenType"
);
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);
WebServiceContextImpl webServiceContext = new WebServiceContextImpl(msgCtx);
// Issue a token - failure expected on an unknown token type
try {
issueOperation.issue(request, webServiceContext);
fail("Failure expected on an unknown token type");
} catch (STSException ex) {
// expected
}
// Issue a token - failure expected as no token type is sent
request.getAny().remove(0);
try {
issueOperation.issue(request, webServiceContext);
fail("Failure expected on no token type");
} catch (STSException ex) {
// expected
}
// Issue a token - this time it defaults to a known token type
service.setTokenType(DummyTokenProvider.TOKEN_TYPE);
issueOperation.setServices(Collections.singletonList(service));
RequestSecurityTokenResponseCollectionType response =
issueOperation.issue(request, webServiceContext);
List<RequestSecurityTokenResponseType> securityTokenResponse =