cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: More prototyping related to complex claims
Date Wed, 17 Feb 2016 22:57:33 GMT
Repository: cxf
Updated Branches:
  refs/heads/master d51f4ec91 -> fbcb69296


More prototyping related to complex claims


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

Branch: refs/heads/master
Commit: fbcb69296363a1ac1a18b9d7c21ae8b37d2ce506
Parents: d51f4ec
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Feb 17 22:57:18 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Feb 17 22:57:18 2016 +0000

----------------------------------------------------------------------
 .../security/oidc/common/AbstractUserInfo.java  | 66 +++++++++++++-------
 .../security/oidc/common/AggregatedClaims.java  | 10 +--
 .../oidc/common/DistributedClaimSource.java     | 41 ++++++++++++
 .../security/oidc/common/DistributedClaims.java | 21 ++-----
 4 files changed, 97 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/fbcb6929/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AbstractUserInfo.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AbstractUserInfo.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AbstractUserInfo.java
index 18970f0..5ed5b6e 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AbstractUserInfo.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AbstractUserInfo.java
@@ -24,7 +24,6 @@ import java.util.Map;
 
 import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.rs.security.jose.jwt.JwtClaims;
-import org.apache.cxf.rs.security.jose.jwt.JwtException;
 import org.apache.cxf.rs.security.oidc.utils.OidcUtils;
 
 public abstract class AbstractUserInfo extends JwtClaims {
@@ -183,42 +182,67 @@ public abstract class AbstractUserInfo extends JwtClaims {
     
     public void setAggregatedClaims(AggregatedClaims claims) {
         setProperty(OidcUtils.CLAIM_NAMES_PROPERTY, claims.getClaimNames());
-        setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, 
-            Collections.singletonMap(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY, claims.getJwtClaims()));
+        Map<String, Map<String, String>> sources = new LinkedHashMap<String,
Map<String, String>>();
+        for (Map.Entry<String, String> entry : claims.getClaimNames().entrySet()) {
+            String source = entry.getValue();
+            String jwt = claims.getClaimSources().get(source); 
+            sources.put(source, 
+                        Collections.singletonMap(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY, jwt));
+            
+        }
+        setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, sources);
     }
     public AggregatedClaims getAggregatedClaims() {
-        Map<String, Object> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
-        Map<String, Object> sources = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_SOURCES_PROPERTY));
-        if (names == null || sources == null || !sources.containsKey(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY))
{
+        Map<String, String> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
+        Map<String, Map<String, String>> sources = 
+            CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_SOURCES_PROPERTY));
+        if (names == null || sources == null) {
             return null;
         }
         AggregatedClaims claims = new AggregatedClaims();
-        claims.setClaimNames(CastUtils.cast(names));
-        claims.setJwtClaims((String)sources.get(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY));
+        claims.setClaimNames(names);
+        Map<String, String> sourcesMap = new LinkedHashMap<String, String>();
+        for (Map.Entry<String, Map<String, String>> entry : sources.entrySet())
{
+            String source = entry.getKey();
+            String jwt = entry.getValue().values().iterator().next(); 
+            sourcesMap.put(source, jwt);
+        }
+        claims.setClaimSources(sourcesMap);
         return claims;
     }
     public void setDistributedClaims(DistributedClaims claims) {
-        if (claims.getEndpoint() == null) {
-            throw new JwtException();
-        }
-        Map<String, String> sources = new LinkedHashMap<String, String>();
         setProperty(OidcUtils.CLAIM_NAMES_PROPERTY, claims.getClaimNames());
-        sources.put(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY, claims.getEndpoint());
-        if (claims.getAccessToken() != null) {
-            sources.put(OidcUtils.TOKEN_CLAIM_SOURCE_PROPERTY, claims.getAccessToken());
+        Map<String, Map<String, String>> sources = new LinkedHashMap<String,
Map<String, String>>();
+        for (Map.Entry<String, String> entry : claims.getClaimNames().entrySet()) {
+            String source = entry.getValue();
+            DistributedClaimSource distSource = claims.getClaimSources().get(source); 
+            Map<String, String> mapSource = new LinkedHashMap<String, String>();
+            mapSource.put(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY, distSource.getEndpoint());
+            if (distSource.getAccessToken() != null) {
+                mapSource.put(OidcUtils.TOKEN_CLAIM_SOURCE_PROPERTY, distSource.getAccessToken());
+            }
+            sources.put(source, mapSource);
         }
         setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, sources);
     }
     public DistributedClaims getDistributedClaims() {
-        Map<String, Object> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
-        Map<String, Object> sources = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_SOURCES_PROPERTY));
-        if (names == null || sources == null || !sources.containsKey(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY))
{
+        Map<String, String> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
+        Map<String, Map<String, String>> sources = 
+            CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_SOURCES_PROPERTY));
+        if (names == null || sources == null) {
             return null;
         }
         DistributedClaims claims = new DistributedClaims();
-        claims.setClaimNames(CastUtils.cast(names));
-        claims.setEndpoint((String)sources.get(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY));
-        claims.setAccessToken((String)sources.get(OidcUtils.TOKEN_CLAIM_SOURCE_PROPERTY));
+        claims.setClaimNames(names);
+        Map<String, DistributedClaimSource> sourcesMap = new LinkedHashMap<String,
DistributedClaimSource>();
+        for (Map.Entry<String, Map<String, String>> entry : sources.entrySet())
{
+            String source = entry.getKey();
+            DistributedClaimSource distSource = new DistributedClaimSource();
+            distSource.setEndpoint(entry.getValue().get(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY));

+            distSource.setAccessToken(entry.getValue().get(OidcUtils.TOKEN_CLAIM_SOURCE_PROPERTY));
+            sourcesMap.put(source, distSource);
+        }
+        claims.setClaimSources(sourcesMap);
         return claims;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/fbcb6929/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AggregatedClaims.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AggregatedClaims.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AggregatedClaims.java
index 38c9fa9..fb1806b 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AggregatedClaims.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/AggregatedClaims.java
@@ -22,7 +22,7 @@ import java.util.Map;
 
 public class AggregatedClaims {
     private Map<String, String> claimNames;
-    private String jwtClaims;
+    private Map<String, String> claimSources;
     
     public Map<String, String> getClaimNames() {
         return claimNames;
@@ -32,11 +32,11 @@ public class AggregatedClaims {
         this.claimNames = claimNames;
     }
 
-    public String getJwtClaims() {
-        return jwtClaims;
+    public Map<String, String> getClaimSources() {
+        return claimSources;
     }
 
-    public void setJwtClaims(String jwtClaims) {
-        this.jwtClaims = jwtClaims;
+    public void setClaimSources(Map<String, String> claimSources) {
+        this.claimSources = claimSources;
     }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/fbcb6929/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaimSource.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaimSource.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaimSource.java
new file mode 100644
index 0000000..d0f1fc2
--- /dev/null
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaimSource.java
@@ -0,0 +1,41 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oidc.common;
+
+public class DistributedClaimSource {
+    private String endpoint;
+    private String accessToken;
+    
+    public String getEndpoint() {
+        return endpoint;
+    }
+
+    public void setEndpoint(String endpoint) {
+        this.endpoint = endpoint;
+    }
+
+    public String getAccessToken() {
+        return accessToken;
+    }
+
+    public void setAccessToken(String accessToken) {
+        this.accessToken = accessToken;
+    }
+    
+}

http://git-wip-us.apache.org/repos/asf/cxf/blob/fbcb6929/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaims.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaims.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaims.java
index 07ae9c6..d77afe8 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaims.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/common/DistributedClaims.java
@@ -22,8 +22,7 @@ import java.util.Map;
 
 public class DistributedClaims {
     private Map<String, String> claimNames;
-    private String endpoint;
-    private String accessToken;
+    private Map<String, DistributedClaimSource> claimSources;
     public Map<String, String> getClaimNames() {
         return claimNames;
     }
@@ -32,20 +31,12 @@ public class DistributedClaims {
         this.claimNames = claimNames;
     }
 
-    public String getEndpoint() {
-        return endpoint;
+    public Map<String, DistributedClaimSource> getClaimSources() {
+        return claimSources;
     }
 
-    public void setEndpoint(String endpoint) {
-        this.endpoint = endpoint;
+    public void setClaimSources(Map<String, DistributedClaimSource> claimSources) {
+        this.claimSources = claimSources;
     }
-
-    public String getAccessToken() {
-        return accessToken;
-    }
-
-    public void setAccessToken(String accessToken) {
-        this.accessToken = accessToken;
-    }
-    
+       
 }


Mime
View raw message