cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject [1/6] cxf git commit: Minor test change
Date Wed, 10 Feb 2016 17:24:11 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 5f038c239 -> c857aa32e


Minor test change


Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/064fc778
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/064fc778
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/064fc778

Branch: refs/heads/master
Commit: 064fc778ed813902358456c0d3ecabd6ce457e99
Parents: 456ed68
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Feb 10 15:00:37 2016 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Feb 10 17:22:02 2016 +0000

----------------------------------------------------------------------
 .../sts/operation/IssueJWTRealmUnitTest.java    | 34 ++++++++++++--------
 .../cxf/sts/operation/IssueJWTUnitTest.java     | 10 ++++++
 2 files changed, 31 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/064fc778/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTRealmUnitTest.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTRealmUnitTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTRealmUnitTest.java
index 5c009a1..34ee3b3 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTRealmUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTRealmUnitTest.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.sts.operation;
 
 import java.security.Principal;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -35,6 +36,7 @@ import org.w3c.dom.Element;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
 import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer;
 import org.apache.cxf.rs.security.jose.jwt.JwtConstants;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
@@ -56,6 +58,7 @@ import org.apache.cxf.ws.security.sts.provider.model.RequestSecurityTokenType;
 import org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.common.crypto.CryptoType;
 import org.apache.wss4j.common.principal.CustomTokenPrincipal;
 import org.apache.wss4j.dom.WSConstants;
 import org.junit.Assert;
@@ -142,9 +145,7 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
         }
         
         assertNotNull(token);
-        JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token.getTextContent());
-        JwtToken jwt = jwtConsumer.getJwtToken();
-        Assert.assertEquals("A-Issuer", jwt.getClaim(JwtConstants.CLAIM_ISSUER));
+        validateToken(token.getTextContent(), "A-Issuer", stsProperties.getSignatureUsername(),
crypto);
     }
     
     /**
@@ -217,9 +218,7 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
         }
         
         assertNotNull(token);
-        JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token.getTextContent());
-        JwtToken jwt = jwtConsumer.getJwtToken();
-        Assert.assertEquals("B-Issuer", jwt.getClaim(JwtConstants.CLAIM_ISSUER));
+        validateToken(token.getTextContent(), "B-Issuer", stsProperties.getSignatureUsername(),
crypto);
     }
     
     /**
@@ -292,9 +291,7 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
         }
         
         assertNotNull(token);
-        JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token.getTextContent());
-        JwtToken jwt = jwtConsumer.getJwtToken();
-        Assert.assertEquals("STS", jwt.getClaim(JwtConstants.CLAIM_ISSUER));
+        validateToken(token.getTextContent(), "STS", stsProperties.getSignatureUsername(),
crypto);
     }
     
     
@@ -374,7 +371,7 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
             response.getRequestSecurityTokenResponse();
         assertTrue(!securityTokenResponse.isEmpty());
         
-     // Test the generated token.
+        // Test the generated token.
         Element token = null;
         for (Object tokenObject : securityTokenResponse.get(0).getAny()) {
             if (tokenObject instanceof JAXBElement<?>
@@ -387,9 +384,7 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
         }
         
         assertNotNull(token);
-        JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token.getTextContent());
-        JwtToken jwt = jwtConsumer.getJwtToken();
-        Assert.assertEquals("B-Issuer", jwt.getClaim(JwtConstants.CLAIM_ISSUER));
+        validateToken(token.getTextContent(), "B-Issuer", stsProperties.getSignatureUsername(),
crypto);
     }
     
     /**
@@ -407,6 +402,19 @@ public class IssueJWTRealmUnitTest extends org.junit.Assert {
         return realms;
     }
     
+    private void validateToken(String token, String issuer, String sigUsername, Crypto sigCrypto)
throws Exception {
+        JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token);
+        JwtToken jwt = jwtConsumer.getJwtToken();
+        Assert.assertEquals(issuer, jwt.getClaim(JwtConstants.CLAIM_ISSUER));
+        
+        CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
+        cryptoType.setAlias(sigUsername);
+        X509Certificate[] certs = sigCrypto.getX509Certificates(cryptoType);
+        assertNotNull(certs);
+        
+        assertTrue(jwtConsumer.verifySignatureWith(certs[0], SignatureAlgorithm.RS256));
+    }
+    
     /*
      * Create a security context object
      */

http://git-wip-us.apache.org/repos/asf/cxf/blob/064fc778/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTUnitTest.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTUnitTest.java
b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTUnitTest.java
index 2f29d3f..eacf6bd 100644
--- a/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTUnitTest.java
+++ b/services/sts/sts-core/src/test/java/org/apache/cxf/sts/operation/IssueJWTUnitTest.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.sts.operation;
 
 import java.security.Principal;
+import java.security.cert.X509Certificate;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -33,6 +34,7 @@ import org.w3c.dom.Element;
 import org.apache.cxf.helpers.DOMUtils;
 import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.MessageImpl;
+import org.apache.cxf.rs.security.jose.jwa.SignatureAlgorithm;
 import org.apache.cxf.rs.security.jose.jws.JwsJwtCompactConsumer;
 import org.apache.cxf.rs.security.jose.jwt.JwtConstants;
 import org.apache.cxf.rs.security.jose.jwt.JwtToken;
@@ -54,6 +56,7 @@ import org.apache.cxf.ws.security.sts.provider.model.RequestedSecurityTokenType;
 import org.apache.cxf.ws.security.tokenstore.TokenStore;
 import org.apache.wss4j.common.crypto.Crypto;
 import org.apache.wss4j.common.crypto.CryptoFactory;
+import org.apache.wss4j.common.crypto.CryptoType;
 import org.apache.wss4j.common.principal.CustomTokenPrincipal;
 import org.apache.wss4j.dom.WSConstants;
 import org.junit.Assert;
@@ -144,6 +147,13 @@ public class IssueJWTUnitTest extends org.junit.Assert {
         JwsJwtCompactConsumer jwtConsumer = new JwsJwtCompactConsumer(token.getTextContent());
         JwtToken jwt = jwtConsumer.getJwtToken();
         Assert.assertEquals("alice", jwt.getClaim(JwtConstants.CLAIM_SUBJECT));
+        
+        CryptoType cryptoType = new CryptoType(CryptoType.TYPE.ALIAS);
+        cryptoType.setAlias(stsProperties.getSignatureUsername());
+        X509Certificate[] certs = crypto.getX509Certificates(cryptoType);
+        assertNotNull(certs);
+        
+        assertTrue(jwtConsumer.verifySignatureWith(certs[0], SignatureAlgorithm.RS256));
     }
     
     /*


Mime
View raw message