Author: sguilhen(a)redhat.com
Date: 2009-04-06 13:57:14 -0400 (Mon, 06 Apr 2009)
New Revision: 427
Added:
identity-federation/trunk/identity-bindings/src/test/resources/config/test-config-4.xml
Modified:
identity-federation/trunk/identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java
Log:
JBID-76: Added an STS configuration sample and included a new test in the
ConfigUnitTestCase that parses this configuration file.
Modified:
identity-federation/trunk/identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java
===================================================================
---
identity-federation/trunk/identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java 2009-04-06
09:59:50 UTC (rev 426)
+++
identity-federation/trunk/identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/config/ConfigUnitTestCase.java 2009-04-06
17:57:14 UTC (rev 427)
@@ -34,37 +34,52 @@
import org.jboss.identity.federation.bindings.config.KeyProviderType;
import org.jboss.identity.federation.bindings.config.KeyValueType;
import org.jboss.identity.federation.bindings.config.SPType;
+import org.jboss.identity.federation.bindings.config.STSType;
+import org.jboss.identity.federation.bindings.config.ServiceProviderType;
+import org.jboss.identity.federation.bindings.config.ServiceProvidersType;
+import org.jboss.identity.federation.bindings.config.TokenProviderType;
+import org.jboss.identity.federation.bindings.config.TokenProvidersType;
import org.jboss.identity.federation.bindings.config.TrustType;
import org.jboss.identity.federation.core.saml.v2.factories.JBossSAMLBaseFactory;
/**
* Unit Test the various config
+ *
* @author Anil.Saldhana(a)redhat.com
* @since Jan 21, 2009
*/
public class ConfigUnitTestCase extends TestCase
{
String config = "config/test-config-";
-
+
+ @SuppressWarnings("unchecked")
public void test01() throws Exception
- {
- IDPType idp = this.getIDP(config + "1.xml");
- assertEquals("300000",300000L,idp.getAssertionValidity());
-
assertEquals("org.jboss.identity.federation.bindings.tomcat.TomcatRoleGenerator",idp.getRoleGenerator());
-
- TrustType trust = idp.getTrust();
- assertNotNull("Trust is not null", trust);
- String domains = trust.getDomains();
- assertTrue("localhost trusted", domains.indexOf("localhost")
> -1);
-
assertTrue("jboss.com trusted", domains.indexOf("jboss.com")
> -1);
+ {
+ Object object = this.unmarshall(config + "1.xml");
+ assertNotNull("IDP is not null", object);
+ assertTrue(object instanceof JAXBElement);
+
+ IDPType idp = ((JAXBElement<IDPType>) object).getValue();
+ assertEquals("300000", 300000L, idp.getAssertionValidity());
+
assertEquals("org.jboss.identity.federation.bindings.tomcat.TomcatRoleGenerator",
idp.getRoleGenerator());
+
+ TrustType trust = idp.getTrust();
+ assertNotNull("Trust is not null", trust);
+ String domains = trust.getDomains();
+ assertTrue("localhost trusted", domains.indexOf("localhost")
> -1);
+
assertTrue("jboss.com trusted", domains.indexOf("jboss.com")
> -1);
}
-
+
+ @SuppressWarnings("unchecked")
public void test02() throws Exception
{
- IDPType idp = this.getIDP(config + "2.xml");
-
- assertEquals("20000",20000L,idp.getAssertionValidity());
- assertEquals("somefqn",idp.getRoleGenerator());
+ Object object = this.unmarshall(config + "2.xml");
+ assertNotNull("IDP is not null", object);
+ assertTrue(object instanceof JAXBElement);
+
+ IDPType idp = ((JAXBElement<IDPType>) object).getValue();
+ assertEquals("20000", 20000L, idp.getAssertionValidity());
+ assertEquals("somefqn", idp.getRoleGenerator());
assertTrue(idp.isEncrypt());
KeyProviderType kp = idp.getKeyProvider();
assertNotNull("KeyProvider is not null", kp);
@@ -72,63 +87,95 @@
List<AuthPropertyType> authProps = kp.getAuth();
AuthPropertyType authProp = authProps.get(0);
assertEquals("SomeKey", "SomeKey", authProp.getKey());
- assertEquals("SomeValue", "SomeValue", authProp.getValue());
-
+ assertEquals("SomeValue", "SomeValue", authProp.getValue());
+
authProp = authProps.get(1);
assertEquals("DBURL", "DBURL", authProp.getKey());
- assertEquals("SomeDBURL", "SomeDBURL", authProp.getValue());
-
+ assertEquals("SomeDBURL", "SomeDBURL", authProp.getValue());
+
List<KeyValueType> validatingAliases = kp.getValidatingAlias();
assertEquals("Validating Alias length is 2", 2,
validatingAliases.size());
-
+
KeyValueType kv = validatingAliases.get(0);
assertEquals("localhost", kv.getKey());
assertEquals("localhostalias", kv.getValue());
-
+
kv = validatingAliases.get(1);
assertEquals("jboss.com", kv.getKey());
assertEquals("jbossalias", kv.getValue());
-
+
TrustType trust = idp.getTrust();
assertNotNull("Trust is not null", trust);
String domains = trust.getDomains();
assertTrue("localhost trusted", domains.indexOf("localhost")
> -1);
assertTrue("jboss.com trusted", domains.indexOf("jboss.com")
> -1);
}
-
+
+ @SuppressWarnings("unchecked")
public void test03() throws Exception
{
- SPType sp = getSP(config + "3.xml");
+ Object object = this.unmarshall(config + "3.xml");
+ assertNotNull("SP is null", object);
+ assertTrue(object instanceof JAXBElement);
+
+ SPType sp = ((JAXBElement<SPType>) object).getValue();
assertEquals("http://localhost:8080/idp", sp.getIdentityURL());
assertEquals("http://localhost:8080/sales", sp.getServiceURL());
}
-
+
+ /**
+ * <p>
+ * Tests the parsing of a Security Token Service configuration.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
@SuppressWarnings("unchecked")
- private SPType getSP(String configFile) throws Exception
+ public void test04() throws Exception
{
- String schema = "schema/config/jboss-identity-fed.xsd";
-
- ClassLoader tcl = Thread.currentThread().getContextClassLoader();
- InputStream is = tcl.getResourceAsStream(configFile);
- assertNotNull("Inputstream not null", is);
-
- Unmarshaller un =
JBossSAMLBaseFactory.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
schema);
- JAXBElement<SPType> jaxbSp = (JAXBElement<SPType>) un.unmarshal(is);
- assertNotNull("SP is not null", jaxbSp);
- return jaxbSp.getValue();
+ Object object = this.unmarshall(this.config + "4.xml");
+ assertNotNull("Found a null STS configuration", object);
+ assertTrue("Unexpected configuration type", object instanceof
JAXBElement);
+
+ STSType stsType = ((JAXBElement<STSType>) object).getValue();
+ // general STS configurations.
+ assertEquals("Unexpected STS name", "Test STS",
stsType.getSTSName());
+ assertEquals("Unexpected token timeout value", 7200,
stsType.getTokenTimeout().intValue());
+ assertTrue("Encryption of tokens should have been enabled",
stsType.isEncryptToken());
+ // we don't verify all values of the key provider config as it has been done in
the other test scenarios.
+ assertNotNull("Unexpected null key provider", stsType.getKeyProvider());
+ // request handler and configurations based on the token type.
+ assertEquals("Unexpected request handler class",
"org.jboss.identity.federation.wstrust.Handler", stsType
+ .getRequestHandler());
+ // configuration of the token providers.
+ TokenProvidersType tokenProviders = stsType.getTokenProviders();
+ assertNotNull("Unexpected null list of token providers",
tokenProviders);
+ assertEquals("Unexpected number of token providers", 1,
tokenProviders.getTokenProvider().size());
+ TokenProviderType tokenProvider = tokenProviders.getTokenProvider().get(0);
+ assertNotNull("Unexpected null token provider", tokenProvider);
+ assertEquals("Unexpected provider class name",
"org.jboss.SpecialTokenProvider", tokenProvider.getProviderClass());
+ assertEquals("Unexpected token type", "specialToken",
tokenProvider.getTokenType());
+ // configuration of the service providers.
+ ServiceProvidersType serviceProviders = stsType.getServiceProviders();
+ assertNotNull("Unexpected null list of service providers",
serviceProviders);
+ assertEquals("Unexpected number of service providers", 1,
serviceProviders.getServiceProvider().size());
+ ServiceProviderType serviceProvider =
serviceProviders.getServiceProvider().get(0);
+ assertNotNull("Unexpected null service provider", serviceProvider);
+ assertEquals("Unexpected provider endpoint",
"http://provider.endpoint/provider", serviceProvider.getEndpoint());
+ assertEquals("Unexpected truststore alias", "providerAlias",
serviceProvider.getTruststoreAlias());
+ assertEquals("Unexpected token type", "specialToken",
serviceProvider.getTokenType());
}
- @SuppressWarnings("unchecked")
- private IDPType getIDP(String configFile) throws Exception
+
+ private Object unmarshall(String configFile) throws Exception
{
String schema = "schema/config/jboss-identity-fed.xsd";
-
+
ClassLoader tcl = Thread.currentThread().getContextClassLoader();
InputStream is = tcl.getResourceAsStream(configFile);
assertNotNull("Inputstream not null", is);
-
- Unmarshaller un =
JBossSAMLBaseFactory.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
schema);
- JAXBElement<IDPType> jaxbIdp = (JAXBElement<IDPType>)
un.unmarshal(is);
- assertNotNull("IDP is not null", jaxbIdp);
- return jaxbIdp.getValue();
+
+ Unmarshaller un =
JBossSAMLBaseFactory.getValidatingUnmarshaller("org.jboss.identity.federation.bindings.config",
+ schema);
+ return un.unmarshal(is);
}
}
\ No newline at end of file
Added:
identity-federation/trunk/identity-bindings/src/test/resources/config/test-config-4.xml
===================================================================
---
identity-federation/trunk/identity-bindings/src/test/resources/config/test-config-4.xml
(rev 0)
+++
identity-federation/trunk/identity-bindings/src/test/resources/config/test-config-4.xml 2009-04-06
17:57:14 UTC (rev 427)
@@ -0,0 +1,23 @@
+<JBossSTS xmlns="urn:jboss:identity-federation:config:1.0">
+ <STSName>Test STS</STSName>
+ <TokenTimeout>7200</TokenTimeout>
+ <EncryptToken>true</EncryptToken>
+ <KeyProvider ClassName="SomeClass">
+ <ValidatingAlias Key="localhost" Value="localhostalias"/>
+ <ValidatingAlias Key="jboss.com" Value="jbossalias"/>
+ <SigningAlias>issueralias</SigningAlias>
+ </KeyProvider>
+ <RequestHandler>org.jboss.identity.federation.wstrust.Handler</RequestHandler>
+ <TokenProviders>
+ <TokenProvider>
+ <ProviderClass>org.jboss.SpecialTokenProvider</ProviderClass>
+ <TokenType>specialToken</TokenType>
+ </TokenProvider>
+ </TokenProviders>
+ <ServiceProviders>
+ <ServiceProvider endpoint="http://provider.endpoint/provider">
+ <TruststoreAlias>providerAlias</TruststoreAlias>
+ <TokenType>specialToken</TokenType>
+ </ServiceProvider>
+ </ServiceProviders>
+</JBossSTS>
\ No newline at end of file