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 AbstractOAuthProvider with some boilerplate code
Date Tue, 08 Dec 2015 16:25:29 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes dfe90b649 -> c27dc582c


Updating AbstractOAuthProvider with some boilerplate code


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

Branch: refs/heads/3.1.x-fixes
Commit: c27dc582c203d01fa8f63f500def10f0ae57d1e4
Parents: dfe90b6
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Tue Dec 8 16:17:41 2015 +0000
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Tue Dec 8 16:25:13 2015 +0000

----------------------------------------------------------------------
 .../provider/AbstractOAuthDataProvider.java     | 48 +++++++++++++++++++-
 .../DefaultEHCacheOAuthDataProvider.java        |  1 +
 2 files changed, 47 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/c27dc582/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 3c88608..149bff1 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
@@ -18,9 +18,13 @@
  */
 package org.apache.cxf.rs.security.oauth2.provider;
 
+import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
+import org.apache.cxf.jaxrs.ext.MessageContext;
 import org.apache.cxf.rs.security.oauth2.common.AccessTokenRegistration;
 import org.apache.cxf.rs.security.oauth2.common.Client;
 import org.apache.cxf.rs.security.oauth2.common.OAuthPermission;
@@ -35,6 +39,9 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
     private long accessTokenLifetime = 3600L;
     private long refreshTokenLifetime; // refresh tokens are eternal by default
     private boolean recycleRefreshTokens = true;
+    private Map<String, OAuthPermission> permissionMap = new HashMap<String, OAuthPermission>();
+    private MessageContext messageContext;
+    
     
     protected AbstractOAuthDataProvider() {
     }
@@ -133,12 +140,20 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
         return currentRefreshToken;
     }
 
-    
-
     @Override
     public List<OAuthPermission> convertScopeToPermissions(Client client, List<String>
requestedScopes) {
         if (requestedScopes.isEmpty()) {
             return Collections.emptyList();
+        } else if (!permissionMap.isEmpty()) {
+            List<OAuthPermission> list = new ArrayList<OAuthPermission>();
+            for (String scope : requestedScopes) {
+                OAuthPermission permission = permissionMap.get(scope);
+                if (permission == null) {
+                    throw new OAuthServiceException("Unexpected scope: " + scope);
+                }
+                list.add(permission);
+            }
+            return list;
         } else {
             throw new OAuthServiceException("Requested scopes can not be mapped");
         }
@@ -217,9 +232,38 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
         this.recycleRefreshTokens = recycleRefreshTokens;
     }
     
+    public void init() {
+    }
+    
+    public void close() {
+    }
+    
     protected abstract void saveAccessToken(ServerAccessToken serverToken);
     protected abstract void saveRefreshToken(ServerAccessToken at, RefreshToken refreshToken);
     protected abstract ServerAccessToken revokeAccessToken(String accessTokenKey);
     protected abstract RefreshToken revokeRefreshToken(Client client, String refreshTokenKey);
     protected abstract RefreshToken getRefreshToken(Client client, String refreshTokenKey);
+
+    public Map<String, OAuthPermission> getPermissionMap() {
+        return permissionMap;
+    }
+
+    public void setPermissionMap(Map<String, OAuthPermission> permissionMap) {
+        this.permissionMap = permissionMap;
+    }
+    
+    public void setScopes(Map<String, String> scopes) {
+        for (Map.Entry<String, String> entry : scopes.entrySet()) {
+            OAuthPermission permission = new OAuthPermission(entry.getKey(), entry.getValue());
+            permissionMap.put(entry.getKey(), permission);
+        }
+    }
+
+    public MessageContext getMessageContext() {
+        return messageContext;
+    }
+
+    public void setMessageContext(MessageContext messageContext) {
+        this.messageContext = messageContext;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/c27dc582/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEHCacheOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEHCacheOAuthDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEHCacheOAuthDataProvider.java
index bdf9d10..8a3b514 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEHCacheOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEHCacheOAuthDataProvider.java
@@ -195,6 +195,7 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
         refreshTokenCache = createCache(cacheManager, refreshTokenKey);
     }
 
+    @Override
     public void close() {
         cacheManager.shutdown();
     }


Mime
View raw message