cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject cxf git commit: CXF-6044 - Obsolet Testing Method in LDAPClaimsTest
Date Fri, 24 Mar 2017 10:51:41 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 4824bfe59 -> a719adcca


CXF-6044 - Obsolet Testing Method in LDAPClaimsTest


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

Branch: refs/heads/master
Commit: a719adccae8500f2d7e7140a9f4cd26e20775818
Parents: 4824bfe
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Fri Mar 24 10:51:24 2017 +0000
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Fri Mar 24 10:51:24 2017 +0000

----------------------------------------------------------------------
 .../systest/kerberos/ldap/LDAPClaimsTest.java   | 61 +++++++++++---------
 1 file changed, 33 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a719adcc/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
----------------------------------------------------------------------
diff --git a/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
b/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
index 254da3c..0c0a37e 100644
--- a/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
+++ b/systests/kerberos/src/test/java/org/apache/cxf/systest/kerberos/ldap/LDAPClaimsTest.java
@@ -30,6 +30,7 @@ import java.nio.file.Path;
 import java.security.cert.CertificateFactory;
 import java.security.cert.X509Certificate;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
@@ -38,6 +39,7 @@ import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.rt.security.claims.Claim;
 import org.apache.cxf.rt.security.claims.ClaimCollection;
 import org.apache.cxf.sts.claims.ClaimTypes;
+import org.apache.cxf.sts.claims.ClaimsManager;
 import org.apache.cxf.sts.claims.ClaimsParameters;
 import org.apache.cxf.sts.claims.LdapClaimsHandler;
 import org.apache.cxf.sts.claims.LdapGroupClaimsHandler;
@@ -131,6 +133,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     @org.junit.Test
     public void testRetrieveClaims() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("claimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -145,7 +149,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(
                       "Retrieved number of claims [" + retrievedClaims.size()
@@ -165,6 +169,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     @org.junit.Test
     public void testRetrieveClaimsUsingLDAPLookup() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         ClaimCollection requestedClaims = createRequestClaimCollection();
 
@@ -176,7 +182,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal("cn=alice,ou=users,dc=example,dc=com"));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(
                       "Retrieved number of claims [" + retrievedClaims.size()
@@ -196,6 +202,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     @org.junit.Test
     public void testMultiUserBaseDNs() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandlerMultipleUserBaseDNs");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("claimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -213,7 +221,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(
                       "Retrieved number of claims [" + retrievedClaims.size()
@@ -231,7 +239,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
 
         // Second user
         params.setPrincipal(new CustomTokenPrincipal(otherUser));
-        retrievedClaims = claimsHandler.retrieveClaimValues(requestedClaims, params);
+        retrievedClaims = claimsManager.retrieveClaimValues(requestedClaims, params);
 
         expectedClaims.add(ClaimTypes.FIRSTNAME);
         expectedClaims.add(ClaimTypes.LASTNAME);
@@ -255,6 +263,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     @org.junit.Test(expected = STSException.class)
     public void testRetrieveClaimsWithUnsupportedMandatoryClaimType() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("claimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -268,29 +278,14 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
 
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
-        ProcessedClaimCollection processedClaim =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
-
-        for (Claim requestedClaim : requestedClaims) {
-            URI claimType = requestedClaim.getClaimType();
-            boolean found = false;
-            if (!requestedClaim.isOptional()) {
-                for (ProcessedClaim c : processedClaim) {
-                    if (c.getClaimType().equals(claimType)) {
-                        found = true;
-                        break;
-                    }
-                }
-                if (!found) {
-                    throw new STSException("Mandatory claim '" + claim.getClaimType() + "'
not found");
-                }
-            }
-        }
+        claimsManager.retrieveClaimValues(requestedClaims, params);
     }
 
     @org.junit.Test
     public void testRetrieveClaimsWithUnsupportedOptionalClaimType() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("claimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -311,7 +306,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(
                       "Retrieved number of claims [" + retrievedClaims.size()
@@ -355,6 +350,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     @org.junit.Test
     public void testRetrieveBinaryClaims() throws Exception {
         LdapClaimsHandler claimsHandler = (LdapClaimsHandler)appContext.getBean("testClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("binaryClaimUser");
         Assert.assertNotNull(user, "Property 'binaryClaimUser' not configured");
@@ -375,7 +372,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(
                       "Retrieved number of claims [" + retrievedClaims.size()
@@ -402,6 +399,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     public void testRetrieveRolesForAlice() throws Exception {
         LdapGroupClaimsHandler claimsHandler =
             (LdapGroupClaimsHandler)appContext.getBean("testGroupClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("claimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -415,7 +414,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(retrievedClaims.size() == 1);
         Assert.assertTrue(retrievedClaims.get(0).getClaimType().equals(roleURI));
@@ -426,6 +425,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     public void testRetrieveRolesForAliceUsingLDAPLookup() throws Exception {
         LdapGroupClaimsHandler claimsHandler =
             (LdapGroupClaimsHandler)appContext.getBean("testGroupClaimsHandler");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         ClaimCollection requestedClaims = new ClaimCollection();
         Claim claim = new Claim();
@@ -436,7 +437,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal("cn=alice,ou=users,dc=example,dc=com"));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(retrievedClaims.size() == 1);
         Assert.assertTrue(retrievedClaims.get(0).getClaimType().equals(roleURI));
@@ -447,6 +448,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     public void testRetrieveRolesForBob() throws Exception {
         LdapGroupClaimsHandler claimsHandler =
             (LdapGroupClaimsHandler)appContext.getBean("testGroupClaimsHandlerOtherUsers");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("otherClaimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -460,7 +463,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(retrievedClaims.size() == 1);
         Assert.assertTrue(retrievedClaims.get(0).getClaimType().equals(roleURI));
@@ -471,6 +474,8 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
     public void testRetrieveRolesForBobInBusinessCategoryWidgets() throws Exception {
         LdapGroupClaimsHandler claimsHandler =
             (LdapGroupClaimsHandler)appContext.getBean("testGroupClaimsHandlerFilter");
+        ClaimsManager claimsManager = new ClaimsManager();
+        claimsManager.setClaimHandlers(Collections.singletonList(claimsHandler));
 
         String user = props.getProperty("otherClaimUser");
         Assert.assertNotNull(user, "Property 'claimUser' not configured");
@@ -484,7 +489,7 @@ public class LDAPClaimsTest extends AbstractLdapTestUnit {
         ClaimsParameters params = new ClaimsParameters();
         params.setPrincipal(new CustomTokenPrincipal(user));
         ProcessedClaimCollection retrievedClaims =
-            claimsHandler.retrieveClaimValues(requestedClaims, params);
+            claimsManager.retrieveClaimValues(requestedClaims, params);
 
         Assert.assertTrue(retrievedClaims.size() == 1);
         Assert.assertTrue(retrievedClaims.get(0).getClaimType().equals(roleURI));


Mime
View raw message