usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mru...@apache.org
Subject [1/2] usergrid git commit: Better Shiro cache key logic
Date Fri, 20 May 2016 14:16:24 GMT
Repository: usergrid
Updated Branches:
  refs/heads/release-2.1.1 7fdca3d24 -> 5107ccf59


Better Shiro cache key logic


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

Branch: refs/heads/release-2.1.1
Commit: e2ebc468b2e72cb9cec98bd8f91ee07d507d1c59
Parents: 7fdca3d
Author: Dave Johnson <snoopdave@apache.org>
Authored: Thu May 19 22:39:05 2016 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Thu May 19 22:39:05 2016 -0400

----------------------------------------------------------------------
 .../usergrid/security/shiro/ShiroCache.java     | 22 ++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/e2ebc468/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
index 88466bf..e14442c 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
@@ -182,16 +182,34 @@ public class ShiroCache<K, V> implements Cache<K,V> {
     /** key is the user UUID in string form + class name of key */
     private String getKeyString( K key ) {
 
+        // both authc and authz caches use same column family
+        // make sure keys unique to key type
+        String keyClass = key.getClass().getSimpleName();
+
+        // if we can't get a user UUID or access token, then we have a guest
+        String ret = keyClass + "_guest";
+
         if ( key instanceof SimplePrincipalCollection) {
             SimplePrincipalCollection spc = (SimplePrincipalCollection)key;
 
+            // principal is a user, use UUID as cache key
             if ( spc.getPrimaryPrincipal() instanceof UserPrincipal) {
                 UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal();
-                return p.getUser().getUuid().toString();
+                ret = p.getUser().getUuid().toString() + "_" + keyClass;
+            }
+
+            else if ( spc.getPrimaryPrincipal() instanceof PrincipalIdentifier ) {
+                PrincipalIdentifier p = (PrincipalIdentifier)spc.getPrimaryPrincipal();
+
+                // principal is not user, try to get something unique as cache key
+                if ( p.getAccessTokenCredentials() != null ) {
+                    ret = p.getAccessTokenCredentials().getToken() + "_" + keyClass;
+
+                }
             }
         }
 
-        return key.toString() + "_" + key.getClass().getSimpleName();
+        return ret;
     }
 
 }


Mime
View raw message