cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf-fediz git commit: [FEDIZ-134] Adding OAuthDataManager extraScopes property
Date Mon, 09 Nov 2015 11:11:31 GMT
Repository: cxf-fediz
Updated Branches:
  refs/heads/master e5de0f3d1 -> e3aa8baca


[FEDIZ-134] Adding OAuthDataManager extraScopes property


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

Branch: refs/heads/master
Commit: e3aa8baca7d9b0a6582e2b949ca8520388e0fb3e
Parents: e5de0f3
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Mon Nov 9 11:11:11 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Mon Nov 9 11:11:11 2015 +0000

----------------------------------------------------------------------
 .../fediz/service/oidc/OAuthDataManager.java    | 22 +++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf-fediz/blob/e3aa8bac/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/OAuthDataManager.java
----------------------------------------------------------------------
diff --git a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/OAuthDataManager.java
b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/OAuthDataManager.java
index 6a08465..2e802da 100644
--- a/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/OAuthDataManager.java
+++ b/services/oidc/src/main/java/org/apache/cxf/fediz/service/oidc/OAuthDataManager.java
@@ -42,15 +42,13 @@ import org.apache.cxf.rs.security.oauth2.utils.OAuthConstants;
 public class OAuthDataManager extends AbstractCodeDataProvider {
 
     private static final OAuthPermission OPENID_PERMISSION;
-    private static final Map<String, OAuthPermission> PERMISSION_MAP;
     
     static {
-        PERMISSION_MAP = new HashMap<String, OAuthPermission>();
         OPENID_PERMISSION = new OAuthPermission("openid", "OIDC Authentication");
         OPENID_PERMISSION.setDefault(true);
-        PERMISSION_MAP.put("openid", OPENID_PERMISSION);
     }
 
+    private Map<String, OAuthPermission> permissionMap = new HashMap<String, OAuthPermission>();
     private MessageContext messageContext;
     private SamlTokenConverter tokenConverter = new LocalSamlTokenConverter();
     private Map<String, Client> clients = new ConcurrentHashMap<String, Client>();
@@ -59,6 +57,10 @@ public class OAuthDataManager extends AbstractCodeDataProvider {
     private Map<String, ServerAuthorizationCodeGrant> codeGrants = 
             new ConcurrentHashMap<String, ServerAuthorizationCodeGrant>();
 
+    public OAuthDataManager() {
+        permissionMap.put(OPENID_PERMISSION.getPermission(), OPENID_PERMISSION);
+    }
+    
     public void registerClient(Client c) {
         clients.put(c.getClientId(), c);
     }
@@ -135,15 +137,14 @@ public class OAuthDataManager extends AbstractCodeDataProvider {
             throws OAuthServiceException {
         List<OAuthPermission> list = new ArrayList<OAuthPermission>();
         for (String scope : scopes) {
-            OAuthPermission permission = PERMISSION_MAP.get(scope);
+            OAuthPermission permission = permissionMap.get(scope);
             if (permission == null) {
                 throw new OAuthServiceException("Unexpected scope: " + scope);
             }
             list.add(permission);
         }
-        // Ensure the default permission is available
-        if (list.isEmpty()) {
-            list.add(OPENID_PERMISSION);
+        if (!list.contains(OPENID_PERMISSION)) {
+            throw new OAuthServiceException("Default scope is missing");
         }
         return list;
     }
@@ -155,4 +156,11 @@ public class OAuthDataManager extends AbstractCodeDataProvider {
     public void setTokenConverter(SamlTokenConverter tokenConverter) {
         this.tokenConverter = tokenConverter;
     }
+
+    public void setExtraScopes(Map<String, String> extraScopes) {
+        for (Map.Entry<String, String> entry : extraScopes.entrySet()) {
+            permissionMap.put(entry.getKey(), 
+                    new OAuthPermission(entry.getKey(), entry.getValue()));
+        }
+    }
 }


Mime
View raw message