cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject [1/2] git commit: [CXF-5669] Prototyping ClientRegistrationProvider interface
Date Wed, 20 Aug 2014 13:26:03 GMT
Repository: cxf
Updated Branches:
  refs/heads/3.0.x-fixes d3c423944 -> 79be65ac2


[CXF-5669] Prototyping ClientRegistrationProvider interface


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

Branch: refs/heads/3.0.x-fixes
Commit: 98b58d094ce6a5c80470379ffb7eb5e48b0f0ce1
Parents: d3c4239
Author: Sergey Beryozkin <sberyozkin@talend.com>
Authored: Wed Aug 20 14:16:42 2014 +0100
Committer: Sergey Beryozkin <sberyozkin@talend.com>
Committed: Wed Aug 20 14:25:36 2014 +0100

----------------------------------------------------------------------
 .../DefaultEHCacheOAuthDataProvider.java        | 31 +++++++++++++++++++-
 .../DefaultEncryptingOAuthDataProvider.java     | 29 ++++++++++++++++--
 2 files changed, 56 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/98b58d09/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 78ab702..23891d2 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
@@ -20,6 +20,8 @@ package org.apache.cxf.rs.security.oauth2.provider;
 
 import java.io.File;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheManager;
@@ -32,13 +34,15 @@ import net.sf.ehcache.config.DiskStoreConfiguration;
 
 import org.apache.cxf.Bus;
 import org.apache.cxf.BusFactory;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.jaxrs.utils.ResourceUtils;
 import org.apache.cxf.rs.security.oauth2.common.Client;
 import org.apache.cxf.rs.security.oauth2.common.ServerAccessToken;
 import org.apache.cxf.rs.security.oauth2.tokens.refresh.RefreshToken;
 import org.apache.cxf.rs.security.oauth2.utils.EHCacheUtil;
 
-public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider {
+public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider 
+    implements ClientRegistrationProvider {
     public static final String CLIENT_CACHE_KEY = "cxf.oauth2.client.cache";
     public static final String ACCESS_TOKEN_CACHE_KEY = "cxf.oauth2.accesstoken.cache";
     public static final String REFRESH_TOKEN_CACHE_KEY = "cxf.oauth2.refreshtoken.cache";
@@ -71,6 +75,29 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
     }
     
     @Override
+    public void setClient(Client client) {
+        putCacheValue(clientCache, client.getClientId(), client, 0);
+        
+    }
+
+    @Override
+    public Client removeClient(String clientId) {
+        Client c = getClient(clientId);
+        clientCache.remove(clientId);
+        return c;
+    }
+
+    @Override
+    public List<Client> getClients() {
+        List<String> keys = CastUtils.cast(clientCache.getKeys());
+        List<Client> clients = new ArrayList<Client>(keys.size());
+        for (String key : keys) {
+            clients.add(getClient(key));
+        }
+        return clients;
+    }
+    
+    @Override
     public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException
{
         return getCacheValue(accessTokenCache, accessToken, ServerAccessToken.class);
     }
@@ -165,4 +192,6 @@ public class DefaultEHCacheOAuthDataProvider extends AbstractOAuthDataProvider
{
         accessTokenCache = createCache(cacheManager, accessTokenKey);
         refreshTokenCache = createCache(cacheManager, refreshTokenKey);
     }
+
+    
 }

http://git-wip-us.apache.org/repos/asf/cxf/blob/98b58d09/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 bb510af..94f1886 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
@@ -18,8 +18,10 @@
  */
 package org.apache.cxf.rs.security.oauth2.provider;
 
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashSet;
+import java.util.List;
 import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -32,11 +34,12 @@ import org.apache.cxf.rs.security.oauth2.utils.crypto.CryptoUtils;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.KeyProperties;
 import org.apache.cxf.rs.security.oauth2.utils.crypto.ModelEncryptionSupport;
 
-public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvider {
+public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvider 
+    implements ClientRegistrationProvider {
     protected SecretKey key;
     private Set<String> tokens = Collections.synchronizedSet(new HashSet<String>());
     private ConcurrentHashMap<String, String> refreshTokens = new ConcurrentHashMap<String,
String>();
-    
+    private ConcurrentHashMap<String, String> clientsMap = new ConcurrentHashMap<String,
String>();
     public DefaultEncryptingOAuthDataProvider(String algo, int keySize) {
         this(new KeyProperties(algo, keySize));
     }
@@ -49,10 +52,30 @@ public class DefaultEncryptingOAuthDataProvider extends AbstractOAuthDataProvide
     
     @Override
     public Client getClient(String clientId) throws OAuthServiceException {
-        return null;
+        return ModelEncryptionSupport.decryptClient(clientsMap.get(clientId), key);
     }
 
     @Override
+    public void setClient(Client client) {
+        clientsMap.put(client.getClientId(), ModelEncryptionSupport.encryptClient(client,
key));
+        
+    }
+    @Override
+    public Client removeClient(String clientId) {
+        Client client = getClient(clientId);
+        clientsMap.remove(clientId);
+        return client;
+    }
+    @Override
+    public List<Client> getClients() {
+        List<Client> clients = new ArrayList<Client>(clientsMap.size());
+        for (String clientKey : clientsMap.keySet()) {
+            clients.add(getClient(clientKey));
+        }
+        return clients;
+    }
+    
+    @Override
     public ServerAccessToken getAccessToken(String accessToken) throws OAuthServiceException
{
         return ModelEncryptionSupport.decryptAccessToken(this, accessToken, key);
     }


Mime
View raw message