cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [cxf] 01/03: Adding a test to make sure the principal from a SAML Assertion includes comments if they are present in the assertion
Date Wed, 28 Feb 2018 13:58:49 GMT
This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch 3.1.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit cb8d5f0663e0249188c4548088ec5ab13befa1e9
Author: Colm O hEigeartaigh <coheigea@apache.org>
AuthorDate: Wed Feb 28 12:12:47 2018 +0000

    Adding a test to make sure the principal from a SAML Assertion includes comments if they
are present in the assertion
    
    (cherry picked from commit 6412142e16cf113704ed9983d69a2443dea5ea56)
    
    # Conflicts:
    #	services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SAMLTokenValidatorTest.java
---
 .../token/validator/SAMLTokenValidatorTest.java    | 53 +++++++++++++++++++---
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SAMLTokenValidatorTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SAMLTokenValidatorTest.java
index f39595b..d3c2086 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SAMLTokenValidatorTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/token/validator/SAMLTokenValidatorTest.java
@@ -472,7 +472,40 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
         assertTrue(validatorResponse.getToken() != null);
         assertTrue(validatorResponse.getToken().getState() != STATE.VALID);
     }
-    
+
+    @org.junit.Test
+    public void testSAML2SubjectWithComment() throws Exception {
+        TokenValidator samlTokenValidator = new SAMLTokenValidator();
+        TokenValidatorParameters validatorParameters = createValidatorParameters();
+        TokenRequirements tokenRequirements = validatorParameters.getTokenRequirements();
+
+        // Create a ValidateTarget consisting of a SAML Assertion
+        Crypto crypto = CryptoFactory.getInstance(getEncryptionProperties());
+        CallbackHandler callbackHandler = new PasswordCallbackHandler();
+        String principalName = "alice<!---->o=example.com";
+        Element samlToken =
+            createSAMLAssertion(principalName, WSS4JConstants.WSS_SAML2_TOKEN_TYPE, crypto,
+                                "mystskey", callbackHandler);
+        Document doc = samlToken.getOwnerDocument();
+        samlToken = (Element)doc.appendChild(samlToken);
+
+        ReceivedToken validateTarget = new ReceivedToken(samlToken);
+        tokenRequirements.setValidateTarget(validateTarget);
+        validatorParameters.setToken(validateTarget);
+
+        assertTrue(samlTokenValidator.canHandleToken(validateTarget));
+
+        TokenValidatorResponse validatorResponse =
+            samlTokenValidator.validateToken(validatorParameters);
+        assertTrue(validatorResponse != null);
+        assertTrue(validatorResponse.getToken() != null);
+        assertTrue(validatorResponse.getToken().getState() == STATE.VALID);
+
+        Principal principal = validatorResponse.getPrincipal();
+        assertTrue(principal != null && principal.getName() != null);
+        assertEquals(principalName, principal.getName());
+    }
+
     private TokenValidatorParameters createValidatorParameters() throws WSSecurityException
{
         TokenValidatorParameters parameters = new TokenValidatorParameters();
         
@@ -507,10 +540,16 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
     private Element createSAMLAssertion(
         String tokenType, Crypto crypto, String signatureUsername, CallbackHandler callbackHandler
     ) throws WSSecurityException {
+        return createSAMLAssertion("alice", tokenType, crypto, signatureUsername, callbackHandler);
+    }
+
+    private Element createSAMLAssertion(
+        String subjectName, String tokenType, Crypto crypto, String signatureUsername, CallbackHandler
callbackHandler
+    ) throws WSSecurityException {
         TokenProvider samlTokenProvider = new SAMLTokenProvider();
         TokenProviderParameters providerParameters = 
             createProviderParameters(
-                tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler
+                 subjectName, tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername,
callbackHandler
             );
         TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
         assertTrue(providerResponse != null);
@@ -526,7 +565,7 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
         TokenProvider samlTokenProvider = new SAMLTokenProvider();
         TokenProviderParameters providerParameters = 
             createProviderParameters(
-                tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler
+                "alice", tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername,
callbackHandler
             );
         
         ClaimsManager claimsManager = new ClaimsManager();
@@ -557,7 +596,7 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
         samlTokenProvider.setAttributeStatementProviders(Collections.singletonList(statementProvider));
         TokenProviderParameters providerParameters = 
             createProviderParameters(
-                tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername, callbackHandler
+                "alice", tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername,
callbackHandler
             );
         TokenProviderResponse providerResponse = samlTokenProvider.createToken(providerParameters);
         assertTrue(providerResponse != null);
@@ -576,7 +615,7 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
         samlTokenProvider.setConditionsProvider(conditionsProvider);
         TokenProviderParameters providerParameters = 
             createProviderParameters(
-                    tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername,
callbackHandler
+                "alice", tokenType, STSConstants.BEARER_KEY_KEYTYPE, crypto, signatureUsername,
callbackHandler
             );
 
         if (ttlMs != 0) {
@@ -600,7 +639,7 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
     }    
     
     private TokenProviderParameters createProviderParameters(
-        String tokenType, String keyType, Crypto crypto, 
+        String subjectName, String tokenType, String keyType, Crypto crypto,
         String signatureUsername, CallbackHandler callbackHandler
     ) throws WSSecurityException {
         TokenProviderParameters parameters = new TokenProviderParameters();
@@ -613,7 +652,7 @@ public class SAMLTokenValidatorTest extends org.junit.Assert {
         keyRequirements.setKeyType(keyType);
         parameters.setKeyRequirements(keyRequirements);
 
-        parameters.setPrincipal(new CustomTokenPrincipal("alice"));
+        parameters.setPrincipal(new CustomTokenPrincipal(subjectName));
         // Mock up message context
         MessageImpl msg = new MessageImpl();
         WrappedMessageContext msgCtx = new WrappedMessageContext(msg);

-- 
To stop receiving notification emails like this one, please contact
coheigea@apache.org.

Mime
View raw message