Author: sguilhen(a)redhat.com
Date: 2009-04-28 10:58:51 -0400 (Tue, 28 Apr 2009)
New Revision: 464
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSUnitTestCase.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/SpecialTokenProvider.java
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/StandardTokenProvider.java
identity-federation/trunk/jboss-identity-bindings/src/test/resources/keystore/sts_keystore.jks
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/MockSTSConfiguration.java
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/SpecialTokenProvider.java
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/StandardTokenProvider.java
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustJAXBFactoryUnitTestCase.java
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustServiceFactoryUnitTestCase.java
Removed:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/identity/
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSTest.java
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/config/ServiceProviderType.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTS.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/SecurityActions.java
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/cert/KeyStoreUtil.java
identity-federation/trunk/jboss-identity-bindings/src/main/resources/schema/config/jboss-identity-fed.xsd
identity-federation/trunk/jboss-identity-bindings/src/test/resources/config/test-config-4.xml
identity-federation/trunk/jboss-identity-bindings/src/test/resources/jboss-sts.xml
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/SecurityActions.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/StandardRequestHandler.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustJAXBFactory.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestContext.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestHandler.java
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustServiceFactory.java
Log:
JBID-77: Added test cases for the core classes and factories. Included the caller
principal in the wstrust request context. Added missing javadocs and fixed minor problems
uncovered by the test cases.
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/config/ServiceProviderType.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/config/ServiceProviderType.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/config/ServiceProviderType.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -44,7 +44,7 @@
@XmlType(name = "ServiceProviderType")
public class ServiceProviderType {
- @XmlAttribute(required = true)
+ @XmlAttribute(name = "Endpoint", required = true)
protected String endpoint;
@XmlAttribute(name = "TruststoreAlias", required = true)
protected String truststoreAlias;
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTS.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTS.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTS.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -40,7 +40,6 @@
import org.jboss.identity.federation.api.wstrust.WSTrustException;
import org.jboss.identity.federation.api.wstrust.WSTrustJAXBFactory;
import org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler;
-import org.jboss.identity.federation.api.wstrust.WSTrustServiceFactory;
import org.jboss.identity.federation.api.wstrust.protocol.BaseRequestSecurityToken;
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken;
import
org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenCollection;
@@ -94,19 +93,19 @@
if(this.config == null)
this.config = this.getConfiguration();
- WSTrustRequestHandler handler =
WSTrustServiceFactory.getInstance().createRequestHandler(this.config);
+ WSTrustRequestHandler handler = this.config.getRequestHandler();
String requestType = request.getRequestType().toString();
try
{
if (requestType.equals(WSTrustConstants.ISSUE_REQUEST))
- return this.marshallResponse(handler.issue(request,
this.context.getMessageContext()));
+ return this.marshallResponse(handler.issue(request,
this.context.getUserPrincipal()));
else if (requestType.equals(WSTrustConstants.RENEW_REQUEST))
- return this.marshallResponse(handler.renew(request,
this.context.getMessageContext()));
+ return this.marshallResponse(handler.renew(request,
this.context.getUserPrincipal()));
else if (requestType.equals(WSTrustConstants.CANCEL_REQUEST))
- return this.marshallResponse(handler.cancel(request,
this.context.getMessageContext()));
+ return this.marshallResponse(handler.cancel(request,
this.context.getUserPrincipal()));
else if (requestType.equals(WSTrustConstants.VALIDATE_REQUEST))
- return this.marshallResponse(handler.validate(request,
this.context.getMessageContext()));
+ return this.marshallResponse(handler.validate(request,
this.context.getUserPrincipal()));
else
throw new WSTrustException("Invalid request type: " +
requestType);
}
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/SecurityActions.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/SecurityActions.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/jboss/trust/SecurityActions.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -27,8 +27,8 @@
import java.security.PrivilegedExceptionAction;
/**
- *
* <p>
+ * Utility class that executes actions such as creating a class in privileged blocks.
* </p>
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
@@ -37,8 +37,11 @@
{
/**
+ * <p>
+ * Gets the thread context class loader using a privileged block.
+ * </p>
*
- * @return
+ * @return a reference to the thread context {@code ClassLoader}.
*/
static ClassLoader getContextClassLoader()
{
@@ -52,10 +55,15 @@
}
/**
+ * <p>
+ * Loads a class using the thread context class loader in a privileged block.
+ * </p>
*
- * @param name
- * @return
- * @throws PrivilegedActionException
+ * @param name the fully-qualified name of the class to be loaded.
+ * @return a reference to the loaded {@code Class}.
+ * @throws PrivilegedActionException if an error occurs while loading the class. This
exception wraps the real cause
+ * of the error, so classes using this method must perform a {@code
getCause()} in order to get a
+ * reference to the root of the error.
*/
static Class<?> loadClass(final String name) throws PrivilegedActionException
{
@@ -76,10 +84,15 @@
}
/**
+ * <p>
+ * Creates an instance of the specified class in a privileged block. The class must
define a default constructor.
+ * </p>
*
- * @param className
- * @return
- * @throws PrivilegedActionException
+ * @param className the fully-qualified name of the class to be instantiated.
+ * @return a reference to the instantiated {@code Object}.
+ * @throws PrivilegedActionException if an error occurs while instantiating the class.
This exception wraps the real
+ * cause of the error, so classes using this method must perform a {@code
getCause()} in order to get a
+ * reference to the root of the error.
*/
static Object instantiateClass(final String className) throws
PrivilegedActionException
{
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/cert/KeyStoreUtil.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/cert/KeyStoreUtil.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/java/org/jboss/identity/federation/bindings/util/cert/KeyStoreUtil.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -144,6 +144,13 @@
// Get public key
publicKey = cert.getPublicKey();
}
+ // if alias is a certificate alias, get the public key from the certificate.
+ if(publicKey == null)
+ {
+ Certificate cert = ks.getCertificate(alias);
+ if(cert != null)
+ publicKey = cert.getPublicKey();
+ }
return publicKey;
}
Modified:
identity-federation/trunk/jboss-identity-bindings/src/main/resources/schema/config/jboss-identity-fed.xsd
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/main/resources/schema/config/jboss-identity-fed.xsd 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/main/resources/schema/config/jboss-identity-fed.xsd 2009-04-28
14:58:51 UTC (rev 464)
@@ -208,7 +208,7 @@
generated token.
</documentation>
</annotation>
- <attribute name="endpoint" type="string"
use="required"/>
+ <attribute name="Endpoint" type="string"
use="required"/>
<attribute name="TruststoreAlias" type="string"
use="required"/>
<attribute name="TokenType" type="string"
use="required"/>
</complexType>
Copied:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust
(from rev 437,
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/identity/federation/bindings/jboss/trust)
Deleted:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSTest.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTSTest.java 2009-04-15
18:30:26 UTC (rev 437)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSTest.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -1,35 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2009, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.identity.federation.bindings.jboss.trust;
-
-import org.jboss.identity.federation.api.wstrust.STSConfiguration;
-
-public class JBossSTSTest
-{
-
- public static void main(String[] args)
- {
- JBossSTS sts = new JBossSTS();
- STSConfiguration config = sts.getConfiguration();
- System.out.println(config.getEncryptIssuedToken());
- }
-}
Copied:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSUnitTestCase.java
(from rev 437,
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/identity/federation/bindings/jboss/trust/JBossSTSTest.java)
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/JBossSTSUnitTestCase.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,136 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.trust;
+
+import junit.framework.TestCase;
+
+import org.jboss.identity.federation.api.wstrust.STSConfiguration;
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.StandardRequestHandler;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler;
+import org.jboss.identity.federation.bindings.jboss.trust.JBossSTS;
+
+/**
+ * <p>
+ * This {@code TestCase} tests the behavior of the {@code JBossSTS} service.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class JBossSTSUnitTestCase extends TestCase
+{
+
+ /**
+ * <p>
+ * This test verifies that the STS service can read and load all configuration
parameters correctly. The
+ * configuration file (jboss-sts.xml) looks like the following:
+ *
+ * <pre>
+ * <JBossSTS
xmlns="urn:jboss:identity-federation:config:1.0"
+ * STSName="Test STS" TokenTimeout="7200"
EncryptToken="true">
+ * <KeyProvider
ClassName="org.jboss.identity.federation.bindings.tomcat.KeyStoreKeyManager">
+ * <Auth Key="KeyStoreURL"
Value="keystore/sts_keystore.jks"/>
+ * <Auth Key="KeyStorePass"
Value="testpass"/>
+ * <Auth Key="SigningKeyAlias"
Value="sts"/>
+ * <Auth Key="SigningKeyPass"
Value="keypass"/>
+ * <ValidatingAlias
Key="http://services.testcorp.org/provider1"
Value="service1"/>
+ * <ValidatingAlias
Key="http://services.testcorp.org/provider2"
Value="service2"/>
+ * </KeyProvider>
+ *
<RequestHandler>org.jboss.identity.federation.wstrust.Handler</RequestHandler>
+ * <ServiceProviders>
+ * <ServiceProvider
endpoint="http://services.testcorp.org/provider1"
TokenType="specialToken"
+ * TruststoreAlias="service1"/>
+ * <ServiceProvider
endpoint="http://services.testcorp.org/provider2"
TokenType="specialToken"
+ * TruststoreAlias="service2"/>
+ * </ServiceProviders>
+ * </JBossSTS>
+ * </pre>
+ *
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testSTSConfiguration() throws Exception
+ {
+ // for testing purposes we can instantiate the TestSTS as a regular POJO.
+ TestSTS sts = new TestSTS();
+
+ // make the STS read the configuration file.
+ STSConfiguration config = sts.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());
+ assertTrue("Encrypt token should be true",
config.getEncryptIssuedToken());
+ 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("specialToken");
+ assertNotNull("Unexpected null token provider", provider);
+ assertTrue("Unexpected token provider type", provider instanceof
SpecialTokenProvider);
+ provider = config.getProviderForTokenType("standardToken");
+ assertNotNull("Unexpected null token provider", provider);
+ assertTrue("Unexpected token provider type", provider instanceof
StandardTokenProvider);
+ assertNull(config.getProviderForTokenType("unexistentType"));
+
+ // check the service provider -> token type mapping.
+ assertEquals("Invalid token type for service provider 1",
"specialToken", config
+
.getTokenTypeForService("http://services.testcorp.org/provider1"));
+ assertEquals("Invalid token type for service provider 2",
"standardToken", config
+
.getTokenTypeForService("http://services.testcorp.org/provider2"));
+
assertNull(config.getTokenTypeForService("http://invalid.service/service"));
+
+ // 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
StandardTokenProvider);
+
assertNull(config.getProviderForService("http://invalid.service/service"));
+
+ // check the keystore configuration.
+ assertNotNull("Invalid null private key", config.getSigningKey());
+ assertNotNull("Invalid null validating key for service provider 1",
config
+
.getPublicKeyForService("http://services.testcorp.org/provider1"));
+ assertNotNull("Invalid null validating key for service provider 2",
config
+
.getPublicKeyForService("http://services.testcorp.org/provider2"));
+ }
+
+ /**
+ * <p>
+ * Helper class that exposes the JBossSTS methods as public for the tests to work.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan
Guilhen</a>
+ */
+ class TestSTS extends JBossSTS
+ {
+ @Override
+ public STSConfiguration getConfiguration()
+ {
+ return super.getConfiguration();
+ }
+ }
+}
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/SpecialTokenProvider.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/SpecialTokenProvider.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/SpecialTokenProvider.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.trust;
+
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.WSTrustException;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestContext;
+
+/**
+ * <p>
+ * Mock {@code SecurityTokenProvider} used in the test scenarios.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class SpecialTokenProvider implements SecurityTokenProvider
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#cancelToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void cancelToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#issueToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void issueToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#renewToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void renewToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#validateToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void validateToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+}
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/StandardTokenProvider.java
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/StandardTokenProvider.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/java/org/jboss/test/identity/federation/bindings/trust/StandardTokenProvider.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.bindings.trust;
+
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.WSTrustException;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestContext;
+
+/**
+ * <p>
+ * Mock {@code SecurityTokenProvider} used in the test scenarios.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class StandardTokenProvider implements SecurityTokenProvider
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#cancelToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void cancelToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#issueToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void issueToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#renewToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void renewToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#validateToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void validateToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+}
Modified:
identity-federation/trunk/jboss-identity-bindings/src/test/resources/config/test-config-4.xml
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/resources/config/test-config-4.xml 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/resources/config/test-config-4.xml 2009-04-28
14:58:51 UTC (rev 464)
@@ -10,7 +10,7 @@
<TokenProvider ProviderClass="org.jboss.SpecialTokenProvider"
TokenType="specialToken"/>
</TokenProviders>
<ServiceProviders>
- <ServiceProvider endpoint="http://provider.endpoint/provider"
TokenType="specialToken"
+ <ServiceProvider Endpoint="http://provider.endpoint/provider"
TokenType="specialToken"
TruststoreAlias="providerAlias"/>
</ServiceProviders>
</JBossSTS>
\ No newline at end of file
Modified:
identity-federation/trunk/jboss-identity-bindings/src/test/resources/jboss-sts.xml
===================================================================
---
identity-federation/trunk/jboss-identity-bindings/src/test/resources/jboss-sts.xml 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-bindings/src/test/resources/jboss-sts.xml 2009-04-28
14:58:51 UTC (rev 464)
@@ -1,17 +1,24 @@
<JBossSTS xmlns="urn:jboss:identity-federation:config:1.0"
STSName="Test STS" TokenTimeout="7200"
EncryptToken="true">
<KeyProvider
ClassName="org.jboss.identity.federation.bindings.tomcat.KeyStoreKeyManager">
- <Auth Key="KeyStoreURL" Value="file://url/to/keystore.jks" />
- <Auth Key="KeyStorePass" Value="SomePassword" />
- <Auth Key="SigningKeyAlias" Value="SigningAlias" />
- <Auth Key="SigningKeyPass" Value="SigningPass" />
- <ValidatingAlias Key="localhost" Value="localhostalias"/>
- <ValidatingAlias Key="jboss.com" Value="jbossalias"/>
- <SigningAlias>issueralias</SigningAlias>
+ <Auth Key="KeyStoreURL" Value="keystore/sts_keystore.jks"/>
+ <Auth Key="KeyStorePass" Value="testpass"/>
+ <Auth Key="SigningKeyAlias" Value="sts"/>
+ <Auth Key="SigningKeyPass" Value="keypass"/>
+ <ValidatingAlias
Key="http://services.testcorp.org/provider1"
Value="service1"/>
+ <ValidatingAlias
Key="http://services.testcorp.org/provider2"
Value="service2"/>
</KeyProvider>
- <RequestHandler>org.jboss.identity.federation.wstrust.Handler</RequestHandler>
+ <RequestHandler>org.jboss.identity.federation.api.wstrust.StandardRequestHandler</RequestHandler>
+ <TokenProviders>
+ <TokenProvider
ProviderClass="org.jboss.test.identity.federation.bindings.trust.SpecialTokenProvider"
+ TokenType="specialToken"/>
+ <TokenProvider
ProviderClass="org.jboss.test.identity.federation.bindings.trust.StandardTokenProvider"
+ TokenType="standardToken"/>
+ </TokenProviders>
<ServiceProviders>
- <ServiceProvider endpoint="http://provider.endpoint/provider"
TokenType="specialToken"
- TruststoreAlias="providerAlias"/>
+ <ServiceProvider
Endpoint="http://services.testcorp.org/provider1"
TokenType="specialToken"
+ TruststoreAlias="service1"/>
+ <ServiceProvider
Endpoint="http://services.testcorp.org/provider2"
TokenType="standardToken"
+ TruststoreAlias="service2"/>
</ServiceProviders>
</JBossSTS>
\ No newline at end of file
Added:
identity-federation/trunk/jboss-identity-bindings/src/test/resources/keystore/sts_keystore.jks
===================================================================
(Binary files differ)
Property changes on:
identity-federation/trunk/jboss-identity-bindings/src/test/resources/keystore/sts_keystore.jks
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/SecurityActions.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/SecurityActions.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/SecurityActions.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -27,8 +27,8 @@
import java.security.PrivilegedExceptionAction;
/**
- *
* <p>
+ * Utility class that executes actions such as creating a class in privileged blocks.
* </p>
*
* @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
@@ -37,8 +37,11 @@
{
/**
+ * <p>
+ * Gets the thread context class loader using a privileged block.
+ * </p>
*
- * @return
+ * @return a reference to the thread context {@code ClassLoader}.
*/
static ClassLoader getContextClassLoader()
{
@@ -52,10 +55,15 @@
}
/**
+ * <p>
+ * Loads a class using the thread context class loader in a privileged block.
+ * </p>
*
- * @param name
- * @return
- * @throws PrivilegedActionException
+ * @param name the fully-qualified name of the class to be loaded.
+ * @return a reference to the loaded {@code Class}.
+ * @throws PrivilegedActionException if an error occurs while loading the class. This
exception wraps the real cause
+ * of the error, so classes using this method must perform a {@code
getCause()} in order to get a
+ * reference to the root of the error.
*/
static Class<?> loadClass(final String name) throws PrivilegedActionException
{
@@ -76,10 +84,15 @@
}
/**
+ * <p>
+ * Creates an instance of the specified class in a privileged block. The class must
define a default constructor.
+ * </p>
*
- * @param className
- * @return
- * @throws PrivilegedActionException
+ * @param className the fully-qualified name of the class to be instantiated.
+ * @return a reference to the instantiated {@code Object}.
+ * @throws PrivilegedActionException if an error occurs while instantiating the class.
This exception wraps the real
+ * cause of the error, so classes using this method must perform a {@code
getCause()} in order to get a
+ * reference to the root of the error.
*/
static Object instantiateClass(final String className) throws
PrivilegedActionException
{
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/StandardRequestHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/StandardRequestHandler.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/StandardRequestHandler.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -21,14 +21,8 @@
*/
package org.jboss.identity.federation.api.wstrust;
-import javax.xml.ws.handler.MessageContext;
+import java.security.Principal;
-import org.jboss.identity.federation.api.wstrust.STSConfiguration;
-import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
-import org.jboss.identity.federation.api.wstrust.WSTrustException;
-import org.jboss.identity.federation.api.wstrust.WSTrustRequestContext;
-import org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler;
-import org.jboss.identity.federation.api.wstrust.WSTrustUtil;
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken;
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenResponse;
import org.jboss.identity.federation.ws.policy.AppliesTo;
@@ -63,51 +57,51 @@
* (non-Javadoc)
*
* @see
org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler#issue(org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken,
- * javax.xml.ws.handler.MessageContext)
+ * java.security.Principal)
*/
- public RequestSecurityTokenResponse issue(RequestSecurityToken request, MessageContext
context)
+ public RequestSecurityTokenResponse issue(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException
{
SecurityTokenProvider provider = null;
-
+
// first try to obtain the security token provider using the applies-to contents.
AppliesTo appliesTo = request.getAppliesTo();
- if(appliesTo != null)
+ if (appliesTo != null)
{
String serviceName = WSTrustUtil.parseAppliesTo(appliesTo);
- if(serviceName != null)
+ if (serviceName != null)
provider = this.configuration.getProviderForService(serviceName);
}
// if applies-to is not available or if no provider was found for the service, use
the token type.
- if(provider == null && request.getTokenType() != null)
+ if (provider == null && request.getTokenType() != null)
{
provider =
this.configuration.getProviderForTokenType(request.getTokenType().toString());
}
- else if(appliesTo == null && request.getTokenType() == null)
+ else if (appliesTo == null && request.getTokenType() == null)
throw new WSTrustException("Either AppliesTo or TokenType must be present
in a security token request");
-
- if(provider != null)
+
+ if (provider != null)
{
// create the request context and delegate token generation to the provider.
- WSTrustRequestContext requestContext = new WSTrustRequestContext(request);
- if(request.getLifetime() == null &&
this.configuration.getIssuedTokenTimeout() != 0)
+ WSTrustRequestContext requestContext = new WSTrustRequestContext(request,
callerPrincipal);
+ if (request.getLifetime() == null &&
this.configuration.getIssuedTokenTimeout() != 0)
{
// if no lifetime has been specified, use the configured timeout value.
LifetimeType lifetime =
WSTrustUtil.createDefaultLifetime(this.configuration.getIssuedTokenTimeout());
request.setLifetime(lifetime);
}
provider.issueToken(requestContext);
-
+
// construct the ws-trust security token response.
RequestedSecurityTokenType requestedSecurityToken = new
RequestedSecurityTokenType();
requestedSecurityToken.setAny(requestContext.getSecurityToken());
-
+
// TODO: create proof token and encrypt the token if needed
-
+
RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
- if(request.getContext() != null)
+ if (request.getContext() != null)
response.setContext(request.getContext());
-
+
response.setTokenType(request.getTokenType());
response.setLifetime(request.getLifetime());
response.setAppliesTo(appliesTo);
@@ -122,9 +116,9 @@
* (non-Javadoc)
*
* @see
org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler#renew(org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken,
- * javax.xml.ws.handler.MessageContext)
+ * java.security.Principal)
*/
- public RequestSecurityTokenResponse renew(RequestSecurityToken request, MessageContext
context)
+ public RequestSecurityTokenResponse renew(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException
{
// TODO: implement renew logic.
@@ -135,9 +129,9 @@
* (non-Javadoc)
*
* @see
org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler#validate(org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken,
- * javax.xml.ws.handler.MessageContext)
+ * java.security.Principal)
*/
- public RequestSecurityTokenResponse validate(RequestSecurityToken request,
MessageContext context)
+ public RequestSecurityTokenResponse validate(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException
{
// TODO: implement validate logic.
@@ -148,9 +142,9 @@
* (non-Javadoc)
*
* @see
org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler#cancel(org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken,
- * javax.xml.ws.handler.MessageContext)
+ * java.security.Principal)
*/
- public RequestSecurityTokenResponse cancel(RequestSecurityToken request,
MessageContext context)
+ public RequestSecurityTokenResponse cancel(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException
{
// TODO: implement cancel logic.
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustJAXBFactory.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustJAXBFactory.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustJAXBFactory.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -108,6 +108,7 @@
{
Unmarshaller unmarshaller = this.context.createUnmarshaller();
Object object = unmarshaller.unmarshal(request);
+
// check the type of the unmarshalled object.
if (object instanceof RequestSecurityTokenType)
return new RequestSecurityToken((RequestSecurityTokenType) object);
@@ -148,15 +149,26 @@
try
{
Unmarshaller unmarshaller = this.context.createUnmarshaller();
- JAXBElement<?> element = (JAXBElement<?>)
unmarshaller.unmarshal(response);
- // is this a single token response or a collection of token responses
- if (element.getDeclaredType().equals(RequestSecurityTokenResponseType.class))
- return new RequestSecurityTokenResponse((RequestSecurityTokenResponseType)
element.getValue());
- else if
(element.getDeclaredType().equals(RequestSecurityTokenResponseCollectionType.class))
- return new
RequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType)
element
- .getValue());
+ Object object = unmarshaller.unmarshal(response);
+ // check the type of the response object.
+ if (object instanceof RequestSecurityTokenResponseType)
+ return new RequestSecurityTokenResponse((RequestSecurityTokenResponseType)
object);
+ else if (object instanceof RequestSecurityTokenResponseCollectionType)
+ return new
RequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType)
object);
+ else if (object instanceof JAXBElement)
+ {
+ JAXBElement<?> element = (JAXBElement<?>)
unmarshaller.unmarshal(response);
+ // is this a single token response or a collection of token responses
+ if
(element.getDeclaredType().equals(RequestSecurityTokenResponseType.class))
+ return new RequestSecurityTokenResponse((RequestSecurityTokenResponseType)
element.getValue());
+ else if
(element.getDeclaredType().equals(RequestSecurityTokenResponseCollectionType.class))
+ return new
RequestSecurityTokenResponseCollection((RequestSecurityTokenResponseCollectionType)
element
+ .getValue());
+ else
+ throw new RuntimeException("Invalid response type: " +
element.getDeclaredType());
+ }
else
- throw new RuntimeException("Invalid response type: " +
element.getDeclaredType());
+ throw new RuntimeException("Invalid response type: " +
object.getClass().getName());
}
catch (Exception e)
{
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestContext.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestContext.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestContext.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -21,6 +21,8 @@
*/
package org.jboss.identity.federation.api.wstrust;
+import java.security.Principal;
+
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken;
/**
@@ -36,6 +38,8 @@
private final RequestSecurityToken request;
+ private final Principal callerPrincipal;
+
private SecurityToken securityToken;
/**
@@ -46,9 +50,10 @@
* @param request a {@code RequestSecurityToken} object that contains the information
about the security token
* request.
*/
- public WSTrustRequestContext(RequestSecurityToken request)
+ public WSTrustRequestContext(RequestSecurityToken request, Principal callerPrincipal)
{
this.request = request;
+ this.callerPrincipal = callerPrincipal;
}
/**
@@ -65,6 +70,18 @@
/**
* <p>
+ * Obtains the principal of the ws-trust token requester.
+ * </p>
+ *
+ * @return a reference to the caller {@code Principal} object.
+ */
+ public Principal getCallerPrincipal()
+ {
+ return this.callerPrincipal;
+ }
+
+ /**
+ * <p>
* Obtains the security token contained in this context.
* </p>
*
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestHandler.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestHandler.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustRequestHandler.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -21,7 +21,7 @@
*/
package org.jboss.identity.federation.api.wstrust;
-import javax.xml.ws.handler.MessageContext;
+import java.security.Principal;
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken;
import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenResponse;
@@ -53,12 +53,11 @@
* </p>
*
* @param request the security token request message.
- * @param context the context of the token request message. The context provides
information that may be relevant to
- * the request processing, such as the subject of the caller.
+ * @param callerPrincipal the {@code Principal} of the ws-trust token requester.
* @return a {@code RequestSecurityTokenResponse} containing the generated token.
* @throws WSTrustException if an error occurs while handling the request message.
*/
- public RequestSecurityTokenResponse issue(RequestSecurityToken request, MessageContext
context)
+ public RequestSecurityTokenResponse issue(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException;
/**
@@ -67,12 +66,11 @@
* </p>
*
* @param request the request message that contains the token to be renewed.
- * @param context the context of the token request message. The context provides
information that may be relevant to
- * the request processing, such as the subject of the caller.
+ * @param callerPrincipal the {@code Principal} of the ws-trust token requester.
* @return a {@code RequestSecurityTokenResponse} containing the renewed token.
* @throws WSTrustException if an error occurs while handling the renewal process.
*/
- public RequestSecurityTokenResponse renew(RequestSecurityToken request, MessageContext
context)
+ public RequestSecurityTokenResponse renew(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException;
/**
@@ -81,12 +79,11 @@
* </p>
*
* @param request the request message that contains the token to be canceled.
- * @param context the context of the token request message. The context provides
information that may be relevant to
- * the request processing, such as the subject of the caller.
+ * @param callerPrincipal the {@code Principal} of the ws-trust token requester.
* @return a {@code RequestSecurityTokenResponse} indicating whether the token has
been canceled or not.
* @throws WSTrustException if an error occurs while handling the cancellation
process.
*/
- public RequestSecurityTokenResponse cancel(RequestSecurityToken request,
MessageContext context)
+ public RequestSecurityTokenResponse cancel(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException;
/**
@@ -95,11 +92,10 @@
* </p>
*
* @param request the request message that contains the token to be validated.
- * @param context the context of the token request message. The context provides
information that may be relevant to
- * the request processing, such as the subject of the caller.
+ * @param callerPrincipal the {@code Principal} of the ws-trust token requester.
* @return a {@code RequestSecurityTokenResponse} containing the validation status or
a new token.
* @throws WSTrustException if an error occurs while handling the validation process.
*/
- public RequestSecurityTokenResponse validate(RequestSecurityToken request,
MessageContext context)
+ public RequestSecurityTokenResponse validate(RequestSecurityToken request, Principal
callerPrincipal)
throws WSTrustException;
}
Modified:
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustServiceFactory.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustServiceFactory.java 2009-04-28
14:53:13 UTC (rev 463)
+++
identity-federation/trunk/jboss-identity-fed-api/src/main/java/org/jboss/identity/federation/api/wstrust/WSTrustServiceFactory.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -65,9 +65,8 @@
* @param configuration a reference to the {@code STSConfiguration}.
* @return a reference to the constructed {@code WSTrustRequestHandler} object.
*/
- public WSTrustRequestHandler createRequestHandler(STSConfiguration configuration)
+ public WSTrustRequestHandler createRequestHandler(String handlerClassName,
STSConfiguration configuration)
{
- String handlerClassName = configuration.getRequestHandlerClass();
try
{
WSTrustRequestHandler handler = (WSTrustRequestHandler)
SecurityActions.instantiateClass(handlerClassName);
Added:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/MockSTSConfiguration.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/MockSTSConfiguration.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/MockSTSConfiguration.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,130 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.api.wstrust;
+
+import java.security.PrivateKey;
+import java.security.PublicKey;
+import java.util.Map;
+
+import org.jboss.identity.federation.api.wstrust.STSConfiguration;
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler;
+
+/**
+ * <p>
+ * Mock implementation of {@code STSConfiguration} used in the test scenarios.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class MockSTSConfiguration implements STSConfiguration
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getEncryptIssuedToken()
+ */
+ public boolean getEncryptIssuedToken()
+ {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getIssuedTokenTimeout()
+ */
+ public long getIssuedTokenTimeout()
+ {
+ return 0;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.jboss.identity.federation.api.wstrust.STSConfiguration#getOptions()
+ */
+ public Map<String, Object> getOptions()
+ {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getProviderForService(java.lang.String)
+ */
+ public SecurityTokenProvider getProviderForService(String serviceName)
+ {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getProviderForTokenType(java.lang.String)
+ */
+ public SecurityTokenProvider getProviderForTokenType(String tokenType)
+ {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getPublicKeyForService(java.lang.String)
+ */
+ public PublicKey getPublicKeyForService(String serviceName)
+ {
+ return null;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.STSConfiguration#getRequestHandler()
+ */
+ public WSTrustRequestHandler getRequestHandler()
+ {
+ return null;
+ }
+
+ public String getSTSName()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public PrivateKey getSigningKey()
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ public String getTokenTypeForService(String serviceName)
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+}
Added:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/SpecialTokenProvider.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/SpecialTokenProvider.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/SpecialTokenProvider.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.api.wstrust;
+
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.WSTrustException;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestContext;
+
+/**
+ * <p>
+ * Mock {@code SecurityTokenProvider} used in the test scenarios.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class SpecialTokenProvider implements SecurityTokenProvider
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#cancelToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void cancelToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#issueToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void issueToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#renewToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void renewToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#validateToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void validateToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+}
Added:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/StandardTokenProvider.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/StandardTokenProvider.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/StandardTokenProvider.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,74 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.api.wstrust;
+
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.WSTrustException;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestContext;
+
+/**
+ * <p>
+ * Mock {@code SecurityTokenProvider} used in the test scenarios.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class StandardTokenProvider implements SecurityTokenProvider
+{
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#cancelToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void cancelToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#issueToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void issueToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#renewToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void renewToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.jboss.identity.federation.api.wstrust.SecurityTokenProvider#validateToken(org.jboss.identity.federation.api.wstrust.WSTrustRequestContext)
+ */
+ public void validateToken(WSTrustRequestContext context) throws WSTrustException
+ {
+ }
+
+}
Added:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustJAXBFactoryUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustJAXBFactoryUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustJAXBFactoryUnitTestCase.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,275 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.api.wstrust;
+
+import java.net.URI;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.util.JAXBSource;
+import javax.xml.transform.Source;
+
+import junit.framework.TestCase;
+
+import org.jboss.identity.federation.api.wstrust.WSTrustJAXBFactory;
+import org.jboss.identity.federation.api.wstrust.protocol.BaseRequestSecurityToken;
+import
org.jboss.identity.federation.api.wstrust.protocol.BaseRequestSecurityTokenResponse;
+import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityToken;
+import
org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenCollection;
+import org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenResponse;
+import
org.jboss.identity.federation.api.wstrust.protocol.RequestSecurityTokenResponseCollection;
+import org.jboss.identity.federation.ws.trust.ObjectFactory;
+
+/**
+ * <p>
+ * This {@code TestCase} tests the methods of the {@code WSTrustJAXBFactory}.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class WSTrustJAXBFactoryUnitTestCase extends TestCase
+{
+
+ private JAXBContext context;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception
+ {
+ StringBuffer packages = new StringBuffer();
+ packages.append("org.jboss.identity.federation.ws.addressing");
+ packages.append(":org.jboss.identity.federation.ws.policy");
+ packages.append(":org.jboss.identity.federation.ws.trust");
+ packages.append(":org.jboss.identity.federation.ws.wss.secext");
+ packages.append(":org.jboss.identity.federation.ws.wss.utility");
+ this.context = JAXBContext.newInstance(packages.toString());
+ }
+
+ /**
+ * <p>
+ * Tests parsing a WS-Trust request message.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testParseRequestSecurityToken() throws Exception
+ {
+ // create a sample ws-trust request.
+ RequestSecurityToken request = new RequestSecurityToken();
+ request.setContext("testcontext");
+ request.setTokenType(new
URI("http://example.org/specialToken"));
+ request.setRequestType(new
URI("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue"));
+
+ // encapsulate the request in a source object.
+ ObjectFactory objectFactory = new ObjectFactory();
+ JAXBElement<?> element =
objectFactory.createRequestSecurityToken(request.getDelegate());
+ JAXBSource source = new JAXBSource(this.context, element);
+
+ // parse the request using the WSTrustJAXBFactory.
+ WSTrustJAXBFactory factory = WSTrustJAXBFactory.getInstance();
+ BaseRequestSecurityToken baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null request message", baseRequest);
+
+ // check the contents of the parsed request.
+ assertTrue("Unexpected request message type", baseRequest instanceof
RequestSecurityToken);
+ RequestSecurityToken parsedRequest = (RequestSecurityToken) baseRequest;
+ assertEquals("Unexpected context name", "testcontext",
parsedRequest.getContext());
+ assertEquals("Unexpected token type",
"http://example.org/specialToken", parsedRequest.getTokenType().toString());
+ assertEquals("Unexpected request type",
"http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue", parsedRequest
+ .getRequestType().toString());
+
+ // repeat the test, this time using a request collection instead of a single
request.
+ RequestSecurityTokenCollection collection = new RequestSecurityTokenCollection();
+ collection.addRequestSecurityToken(request);
+ element =
objectFactory.createRequestSecurityTokenCollection(collection.getDelegate());
+ source = new JAXBSource(this.context, element);
+
+ baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null request message", baseRequest);
+ assertTrue("Unexpected request message type", baseRequest instanceof
RequestSecurityTokenCollection);
+ RequestSecurityTokenCollection parsedCollection = (RequestSecurityTokenCollection)
baseRequest;
+ assertNotNull("Unexpected null request list",
parsedCollection.getRequestSecurityTokens());
+ assertEquals("Unexpected number of requests", 1,
parsedCollection.getRequestSecurityTokens().size());
+
+ // repeat the tests, this time creating a source that contains the request message
directly (no JAXBElement).
+ source = new JAXBSource(this.context, request.getDelegate());
+ baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null request message", baseRequest);
+ assertTrue("Unexpected request message type", baseRequest instanceof
RequestSecurityToken);
+
+ source = new JAXBSource(this.context, collection.getDelegate());
+ baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null request message", baseRequest);
+ assertTrue("Unexpected request message type", baseRequest instanceof
RequestSecurityTokenCollection);
+ }
+
+ /**
+ * <p>
+ * Tests parsing a WS-Trust response message.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testParseRequestSecurityTokenResponse() throws Exception
+ {
+ // create a sample ws-trust response message.
+ RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
+ response.setContext("testcontext");
+ response.setTokenType(new
URI("http://example.org/specialToken"));
+ response.setForwardable(false);
+
+ // encapsulate the response in a source object.
+ ObjectFactory objectFactory = new ObjectFactory();
+ JAXBElement<?> element =
objectFactory.createRequestSecurityTokenResponse(response.getDelegate());
+ JAXBSource source = new JAXBSource(this.context, element);
+
+ // parse the response using the WSTrustJAXBFactory.
+ WSTrustJAXBFactory factory = WSTrustJAXBFactory.getInstance();
+ BaseRequestSecurityTokenResponse baseResponse =
factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null response message", baseResponse);
+
+ // check the contents of the parsed response.
+ assertTrue("Unexpected response message type", baseResponse instanceof
RequestSecurityTokenResponse);
+ RequestSecurityTokenResponse parsedResponse = (RequestSecurityTokenResponse)
baseResponse;
+ assertEquals("Unexpected context name", "testcontext",
parsedResponse.getContext());
+ assertEquals("Unexpected token type",
"http://example.org/specialToken", parsedResponse.getTokenType().toString());
+ assertFalse(parsedResponse.isForwardable());
+
+ // repeat the test, this time using a response collection instead of a single
response.
+ RequestSecurityTokenResponseCollection collection = new
RequestSecurityTokenResponseCollection();
+ collection.addRequestSecurityTokenResponse(response);
+ element =
objectFactory.createRequestSecurityTokenResponseCollection(collection.getDelegate());
+ source = new JAXBSource(this.context, element);
+
+ baseResponse = factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null response message", baseResponse);
+ assertTrue("Unexpected response message type", baseResponse instanceof
RequestSecurityTokenResponseCollection);
+ RequestSecurityTokenResponseCollection parsedCollection =
(RequestSecurityTokenResponseCollection) baseResponse;
+ assertNotNull("Unexpected null response list",
parsedCollection.getRequestSecurityTokenResponses());
+ assertEquals("Unexpected number of responses", 1,
parsedCollection.getRequestSecurityTokenResponses().size());
+
+ // repeat the tests, this time creating a source that contains the response message
directly (no JAXBElement).
+ source = new JAXBSource(this.context, response.getDelegate());
+ baseResponse = factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null response message", baseResponse);
+ assertTrue("Unexpected response message type", baseResponse instanceof
RequestSecurityTokenResponse);
+
+ source = new JAXBSource(this.context, collection.getDelegate());
+ baseResponse = factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null response message", baseResponse);
+ assertTrue("Unexpected response message type", baseResponse instanceof
RequestSecurityTokenResponseCollection);
+ }
+
+ /**
+ * <p>
+ * Tests the marshalling of a WS-Trust request.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testMarshallRequestSecurityToken() throws Exception
+ {
+ // create a request object.
+ RequestSecurityToken request = new RequestSecurityToken();
+ request.setContext("testcontext");
+ request.setTokenType(new
URI("http://example.org/specialToken"));
+ request.setRequestType(new
URI("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue"));
+
+ // use the factory to marshall the request.
+ WSTrustJAXBFactory factory = WSTrustJAXBFactory.getInstance();
+ Source source = factory.marshallRequestSecurityToken(request);
+ assertNotNull("Unexpected null source", source);
+ assertTrue("Unexpected source type", source instanceof JAXBSource);
+
+ // at this point we know that the parsing works, so parse the generated source and
compare to the original request.
+ BaseRequestSecurityToken baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null value for the parsed request",
baseRequest);
+ assertTrue("Unexpected parsed request type", baseRequest instanceof
RequestSecurityToken);
+ RequestSecurityToken parsedRequest = (RequestSecurityToken) baseRequest;
+ assertEquals("Unexpected context value", request.getContext(),
parsedRequest.getContext());
+ assertTrue("Unexpected token type",
request.getTokenType().equals(parsedRequest.getTokenType()));
+ assertTrue("Unexpected request type",
request.getRequestType().equals(parsedRequest.getRequestType()));
+
+ // repeat the test, now using a collection of requests.
+ RequestSecurityTokenCollection collection = new RequestSecurityTokenCollection();
+ collection.addRequestSecurityToken(request);
+ source = factory.marshallRequestSecurityToken(collection);
+ assertNotNull("Unexpected null source", source);
+ assertTrue("Unexpected source type", source instanceof JAXBSource);
+
+ baseRequest = factory.parseRequestSecurityToken(source);
+ assertNotNull("Unexpected null value for the parsed request",
baseRequest);
+ assertTrue("Unexpected parsed request type", baseRequest instanceof
RequestSecurityTokenCollection);
+ RequestSecurityTokenCollection parsedCollection = (RequestSecurityTokenCollection)
baseRequest;
+ assertNotNull("Unexpected null request list",
parsedCollection.getRequestSecurityTokens());
+ assertEquals("Unexpected number of requests", 1,
parsedCollection.getRequestSecurityTokens().size());
+ }
+
+ /**
+ * <p>
+ * Tests the marshalling of a WS-Trust response.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testMarshallRequestSecurityTokenResponse() throws Exception
+ {
+ // create a sample ws-trust response message.
+ RequestSecurityTokenResponse response = new RequestSecurityTokenResponse();
+ response.setContext("testcontext");
+ response.setTokenType(new
URI("http://example.org/specialToken"));
+ response.setForwardable(false);
+
+ // use the factory to marshall the response.
+ WSTrustJAXBFactory factory = WSTrustJAXBFactory.getInstance();
+ Source source = factory.marshallRequestSecurityTokenResponse(response);
+ assertNotNull("Unexpected null source", source);
+ assertTrue("Unexpected source type", source instanceof JAXBSource);
+
+ // at this point we know that the parsing works, so parse the generated source and
compare to the original response.
+ BaseRequestSecurityTokenResponse baseResponse =
factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null value for the parsed response",
baseResponse);
+ assertTrue("Unexpected parsed response type", baseResponse instanceof
RequestSecurityTokenResponse);
+ RequestSecurityTokenResponse parsedResponse = (RequestSecurityTokenResponse)
baseResponse;
+ assertEquals("Unexpected context value", response.getContext(),
parsedResponse.getContext());
+ assertTrue("Unexpected token type",
response.getTokenType().equals(parsedResponse.getTokenType()));
+ assertFalse(parsedResponse.isForwardable());
+
+ // repeat the test, now using a collection of responses.
+ RequestSecurityTokenResponseCollection collection = new
RequestSecurityTokenResponseCollection();
+ collection.addRequestSecurityTokenResponse(response);
+ source = factory.marshallRequestSecurityTokenResponse(collection);
+ assertNotNull("Unexpected null source", source);
+ assertTrue("Unexpected source type", source instanceof JAXBSource);
+
+ baseResponse = factory.parseRequestSecurityTokenResponse(source);
+ assertNotNull("Unexpected null value for the parsed response",
baseResponse);
+ assertTrue("Unexpected parsed request type", baseResponse instanceof
RequestSecurityTokenResponseCollection);
+ RequestSecurityTokenResponseCollection parsedCollection =
(RequestSecurityTokenResponseCollection) baseResponse;
+ assertNotNull("Unexpected null response list",
parsedCollection.getRequestSecurityTokenResponses());
+ assertEquals("Unexpected number of responses", 1,
parsedCollection.getRequestSecurityTokenResponses().size());
+ }
+}
Added:
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustServiceFactoryUnitTestCase.java
===================================================================
---
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustServiceFactoryUnitTestCase.java
(rev 0)
+++
identity-federation/trunk/jboss-identity-fed-api/src/test/java/org/jboss/test/identity/federation/api/wstrust/WSTrustServiceFactoryUnitTestCase.java 2009-04-28
14:58:51 UTC (rev 464)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2009, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.test.identity.federation.api.wstrust;
+
+import java.security.PrivilegedActionException;
+
+import junit.framework.TestCase;
+
+import org.jboss.identity.federation.api.wstrust.STSConfiguration;
+import org.jboss.identity.federation.api.wstrust.SecurityTokenProvider;
+import org.jboss.identity.federation.api.wstrust.StandardRequestHandler;
+import org.jboss.identity.federation.api.wstrust.WSTrustRequestHandler;
+import org.jboss.identity.federation.api.wstrust.WSTrustServiceFactory;
+
+/**
+ * <p>
+ * This {@code TestCase} tests the behavior of the {@code WSTrustServiceFactory} class.
+ * </p>
+ *
+ * @author <a href="mailto:sguilhen@redhat.com">Stefan Guilhen</a>
+ */
+public class WSTrustServiceFactoryUnitTestCase extends TestCase
+{
+
+ /**
+ * <p>
+ * Tests the creation of a {@code WSTrustRequestHandler} instance.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testCreateRequestHandler() throws Exception
+ {
+ STSConfiguration config = new MockSTSConfiguration();
+ WSTrustServiceFactory factory = WSTrustServiceFactory.getInstance();
+
+ // tests the creation of the request handler.
+ WSTrustRequestHandler handler = factory.createRequestHandler(
+ "org.jboss.identity.federation.api.wstrust.StandardRequestHandler",
config);
+ assertNotNull("Unexpected null request handler", handler);
+ assertTrue("Unexpected request handler type", handler instanceof
StandardRequestHandler);
+
+ // try to create an invalid instance of request handler.
+ try
+ {
+ factory.createRequestHandler("InvalidHandler", config);
+ fail("An exception should have been raised");
+ }
+ catch (RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof PrivilegedActionException);
+ }
+ }
+
+ /**
+ * <p>
+ * Tests the creation of {@code SecurityTokenProvider}s.
+ * </p>
+ *
+ * @throws Exception if an error occurs while running the test.
+ */
+ public void testCreateTokenProvider() throws Exception
+ {
+ WSTrustServiceFactory factory = WSTrustServiceFactory.getInstance();
+ SecurityTokenProvider provider = factory
+
.createTokenProvider("org.jboss.test.identity.federation.api.wstrust.StandardTokenProvider");
+ assertNotNull("Unexpected null token provider", provider);
+ assertTrue("Unexpected token provider type", provider instanceof
StandardTokenProvider);
+ provider = factory
+
.createTokenProvider("org.jboss.test.identity.federation.api.wstrust.SpecialTokenProvider");
+ assertNotNull("Unexpected null token provider", provider);
+ assertTrue("Unexpected token provider type", provider instanceof
SpecialTokenProvider);
+
+ // try to create an invalid token provider.
+ try
+ {
+ factory.createTokenProvider("InvalidTokenProvider");
+ fail("An exception should have been raised");
+ }
+ catch(RuntimeException re)
+ {
+ assertTrue(re.getCause() instanceof PrivilegedActionException);
+ }
+
+ }
+}