cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [1/2] cxf git commit: Applying Jan's patch to the OIDC code, leaving out ROLES for now
Date Wed, 12 Jul 2017 11:40:32 GMT
Repository: cxf
Updated Branches:
  refs/heads/master b936edac5 -> da07e6758


Applying Jan's patch to the OIDC code, leaving out ROLES for now


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

Branch: refs/heads/master
Commit: ef8dda985d1fbe31812b932650026658032d3ec4
Parents: 1387aba
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Jul 12 12:39:52 2017 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Jul 12 12:39:52 2017 +0100

----------------------------------------------------------------------
 .../cxf/rs/security/oidc/utils/OidcUtils.java   | 28 +++++++++--
 .../rs/security/oidc/utils/OidcUtilsTest.java   | 52 ++++++++++++++++++++
 2 files changed, 77 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/ef8dda98/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/utils/OidcUtils.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/utils/OidcUtils.java
b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/utils/OidcUtils.java
index 3fb8c90..f31c209 100644
--- a/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/utils/OidcUtils.java
+++ b/rt/rs/security/sso/oidc/src/main/java/org/apache/cxf/rs/security/oidc/utils/OidcUtils.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.rs.security.oidc.utils;
 
 import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
@@ -54,7 +55,19 @@ public final class OidcUtils {
     public static final String ADDRESS_SCOPE = "address";
     public static final String PHONE_SCOPE = "phone";
     public static final List<String> PROFILE_CLAIMS = Arrays.asList(UserInfo.NAME_CLAIM,
-                                                                    UserInfo.PROFILE_CLAIM);
+                                                                    UserInfo.FAMILY_NAME_CLAIM,
+                                                                    UserInfo.GIVEN_NAME_CLAIM,
+                                                                    UserInfo.MIDDLE_NAME_CLAIM,
+                                                                    UserInfo.NICKNAME_CLAIM,
+                                                                    UserInfo.PREFERRED_USERNAME_CLAIM,
+                                                                    UserInfo.PROFILE_CLAIM,
+                                                                    UserInfo.PICTURE_CLAIM,
+                                                                    UserInfo.WEBSITE_CLAIM,
+                                                                    UserInfo.GENDER_CLAIM,
+                                                                    UserInfo.BIRTHDATE_CLAIM,
+                                                                    UserInfo.ZONEINFO_CLAIM,
+                                                                    UserInfo.LOCALE_CLAIM,
+                                                                    UserInfo.UPDATED_AT_CLAIM);
     public static final List<String> EMAIL_CLAIMS = Arrays.asList(UserInfo.EMAIL_CLAIM,
                                                                   UserInfo.EMAIL_VERIFIED_CLAIM);
     public static final List<String> ADDRESS_CLAIMS = Arrays.asList(UserInfo.ADDRESS_CLAIM);
@@ -110,8 +123,17 @@ public final class OidcUtils {
     public static String getAllScopes() {
         return getScope(OPENID_SCOPE, PROFILE_SCOPE, EMAIL_SCOPE, ADDRESS_SCOPE, PHONE_SCOPE);
     }
-    public static List<String> getScopeProperties(String scope) {
-        return SCOPES_MAP.get(scope);
+    
+    public static List<String> getScopeClaims(String... scope) {
+        List<String> claims = new ArrayList<>();
+        if (scope != null) {
+            for (String s : scope) {
+                if (SCOPES_MAP.containsKey(s)) {
+                    claims.addAll(SCOPES_MAP.get(s));
+                }
+            }
+        }
+        return claims;
     }
 
     private static String getScope(String... scopes) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/ef8dda98/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/utils/OidcUtilsTest.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/utils/OidcUtilsTest.java
b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/utils/OidcUtilsTest.java
new file mode 100644
index 0000000..98c80fc
--- /dev/null
+++ b/rt/rs/security/sso/oidc/src/test/java/org/apache/cxf/rs/security/oidc/utils/OidcUtilsTest.java
@@ -0,0 +1,52 @@
+/**
+ * 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.utils;
+
+import java.util.List;
+
+import org.apache.cxf.rs.security.oidc.common.UserInfo;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class OidcUtilsTest extends Assert {
+    
+    @Test
+    public void testScopeToClaimsMappingNoValue() {
+        List<String> claims = OidcUtils.getScopeClaims();
+        assertNotNull(claims);
+        assertEquals(0, claims.size());
+    }
+    
+    @Test
+    public void testScopeToClaimsMappingSingleValue() {
+        List<String> claims = OidcUtils.getScopeClaims(OidcUtils.PHONE_SCOPE);
+        assertNotNull(claims);
+        assertEquals(1, claims.size());
+        assertEquals(UserInfo.PHONE_CLAIM, claims.get(0));
+    }
+    
+    @Test
+    public void testScopeToClaimsMappingMultiValue() {
+        List<String> claims = OidcUtils.getScopeClaims(OidcUtils.PROFILE_SCOPE, OidcUtils.PHONE_SCOPE);
+        assertNotNull(claims);
+        assertEquals(15, claims.size());
+    }
+        
+}


Mime
View raw message