* @throws Exception if an error occurs while running the test.
*/
@Test
public void testSTSConfiguration() throws Exception {
// make the STS read the configuration file.
STSConfiguration config = this.tokenService.getConfiguration();
// check the values that have been configured.
assertEquals("Unexpected service name", "Test STS", config.getSTSName());
assertEquals("Unexpected token timeout value", 7200 * 1000, config.getIssuedTokenTimeout());
assertFalse("Encrypt token should be true", config.encryptIssuedToken());
WSTrustRequestHandler handler = config.getRequestHandler();
assertNotNull("Unexpected null request handler found", handler);
assertTrue("Unexpected request handler type", handler instanceof StandardRequestHandler);
// check the token type -> token provider mapping.
SecurityTokenProvider provider = config.getProviderForTokenType("http://www.tokens.org/SpecialToken");
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SpecialTokenProvider);
Map<String, String> properties = ((SpecialTokenProvider) provider).getProperties();
assertNotNull("Unexpected null properties map", properties);
assertEquals("Invalid property found", "Value1", properties.get("Property1"));
assertEquals("Invalid property found", "Value2", properties.get("Property2"));
provider = config.getProviderForTokenType(SAMLUtil.SAML2_TOKEN_TYPE);
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SAML20TokenProvider);
provider = config.getProviderForTokenType(SAMLUtil.SAML11_TOKEN_TYPE);
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SAML11TokenProvider);
assertNull(config.getProviderForTokenType("unexistentType"));
// check the service provider -> token provider mapping.
provider = config.getProviderForService("http://services.testcorp.org/provider1");
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SpecialTokenProvider);
provider = config.getProviderForService("http://services.testcorp.org/provider2");
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SAML20TokenProvider);
assertNull(config.getProviderForService("http://invalid.service/service"));
String family = SecurityTokenProvider.FAMILY_TYPE.WS_TRUST.toString();
// check the token element and namespace -> token provider mapping.
provider = config.getProviderForTokenElementNS(family, new QName("http://www.tokens.org", "SpecialToken"));
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SpecialTokenProvider);
provider = config.getProviderForTokenElementNS(family, new QName(JBossSAMLURIConstants.ASSERTION_NSURI.get(),
JBossSAMLConstants.ASSERTION.get()));
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SAML20TokenProvider);
provider = config.getProviderForTokenElementNS(family, new QName(SAML11Constants.ASSERTION_11_NSURI,
JBossSAMLConstants.ASSERTION.get()));
assertNotNull("Unexpected null token provider", provider);
assertTrue("Unexpected token provider type", provider instanceof SAML11TokenProvider);
assertNull(config.getProviderForTokenElementNS(family, new QName("InvalidNamespace", "SpecialToken")));
// check the service provider -> token type mapping.
assertEquals("Invalid token type for service provider 1", "http://www.tokens.org/SpecialToken",
config.getTokenTypeForService("http://services.testcorp.org/provider1"));
assertEquals("Invalid token type for service provider 2", SAMLUtil.SAML2_TOKEN_TYPE,
config.getTokenTypeForService("http://services.testcorp.org/provider2"));
assertNull(config.getTokenTypeForService("http://invalid.service/service"));
// check the keystore configuration.
assertNotNull("Invalid null STS key pair", config.getSTSKeyPair());
assertNotNull("Invalid null STS public key", config.getSTSKeyPair().getPublic());
assertNotNull("Invalid null STS private key", config.getSTSKeyPair().getPrivate());
assertNotNull("Invalid null validating key for service provider 1",
config.getServiceProviderPublicKey("http://services.testcorp.org/provider1"));
assertNotNull("Invalid null validating key for service provider 2",
config.getServiceProviderPublicKey("http://services.testcorp.org/provider2"));
}