cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject cxf git commit: Pushing some of the code to AbstractOAuthProvider
Date Wed, 30 Mar 2016 16:16:16 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.1.x-fixes 3a02b272b -> db8fca38f


Pushing some of the code to AbstractOAuthProvider


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

Branch: refs/heads/3.1.x-fixes
Commit: db8fca38f64cae8cdfc846774db6625cec5d387c
Parents: 3a02b27
Author: Sergey Beryozkin <sberyozkin@gmail.com>
Authored: Wed Mar 30 17:14:19 2016 +0100
Committer: Sergey Beryozkin <sberyozkin@gmail.com>
Committed: Wed Mar 30 17:15:45 2016 +0100

----------------------------------------------------------------------
 .../grants/code/AbstractCodeDataProvider.java   |  9 ++++
 .../code/DefaultEHCacheCodeDataProvider.java    | 11 ++---
 .../provider/AbstractOAuthDataProvider.java     | 45 +++++++++++++++++--
 .../DefaultEHCacheOAuthDataProvider.java        | 47 +++-----------------
 .../DefaultEncryptingOAuthDataProvider.java     | 37 +++------------
 5 files changed, 68 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/db8fca38/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AbstractCodeDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AbstractCodeDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AbstractCodeDataProvider.java
index f41e172..9b5c3df 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AbstractCodeDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/AbstractCodeDataProvider.java
@@ -19,6 +19,7 @@
 package org.apache.cxf.rs.security.oauth2.grants.code;
 
 import org.apache.cxf.rs.security.oauth2.common.Client;
+import org.apache.cxf.rs.security.oauth2.common.UserSubject;
 import org.apache.cxf.rs.security.oauth2.provider.AbstractOAuthDataProvider;
 import org.apache.cxf.rs.security.oauth2.provider.OAuthServiceException;
 
@@ -65,4 +66,12 @@ public abstract class AbstractCodeDataProvider extends AbstractOAuthDataProvider
         return grant;
     }
     protected abstract void saveCodeGrant(ServerAuthorizationCodeGrant grant);
+    
+    public static boolean isCodeMatched(ServerAuthorizationCodeGrant grant, Client c, UserSubject
sub) {
+        if (c == null || grant.getClient().getClientId().equals(c.getClientId())) {
+            UserSubject grantSub = grant.getSubject();
+            return sub == null || grantSub != null && grantSub.getLogin().equals(sub.getLogin());
+        }
+        return false;
+    }
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/db8fca38/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/DefaultEHCacheCodeDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/DefaultEHCacheCodeDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/DefaultEHCacheCodeDataProvider.java
index 12edf9b..4d0155d 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/DefaultEHCacheCodeDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/grants/code/DefaultEHCacheCodeDataProvider.java
@@ -58,9 +58,9 @@ public class DefaultEHCacheCodeDataProvider extends DefaultEHCacheOAuthDataProvi
     }
 
     @Override
-    protected Client doRemoveClient(Client c) {
+    protected void doRemoveClient(Client c) {
         removeClientCodeGrants(c);
-        return super.doRemoveClient(c);
+        super.doRemoveClient(c);
     }
     
     protected void removeClientCodeGrants(Client c) {
@@ -88,11 +88,8 @@ public class DefaultEHCacheCodeDataProvider extends DefaultEHCacheOAuthDataProvi
             new ArrayList<ServerAuthorizationCodeGrant>(keys.size());
         for (String key : keys) {
             ServerAuthorizationCodeGrant grant = getCodeGrant(key);
-            if (c == null || grant.getClient().getClientId().equals(c.getClientId())) {
-                UserSubject grantSub = grant.getSubject();
-                if (sub == null || grantSub != null && grantSub.getLogin().equals(sub.getLogin()))
{
-                    grants.add(grant);
-                }
+            if (AbstractCodeDataProvider.isCodeMatched(grant, c, sub)) {
+                grants.add(grant);
             }
         }
         return grants;

http://git-wip-us.apache.org/repos/asf/cxf/blob/db8fca38/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 cdacbb6..a94bcc3 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
@@ -322,11 +322,36 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
         }
     }
     
+    @Override
+    public Client removeClient(String clientId) {
+        Client c = getClient(clientId);
+        removeClientTokens(c);
+        doRemoveClient(c);
+        return c;
+    }
+    
+    protected ServerAccessToken revokeAccessToken(String accessTokenKey) {
+        ServerAccessToken at = getAccessToken(accessTokenKey);
+        if (at != null) {
+            doRevokeAccessToken(at);
+        }
+        return at;
+    }
+    protected RefreshToken revokeRefreshToken(String refreshTokenKey) { 
+        RefreshToken refreshToken = getRefreshToken(refreshTokenKey);
+        if (refreshToken != null) {
+            doRevokeRefreshToken(refreshToken);
+        }
+        return refreshToken;
+    }
+    
+    
     protected abstract void saveAccessToken(ServerAccessToken serverToken);
     protected abstract void saveRefreshToken(ServerAccessToken at, RefreshToken refreshToken);
-    protected abstract ServerAccessToken revokeAccessToken(String accessTokenKey);
-    protected abstract RefreshToken revokeRefreshToken(String refreshTokenKey);
+    protected abstract void doRevokeAccessToken(ServerAccessToken accessToken);
+    protected abstract void doRevokeRefreshToken(RefreshToken  refreshToken);
     protected abstract RefreshToken getRefreshToken(String refreshTokenKey);
+    protected abstract void doRemoveClient(Client c);
 
     public List<String> getDefaultScopes() {
         return defaultScopes;
@@ -359,7 +384,21 @@ public abstract class AbstractOAuthDataProvider implements OAuthDataProvider,
Cl
     public void setSupportPreauthorizedTokens(boolean supportPreauthorizedTokens) {
         this.supportPreauthorizedTokens = supportPreauthorizedTokens;
     }
-
+    protected static boolean isClientMatched(Client c, UserSubject resourceOwner) {
+        return resourceOwner == null 
+            || c.getResourceOwnerSubject() != null 
+                && c.getResourceOwnerSubject().getLogin().equals(resourceOwner.getLogin());
+    }
+    protected static boolean isTokenMatched(ServerAccessToken token, Client c, UserSubject
sub) {
+        if (c == null || token.getClient().getClientId().equals(c.getClientId())) {
+            UserSubject tokenSub = token.getSubject();
+            if (sub == null || tokenSub != null && tokenSub.getLogin().equals(sub.getLogin()))
{
+                return true;
+            }
+        }
+        return false;
+    }
+    
     
 
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/db8fca38/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 e57e2df..c6e65f3 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
@@ -78,24 +78,9 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
         putCacheValue(clientCache, client.getClientId(), client, 0);
     }
     
-    public void setClients(List<Client> clients) {
-        if (clients != null) {
-            for (Client client : clients) {
-                setClient(client);
-            }
-        }
-    }
-
     @Override
-    public Client removeClient(String clientId) {
-        Client c = getClient(clientId);
-        return doRemoveClient(c);
-    }
-    
-    protected Client doRemoveClient(Client c) {
-        removeClientTokens(c);
+    protected void doRemoveClient(Client c) {
         clientCache.remove(c.getClientId());
-        return c;
     }
 
     @Override
@@ -104,9 +89,7 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
         List<Client> clients = new ArrayList<Client>(keys.size());
         for (String key : keys) {
             Client c = getClient(key);
-            if (resourceOwner == null 
-                || c.getResourceOwnerSubject() != null 
-                   && c.getResourceOwnerSubject().getLogin().equals(resourceOwner.getLogin()))
{
+            if (isClientMatched(c, resourceOwner)) {
                 clients.add(c);
             }
         }
@@ -139,39 +122,21 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
         return tokens;
     }
     
-    protected static boolean isTokenMatched(ServerAccessToken token, Client c, UserSubject
sub) {
-        if (c == null || token.getClient().getClientId().equals(c.getClientId())) {
-            UserSubject tokenSub = token.getSubject();
-            if (sub == null || tokenSub != null && tokenSub.getLogin().equals(sub.getLogin()))
{
-                return true;
-            }
-        }
-        return false;
-    }
-
     @Override
     public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException
{
         return getCacheValue(accessTokenCache, accessToken, ServerAccessToken.class);
     }
     @Override
-    protected ServerAccessToken revokeAccessToken(String accessTokenKey) {
-        ServerAccessToken at = getAccessToken(accessTokenKey);
-        if (at != null) {
-            accessTokenCache.remove(accessTokenKey);
-        }
-        return at;
+    protected void doRevokeAccessToken(ServerAccessToken at) {
+        accessTokenCache.remove(at.getTokenKey());
     }
     @Override
     protected RefreshToken getRefreshToken(String refreshTokenKey) { 
         return getCacheValue(refreshTokenCache, refreshTokenKey, RefreshToken.class);
     }
     @Override
-    protected RefreshToken revokeRefreshToken(String refreshTokenKey) { 
-        RefreshToken refreshToken = getRefreshToken(refreshTokenKey);
-        if (refreshToken != null) {
-            refreshTokenCache.remove(refreshTokenKey);
-        }
-        return refreshToken;
+    protected void doRevokeRefreshToken(RefreshToken rt) { 
+        refreshTokenCache.remove(rt.getTokenKey());
     }
     
     protected void saveAccessToken(ServerAccessToken serverToken) {

http://git-wip-us.apache.org/repos/asf/cxf/blob/db8fca38/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEncryptingOAuthDataProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEncryptingOAuthDataProvider.java
b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEncryptingOAuthDataProvider.java
index fa675f6..e436aec 100644
--- a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEncryptingOAuthDataProvider.java
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/DefaultEncryptingOAuthDataProvider.java
@@ -62,20 +62,15 @@ public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvide
         
     }
     @Override
-    public Client removeClient(String clientId) {
-        Client client = getClient(clientId);
-        clientsMap.remove(clientId);
-        removeClientTokens(client);
-        return client;
+    public void doRemoveClient(Client c) {
+        clientsMap.remove(c.getClientId());
     }
     @Override
     public List<Client> getClients(UserSubject resourceOwner) {
         List<Client> clients = new ArrayList<Client>(clientsMap.size());
         for (String clientKey : clientsMap.keySet()) {
             Client c = getClient(clientKey);
-            if (resourceOwner == null 
-                || c.getResourceOwnerSubject() != null 
-                   && c.getResourceOwnerSubject().getLogin().equals(resourceOwner.getLogin()))
{
+            if (isClientMatched(c, resourceOwner)) {
                 clients.add(c);
             }
         }
@@ -103,16 +98,6 @@ public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvide
         }
         return list;
     }
-    
-    protected static boolean isTokenMatched(ServerAccessToken token, Client c, UserSubject
sub) {
-        if (c == null || token.getClient().getClientId().equals(c.getClientId())) {
-            UserSubject tokenSub = token.getSubject();
-            if (sub == null || tokenSub != null && tokenSub.getLogin().equals(sub.getLogin()))
{
-                return true;
-            }
-        }
-        return false;
-    }
     @Override
     public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException
{
         try {
@@ -128,10 +113,8 @@ public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvide
     }
 
     @Override
-    protected ServerAccessToken revokeAccessToken(String accessTokenKey) {
-        ServerAccessToken at = getAccessToken(accessTokenKey);
-        tokens.remove(accessTokenKey);
-        return at;
+    protected void doRevokeAccessToken(ServerAccessToken at) {
+        tokens.remove(at.getTokenKey());
     }
     
     @Override
@@ -141,14 +124,8 @@ public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvide
     }
 
     @Override
-    protected RefreshToken revokeRefreshToken(String refreshTokenKey) {
-        RefreshToken rt = null;
-        if (refreshTokens.containsKey(refreshTokenKey)) {
-            rt = getRefreshToken(refreshTokenKey);
-            refreshTokens.remove(refreshTokenKey);
-        }
-        return rt;
-        
+    protected void doRevokeRefreshToken(RefreshToken rt) {
+        refreshTokens.remove(rt.getTokenKey());
     }
 
     private void encryptAccessToken(ServerAccessToken token) {


Mime
View raw message