Account for every type of principal
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/5107ccf5 Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5107ccf5 Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5107ccf5 Branch: refs/heads/master Commit: 5107ccf592346cbd0afb65b6a83985bd062ce2dc Parents: e2ebc46 Author: Dave Johnson <[email protected]> Authored: Fri May 20 10:07:11 2016 -0400 Committer: Dave Johnson <[email protected]> Committed: Fri May 20 10:07:11 2016 -0400 ---------------------------------------------------------------------- .../usergrid/security/shiro/ShiroCache.java | 44 +++++++++++++++----- 1 file changed, 33 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/usergrid/blob/5107ccf5/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 e14442c..b4803b1 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,31 +182,53 @@ 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(); + String ret = null; - // if we can't get a user UUID or access token, then we have a guest - String ret = keyClass + "_guest"; + final String typeName = typeRef.getType().getTypeName(); if ( key instanceof SimplePrincipalCollection) { + SimplePrincipalCollection spc = (SimplePrincipalCollection)key; - // principal is a user, use UUID as cache key if ( spc.getPrimaryPrincipal() instanceof UserPrincipal) { + + // principal is a user, use UUID as cache key UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal(); - ret = p.getUser().getUuid().toString() + "_" + keyClass; + ret = p.getUser().getUuid().toString() + "_" + typeName; } 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; - + PrincipalIdentifier p = (PrincipalIdentifier) spc.getPrimaryPrincipal(); + if (p.getAccessTokenCredentials() != null) { + ret = p.getAccessTokenCredentials().getToken() + "_" + typeName; + } else { + ret = p.getApplicationId() + "_" + typeName; } } + + } else if ( key instanceof ApplicationGuestPrincipal ) { + ApplicationGuestPrincipal agp = (ApplicationGuestPrincipal) key; + ret = agp.getApplicationId() + "_" + typeName; + + } else if ( key instanceof ApplicationPrincipal ) { + ApplicationPrincipal ap = (ApplicationPrincipal) key; + ret = ap.getApplicationId() + "_" + typeName; + + } else if ( key instanceof OrganizationPrincipal ) { + OrganizationPrincipal op = (OrganizationPrincipal) key; + ret = op.getOrganizationId() + "_" + typeName; + + } else if ( key instanceof UserPrincipal ) { + UserPrincipal up = (UserPrincipal)key; + ret = up.getUser().getUuid() + "_" + typeName; + } + + if ( ret == null) { + String msg = "Unknown key type: " + key.getClass().getSimpleName(); + logger.error(msg); + throw new RuntimeException(msg); } return ret;
