cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Checking some scope properties in the OAuth provider to minimize the amount of custom code
Date Tue, 19 Jan 2016 10:47:49 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes c090a8163 -> 12206c314


Checking some scope properties in the OAuth provider to minimize the amount of custom code


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

Branch: refs/heads/3.1.x-fixes
Commit: 12206c314d34f2e210f7292fcb7a3e894fafd4e7
Parents: c090a81
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Jan 19 10:46:16 2016 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Jan 19 10:47:20 2016 +0000

----------------------------------------------------------------------
 .../provider/AbstractOAuthDataProvider.java     | 39 ++++++++++++++++++++
 1 file changed, 39 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/12206c31/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
index edfabb6..e836898 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/AbstractOAuthDataProvider.java
@@ -41,6 +41,9 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
     private boolean recycleRefreshTokens = true;
     private Map<String, OAuthPermission> permissionMap = new HashMap<String, OAuthPermission>();
     private MessageContext messageContext;
+    private List<String> defaultScopes;
+    private List<String> requiredScopes;
+    private List<String> invisibleToClientScopes;
     
     
     protected AbstractOAuthDataProvider() {
@@ -159,6 +162,10 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
         if (requestedScopes.isEmpty()) {
             return Collections.emptyList();
         } else if (!permissionMap.isEmpty()) {
+            if (requiredScopes != null && !requestedScopes.containsAll(requiredScopes))
{
+                throw new OAuthServiceException("Required scopes are missing");
+            }
+            
             List<OAuthPermission> list = new ArrayList<OAuthPermission>();
             for (String scope : requestedScopes) {
                 OAuthPermission permission = permissionMap.get(scope);
@@ -247,6 +254,14 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
     }
     
     public void init() {
+        for (OAuthPermission perm : permissionMap.values()) {
+            if (defaultScopes != null && defaultScopes.contains(perm.getPermission()))
{
+                perm.setDefault(true);
+            }
+            if (invisibleToClientScopes != null && invisibleToClientScopes.contains(perm.getPermission()))
{
+                perm.setInvisibleToClient(true);
+            }
+        }
     }
     
     public void close() {
@@ -290,4 +305,28 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
     protected abstract RefreshToken revokeRefreshToken(String refreshTokenKey);
     protected abstract RefreshToken getRefreshToken(String refreshTokenKey);
 
+    public List<String> getDefaultScopes() {
+        return defaultScopes;
+    }
+
+    public void setDefaultScopes(List<String> defaultScopes) {
+        this.defaultScopes = defaultScopes;
+    }
+
+    public List<String> getRequiredScopes() {
+        return requiredScopes;
+    }
+
+    public void setRequiredScopes(List<String> requiredScopes) {
+        this.requiredScopes = requiredScopes;
+    }
+
+    public List<String> getInvisibleToClientScopes() {
+        return invisibleToClientScopes;
+    }
+
+    public void setInvisibleToClientScopes(List<String> invisibleToClientScopes) {
+        this.invisibleToClientScopes = invisibleToClientScopes;
+    }
+
 }


Mime
View raw message