You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2016/06/23 16:47:45 UTC
cxf git commit: Some tweaking around the way advanced IdToken claims
are dealt with
Repository: cxf
Updated Branches:
refs/heads/master 026a8efe4 -> cc950cf4f
Some tweaking around the way advanced IdToken claims are dealt with
Project: http://git-wip-us.apache.org/repos/asf/cxf/repo
Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/cc950cf4
Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/cc950cf4
Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/cc950cf4
Branch: refs/heads/master
Commit: cc950cf4f0bbe3758f6110af9a1e7e889f1ce61e
Parents: 026a8ef
Author: Sergey Beryozkin <sb...@gmail.com>
Authored: Thu Jun 23 17:46:04 2016 +0100
Committer: Sergey Beryozkin <sb...@gmail.com>
Committed: Thu Jun 23 17:46:04 2016 +0100
----------------------------------------------------------------------
.../security/oidc/common/AbstractUserInfo.java | 62 +++++++++++++++-----
1 file changed, 46 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cxf/blob/cc950cf4/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 f63aaaa..a55ee43 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
@@ -181,7 +181,7 @@ public abstract class AbstractUserInfo extends JwtClaims {
}
public void setAggregatedClaims(AggregatedClaims claims) {
- setProperty(OidcUtils.CLAIM_NAMES_PROPERTY, claims.getClaimNames());
+ setAddClaimNames(claims.getClaimNames());
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();
@@ -190,7 +190,24 @@ public abstract class AbstractUserInfo extends JwtClaims {
Collections.singletonMap(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY, jwt));
}
- setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, sources);
+ setAddClaimSources(sources);
+ }
+ private void setAddClaimSources(Map<String, Map<String, String>> newSources) {
+ Map<String, Map<String, String>> sources =
+ CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_SOURCES_PROPERTY));
+ if (sources == null) {
+ setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, sources);
+ } else {
+ sources.putAll(newSources);
+ }
+ }
+ private void setAddClaimNames(Map<String, String> claimNames) {
+ Map<String, String> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
+ if (names == null) {
+ setProperty(OidcUtils.CLAIM_NAMES_PROPERTY, claimNames);
+ } else {
+ names.putAll(claimNames);
+ }
}
public AggregatedClaims getAggregatedClaims() {
Map<String, String> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
@@ -199,19 +216,26 @@ public abstract class AbstractUserInfo extends JwtClaims {
if (names == null || sources == null) {
return null;
}
+
AggregatedClaims claims = new AggregatedClaims();
- claims.setClaimNames(names);
+
+ Map<String, String> namesMap = new LinkedHashMap<String, String>();
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);
+ for (Map.Entry<String, String> entry : names.entrySet()) {
+ String source = entry.getValue();
+ Map<String, String> sourceValue = sources.get(source);
+ if (sourceValue != null && sourceValue.containsKey(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY)) {
+ namesMap.put(entry.getKey(), source);
+ String jwt = sourceValue.values().iterator().next();
+ sourcesMap.put(source, jwt);
+ }
}
+ claims.setClaimNames(namesMap);
claims.setClaimSources(sourcesMap);
return claims;
}
public void setDistributedClaims(DistributedClaims claims) {
- setProperty(OidcUtils.CLAIM_NAMES_PROPERTY, claims.getClaimNames());
+ setAddClaimNames(claims.getClaimNames());
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();
@@ -223,7 +247,7 @@ public abstract class AbstractUserInfo extends JwtClaims {
}
sources.put(source, mapSource);
}
- setProperty(OidcUtils.CLAIM_SOURCES_PROPERTY, sources);
+ setAddClaimSources(sources);
}
public DistributedClaims getDistributedClaims() {
Map<String, String> names = CastUtils.cast((Map<?, ?>)getProperty(OidcUtils.CLAIM_NAMES_PROPERTY));
@@ -233,15 +257,21 @@ public abstract class AbstractUserInfo extends JwtClaims {
return null;
}
DistributedClaims claims = new DistributedClaims();
- claims.setClaimNames(names);
+ Map<String, String> namesMap = new LinkedHashMap<String, String>();
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);
+ for (Map.Entry<String, String> entry : names.entrySet()) {
+ String source = entry.getValue();
+ Map<String, String> sourceValue = sources.get(source);
+ if (sourceValue != null
+ && !sourceValue.containsKey(OidcUtils.JWT_CLAIM_SOURCE_PROPERTY)) {
+ namesMap.put(entry.getKey(), source);
+ DistributedClaimSource distSource = new DistributedClaimSource();
+ distSource.setEndpoint(sourceValue.get(OidcUtils.ENDPOINT_CLAIM_SOURCE_PROPERTY));
+ distSource.setAccessToken(sourceValue.get(OidcUtils.TOKEN_CLAIM_SOURCE_PROPERTY));
+ sourcesMap.put(source, distSource);
+ }
}
+ claims.setClaimNames(namesMap);
claims.setClaimSources(sourcesMap);
return claims;
}