You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by jb...@apache.org on 2014/10/10 20:48:29 UTC

[2/2] git commit: [CXF-5927] Improving ClaimUtils

[CXF-5927] Improving ClaimUtils


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

Branch: refs/heads/master
Commit: 43c65b07658b8041f6689d16a34ff98132b8a424
Parents: a4222c9
Author: Jan Bernhardt <jb...@talend.com>
Authored: Fri Oct 10 20:45:54 2014 +0200
Committer: Jan Bernhardt <jb...@talend.com>
Committed: Fri Oct 10 20:46:34 2014 +0200

----------------------------------------------------------------------
 .../cxf/sts/claims/mapper/ClaimUtils.java       | 41 ++++++++++++++++++++
 1 file changed, 41 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/43c65b07/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/ClaimUtils.java
----------------------------------------------------------------------
diff --git a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/ClaimUtils.java b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/ClaimUtils.java
index 61c2284..2ff19c1 100644
--- a/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/ClaimUtils.java
+++ b/services/sts/sts-core/src/main/java/org/apache/cxf/sts/claims/mapper/ClaimUtils.java
@@ -22,8 +22,10 @@ package org.apache.cxf.sts.claims.mapper;
 import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.StringTokenizer;
 
 import org.apache.cxf.sts.claims.ProcessedClaim;
@@ -415,4 +417,43 @@ public class ClaimUtils {
         }
         return resultClaim;
     }
+    
+    /**
+     * This function removes duplicated values.
+     * 
+     * @param processedClaim claim containing multi-values of which some might be duplicated
+     * @return Returns a clone of the provided claim containing only distinct values
+     */
+    public ProcessedClaim distinctValues(ProcessedClaim processedClaim) {
+        ProcessedClaim resultClaim = null;
+        if (processedClaim != null) {
+            resultClaim = processedClaim.clone();
+            if (resultClaim.getValues() != null) {
+                List<Object> oldValues = resultClaim.getValues();
+                Set<Object> distincValues = new LinkedHashSet<Object>(oldValues);
+                resultClaim.getValues().clear();
+                resultClaim.getValues().addAll(distincValues);
+            }
+        }
+        return resultClaim;
+    }
+    
+    /**
+     * Removes Claims without values.
+     * 
+     * @param processedClaims Collection of claims with and/or without values
+     * @return Returns a collection of claims which contain values only
+     */
+    public ProcessedClaimCollection removeEmptyClaims(ProcessedClaimCollection processedClaims) {
+        ProcessedClaimCollection resultClaimCollection = null;
+        if (processedClaims != null) {
+            resultClaimCollection = new ProcessedClaimCollection();
+            for (ProcessedClaim c : processedClaims) {
+                if (c.getValues() != null && c.getValues().size() > 0) {
+                    resultClaimCollection.add(c);
+                }
+            }
+        }
+        return resultClaimCollection;
+    }
 }