cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From owu...@apache.org
Subject svn commit: r1304223 - in /cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider: CustomAuthenticationProvider.java SAMLProviderCustomTest.java
Date Fri, 23 Mar 2012 08:16:59 GMT
Author: owulff
Date: Fri Mar 23 08:16:59 2012
New Revision: 1304223

URL: http://svn.apache.org/viewvc?rev=1304223&view=rev
Log:
Testcase added for AuthenticationMethod in SAML tokens - requires WSS4J 1.6.6

Modified:
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/CustomAuthenticationProvider.java
    cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SAMLProviderCustomTest.java

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/CustomAuthenticationProvider.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/CustomAuthenticationProvider.java?rev=1304223&r1=1304222&r2=1304223&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/CustomAuthenticationProvider.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/CustomAuthenticationProvider.java
Fri Mar 23 08:16:59 2012
@@ -18,8 +18,11 @@
  */
 package org.apache.cxf.sts.token.provider;
 
+import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.saml.ext.bean.AuthenticationStatementBean;
 import org.apache.ws.security.saml.ext.bean.SubjectLocalityBean;
+import org.apache.ws.security.saml.ext.builder.SAML1Constants;
+import org.apache.ws.security.saml.ext.builder.SAML2Constants;
 
 /**
  * A custom AuthenticationStatementProvider implementation for use in the tests.
@@ -35,9 +38,13 @@ public class CustomAuthenticationProvide
         SubjectLocalityBean subjectLocality = new SubjectLocalityBean();
         subjectLocality.setIpAddress("127.0.0.1");
         authBean.setSubjectLocality(subjectLocality);
-
-        authBean.setAuthenticationMethod("Password");
         
+        if (WSConstants.WSS_SAML_TOKEN_TYPE.equals(
+                providerParameters.getTokenRequirements().getTokenType())) {
+            authBean.setAuthenticationMethod(SAML1Constants.AUTH_METHOD_X509);
+        } else {
+            authBean.setAuthenticationMethod(SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509);
+        }
         return authBean;
     }
     

Modified: cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SAMLProviderCustomTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SAMLProviderCustomTest.java?rev=1304223&r1=1304222&r2=1304223&view=diff
==============================================================================
--- cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SAMLProviderCustomTest.java
(original)
+++ cxf/trunk/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/provider/SAMLProviderCustomTest.java
Fri Mar 23 08:16:59 2012
@@ -40,6 +40,7 @@ import org.apache.ws.security.WSSecurity
 import org.apache.ws.security.components.crypto.Crypto;
 import org.apache.ws.security.components.crypto.CryptoFactory;
 import org.apache.ws.security.saml.ext.builder.SAML1Constants;
+import org.apache.ws.security.saml.ext.builder.SAML2Constants;
 import org.apache.ws.security.util.DOM2Writer;
 
 /**
@@ -98,6 +99,35 @@ public class SAMLProviderCustomTest exte
         assertTrue(tokenString.contains(providerResponse.getTokenId()));
         assertFalse(tokenString.contains("AttributeStatement"));
         assertTrue(tokenString.contains("AuthnStatement"));
+        assertTrue(tokenString.contains(SAML2Constants.AUTH_CONTEXT_CLASS_REF_X509));
+        assertTrue(tokenString.contains("alice"));
+    }
+    
+    /**
+     * Create a custom Saml1 Authentication Assertion.
+     */
+    @org.junit.Test
+    public void testCustomSaml1AuthenticationAssertion() throws Exception {
+        TokenProvider samlTokenProvider = new SAMLTokenProvider();
+        TokenProviderParameters providerParameters = 
+            createProviderParameters(WSConstants.WSS_SAML_TOKEN_TYPE, STSConstants.BEARER_KEY_KEYTYPE);
+        
+        List<AuthenticationStatementProvider> customProviderList = 
+            new ArrayList<AuthenticationStatementProvider>();
+        customProviderList.add(new CustomAuthenticationProvider());
+        ((SAMLTokenProvider)samlTokenProvider).setAuthenticationStatementProviders(customProviderList);
+        
+        assertTrue(samlTokenProvider.canHandleToken(WSConstants.WSS_SAML_TOKEN_TYPE));
+        TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
+        assertTrue(providerResponse != null);
+        assertTrue(providerResponse.getToken() != null && providerResponse.getTokenId()
!= null);
+        
+        Element token = providerResponse.getToken();
+        String tokenString = DOM2Writer.nodeToString(token);
+        assertTrue(tokenString.contains(providerResponse.getTokenId()));
+        assertFalse(tokenString.contains("AttributeStatement"));
+        assertTrue(tokenString.contains("AuthenticationStatement"));
+        assertTrue(tokenString.contains(SAML1Constants.AUTH_METHOD_X509));
         assertTrue(tokenString.contains("alice"));
     }
     



Mime
View raw message