cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Updating UserInfoService to check OidcUserSubject for the prepared UserInfo and adding some basic IdToken to UserInfo conversion code if UserInfo is not available
Date Wed, 09 Dec 2015 11:40:08 GMT
Repository: cxf
Updated Branches:
  refs/heads/master 98453a679 -> a95f63ae4


Updating UserInfoService to check OidcUserSubject for the prepared UserInfo and adding some
basic IdToken to UserInfo conversion code if UserInfo is not available


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

Branch: refs/heads/master
Commit: a95f63ae466fcfe8a7e49a4fe87ecbdf75f7eb5e
Parents: 98453a6
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Dec 9 11:39:53 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Dec 9 11:39:53 2015 +0000

----------------------------------------------------------------------
 .../rs/security/oidc/idp/OidcUserSubject.java   | 10 +++++
 .../rs/security/oidc/idp/UserInfoService.java   | 42 +++++++++++++++++++-
 2 files changed, 50 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/a95f63ae/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java
index d9dd955..c08bd78 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/OidcUserSubject.java
@@ -20,11 +20,13 @@ package org.apache.cxf.rs.security.oidc.idp;
 
 import org.apache.cxf.rs.security.oauth2.common.UserSubject;
 import org.apache.cxf.rs.security.oidc.common.IdToken;
+import org.apache.cxf.rs.security.oidc.common.UserInfo;
 
 public class OidcUserSubject extends UserSubject {
     
     private static final long serialVersionUID = 8806727177012442229L;
     private IdToken idToken;
+    private UserInfo userInfo;
     
     public OidcUserSubject() {
         
@@ -41,4 +43,12 @@ public class OidcUserSubject extends UserSubject {
         this.idToken = idToken;
     }
 
+    public UserInfo getUserInfo() {
+        return userInfo;
+    }
+
+    public void setUserInfo(UserInfo userInfo) {
+        this.userInfo = userInfo;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/a95f63ae/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoService.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoService.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoService.java
index ae22b22..b898593 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoService.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/idp/UserInfoService.java
@@ -30,6 +30,7 @@ import org.apache.cxf.rs.security.oauth2.common.OAuthContext;
 import org.apache.cxf.rs.security.oauth2.provider.AbstractOAuthServerJoseJwtProducer;
 import org.apache.cxf.rs.security.oauth2.provider.OAuthDataProvider;
 import org.apache.cxf.rs.security.oauth2.utils.OAuthContextUtils;
+import org.apache.cxf.rs.security.oidc.common.IdToken;
 import org.apache.cxf.rs.security.oidc.common.UserInfo;
 
 @Path("/userinfo")
@@ -43,9 +44,25 @@ public class UserInfoService extends AbstractOAuthServerJoseJwtProducer
{
     @Produces({"application/json", "application/jwt" })
     public Response getUserInfo() {
         OAuthContext oauth = OAuthContextUtils.getContext(mc);
-        UserInfo userInfo = 
-            userInfoProvider.getUserInfo(oauth.getClientId(), oauth.getSubject(), oauth.getPermissions());
+        UserInfo userInfo = null;
+        if (userInfoProvider != null) {
+            userInfo = userInfoProvider.getUserInfo(oauth.getClientId(), 
+                                         oauth.getSubject(), 
+                                         oauth.getPermissions());
+        } else if (oauth.getSubject() instanceof OidcUserSubject) {
+            OidcUserSubject oidcUserSubject = (OidcUserSubject)oauth.getSubject();
+            userInfo = oidcUserSubject.getUserInfo();
+            if (userInfo == null) {
+                userInfo = createFromIdToken(oidcUserSubject.getIdToken());
+            }
+        }
+        if (userInfo == null) {
+            // Consider customizing the error code in case of UserInfo being not available
+            return Response.serverError().build();
+        }
+        
         Object responseEntity = userInfo;
+        // UserInfo may be returned in a clear form as JSON
         if (super.isJwsRequired() || super.isJweRequired()) {
             responseEntity = super.processJwt(new JwtToken(userInfo),
                                               oauthDataProvider.getClient(oauth.getClientId()));
@@ -54,6 +71,27 @@ public class UserInfoService extends AbstractOAuthServerJoseJwtProducer
{
         
     }
     
+    protected UserInfo createFromIdToken(IdToken idToken) {
+        UserInfo userInfo = new UserInfo();
+        userInfo.setSubject(idToken.getSubject());
+        userInfo.setIssuer(idToken.getIssuer());
+        userInfo.setAudience(idToken.getAudience());
+        if (idToken.getName() != null) {
+            userInfo.setName(idToken.getName());
+        }
+        if (idToken.getGivenName() != null) {
+            userInfo.setGivenName(idToken.getGivenName());
+        }
+        if (idToken.getFamilyName() != null) {
+            userInfo.setFamilyName(idToken.getFamilyName());
+        }
+        if (idToken.getEmail() != null) {
+            userInfo.setEmail(idToken.getEmail());
+        }
+        //etc
+        return userInfo;
+    }
+
     public void setUserInfoProvider(UserInfoProvider userInfoProvider) {
         this.userInfoProvider = userInfoProvider;
     }


Mime
View raw message