You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by se...@apache.org on 2014/08/20 15:26:03 UTC

[1/2] git commit: [CXF-5669] Prototyping ClientRegistrationProvider interface

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 <sb...@talend.com>
Authored: Wed Aug 20 14:16:42 2014 +0100
Committer: Sergey Beryozkin <sb...@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);
     }


[2/2] git commit: [CXF-5669] Adding the missing file

Posted by se...@apache.org.
[CXF-5669] Adding the missing file


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

Branch: refs/heads/3.0.x-fixes
Commit: 79be65ac292c636427922f61e85de6737c7b4975
Parents: 98b58d0
Author: Sergey Beryozkin <sb...@talend.com>
Authored: Wed Aug 20 14:18:20 2014 +0100
Committer: Sergey Beryozkin <sb...@talend.com>
Committed: Wed Aug 20 14:25:37 2014 +0100

----------------------------------------------------------------------
 .../provider/ClientRegistrationProvider.java    | 30 ++++++++++++++++++++
 1 file changed, 30 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cxf/blob/79be65ac/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/ClientRegistrationProvider.java
----------------------------------------------------------------------
diff --git a/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/ClientRegistrationProvider.java b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/ClientRegistrationProvider.java
new file mode 100644
index 0000000..d1010b9
--- /dev/null
+++ b/rt/rs/security/oauth-parent/oauth2/src/main/java/org/apache/cxf/rs/security/oauth2/provider/ClientRegistrationProvider.java
@@ -0,0 +1,30 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.cxf.rs.security.oauth2.provider;
+
+import java.util.List;
+
+import org.apache.cxf.rs.security.oauth2.common.Client;
+
+public interface ClientRegistrationProvider {
+    Client getClient(String clientId);
+    void setClient(Client client);
+    Client removeClient(String clientId);
+    List<Client> getClients();
+}