usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [13/24] usergrid git commit: Adding cache invalidation at all the right places and support for all Principal types makes all tests run except for one. This guy still fails: PermissionsResourceIT.getNonExistantEntityReturns404:213 expected:<404> but was:<
Date Wed, 21 Oct 2015 20:50:13 GMT
Adding cache invalidation at all the right places and support for all Principal types makes
all tests run except for one.
This guy still fails: PermissionsResourceIT.getNonExistantEntityReturns404:213 expected:<404>
but was:<401>


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

Branch: refs/heads/jacoco
Commit: b9a7ab1c07d989f94ea457d5804825561fc33ded
Parents: 02fb362
Author: Dave Johnson <snoopdave@apache.org>
Authored: Tue Sep 29 10:24:46 2015 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Tue Sep 29 10:24:46 2015 -0400

----------------------------------------------------------------------
 .../impl/ScopedCacheSerializationImpl.java      | 30 +++++--
 .../applications/ApplicationsResource.java      |  2 +
 .../rest/security/shiro/ShiroCache.java         | 95 ++++++++++++--------
 .../applications/ApplicationResourceIT.java     |  1 -
 .../users/ConnectionResourceTest.java           | 47 +++++-----
 .../collection/users/PermissionsResourceIT.java | 61 +++++++------
 .../usergrid/management/ApplicationInfo.java    |  6 +-
 .../cassandra/ManagementServiceImpl.java        | 13 ++-
 .../security/oauth/ClientCredentialsInfo.java   |  6 +-
 .../credentials/AbstractClientCredentials.java  |  5 ++
 .../credentials/ApplicationUserAccessToken.java |  3 +
 .../OrganizationClientCredentials.java          |  5 ++
 .../services/AbstractConnectionsService.java    |  3 +-
 .../usergrid/services/groups/GroupsService.java | 10 +++
 .../usergrid/services/users/UsersService.java   |  7 ++
 .../org/apache/usergrid/ServiceApplication.java |  2 +
 16 files changed, 191 insertions(+), 105 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
index bde6672..c11d62f 100644
--- a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
@@ -26,9 +26,11 @@ import com.google.common.base.Preconditions;
 import com.google.common.hash.Funnel;
 import com.google.common.hash.PrimitiveSink;
 import com.google.inject.Inject;
+import com.netflix.astyanax.ColumnListMutation;
 import com.netflix.astyanax.Keyspace;
 import com.netflix.astyanax.MutationBatch;
 import com.netflix.astyanax.Serializer;
+import com.netflix.astyanax.connectionpool.OperationResult;
 import com.netflix.astyanax.connectionpool.exceptions.ConnectionException;
 import com.netflix.astyanax.connectionpool.exceptions.NotFoundException;
 import com.netflix.astyanax.model.Column;
@@ -136,8 +138,13 @@ public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerializati
                 //V value = MAPPER.readValue(result.getByteArrayValue(), new TypeReference<V>()
{});
                 V value = MAPPER.readValue(result.getByteArrayValue(), typeRef);
 
-                logger.debug("Read cache item\n   key/value types {}/{}\n   key:value: {}:{}",
-                    new Object[]{key.getClass().getSimpleName(), value.getClass().getSimpleName(),
key, value});
+                logger.debug("Read cache item from scope {}\n   key/value types {}/{}\n 
 key:value: {}:{}",
+                    new Object[]{
+                        scope.getApplication().getUuid(),
+                        key.getClass().getSimpleName(),
+                        value.getClass().getSimpleName(),
+                        key,
+                        value});
 
                 return value;
 
@@ -192,8 +199,13 @@ public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerializati
 
         executeBatch(batch);
 
-        logger.debug("Wrote cache item\n   key/value types {}/{}\n   key:value: {}:{}",
-            new Object[]{key.getClass().getSimpleName(), value.getClass().getSimpleName(),
key, value});
+        logger.debug("Wrote cache item to scope {}\n   key/value types {}/{}\n   key:value:
{}:{}",
+            new Object[] {
+                scope.getApplication().getUuid(),
+                key.getClass().getSimpleName(),
+                value.getClass().getSimpleName(),
+                key,
+                value});
 
         return value;
     }
@@ -237,7 +249,10 @@ public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerializati
         final MutationBatch batch = keyspace.prepareMutationBatch();
 
         batch.withRow(SCOPED_CACHE, keyRowKey).delete();
-        executeBatch(batch);
+
+        final OperationResult<Void> result = executeBatch(batch);
+
+        logger.debug("Invalidated scope {}", scope.getApplication().getUuid());
     }
 
 
@@ -254,9 +269,10 @@ public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerializati
     }
 
 
-    private void executeBatch(MutationBatch batch) {
+    private OperationResult<Void> executeBatch(MutationBatch batch) {
         try {
-            batch.execute();
+            return batch.execute();
+
         } catch (ConnectionException e) {
             throw new RuntimeException("Unable to connect to cassandra", e);
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
index 86584c3..fcd5404 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/management/organizations/applications/ApplicationsResource.java
@@ -22,6 +22,8 @@ import com.google.common.base.Preconditions;
 import com.google.common.collect.BiMap;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.OrganizationInfo;
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
 import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
 import org.apache.usergrid.rest.AbstractContextResource;
 import org.apache.usergrid.rest.ApiResponse;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
index 535a435..1781885 100644
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
@@ -17,24 +17,26 @@
 package org.apache.usergrid.rest.security.shiro;
 
 import com.fasterxml.jackson.core.type.TypeReference;
-import org.apache.shiro.authc.SimpleAuthenticationInfo;
 import org.apache.shiro.cache.Cache;
 import org.apache.shiro.cache.CacheException;
 import org.apache.shiro.subject.SimplePrincipalCollection;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.persistence.cache.CacheFactory;
 import org.apache.usergrid.persistence.cache.CacheScope;
 import org.apache.usergrid.persistence.cache.ScopedCache;
-import org.apache.usergrid.persistence.index.utils.UUIDUtils;
 import org.apache.usergrid.persistence.model.entity.SimpleId;
-import org.apache.usergrid.persistence.model.util.UUIDGenerator;
 import org.apache.usergrid.security.shiro.UsergridAuthenticationInfo;
 import org.apache.usergrid.security.shiro.UsergridAuthorizationInfo;
-import org.apache.usergrid.security.shiro.principals.AdminUserPrincipal;
+import org.apache.usergrid.security.shiro.principals.ApplicationPrincipal;
+import org.apache.usergrid.security.shiro.principals.OrganizationPrincipal;
 import org.apache.usergrid.security.shiro.principals.UserPrincipal;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.*;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.UUID;
 
 
 /**
@@ -42,7 +44,7 @@ import java.util.*;
  */
 public class ShiroCache<K, V> implements Cache<K,V> {
 
-    private static final Logger logger = LoggerFactory.getLogger( ShiroCacheManager.class
);
+    private static final Logger logger = LoggerFactory.getLogger( ShiroCache.class );
 
     CacheFactory<String, V> cacheFactory;
 
@@ -60,16 +62,18 @@ public class ShiroCache<K, V> implements Cache<K,V> {
         if ( scopedCache != null ) {
             V value = scopedCache.get(getKeyString(key), typeRef);
 
-            if ( value instanceof UsergridAuthorizationInfo ) {
-                UsergridAuthorizationInfo info = (UsergridAuthorizationInfo)value;
-                logger.debug("Got from AUTHZ cache {} for app {}", getKeyString(key), info.toString());
+            if ( logger.isDebugEnabled() ) {
+                if (value instanceof UsergridAuthorizationInfo) {
+                    UsergridAuthorizationInfo info = (UsergridAuthorizationInfo) value;
+                    logger.debug("Got from AUTHZ cache {} for app {}", getKeyString(key),
info.toString());
 
-            } else if ( value instanceof UsergridAuthenticationInfo ) {
-                UsergridAuthenticationInfo info = (UsergridAuthenticationInfo)value;
-                logger.debug("Got from AUTHC cache {} for app {}", getKeyString(key), info.toString());
+                } else if (value instanceof UsergridAuthenticationInfo) {
+                    UsergridAuthenticationInfo info = (UsergridAuthenticationInfo) value;
+                    logger.debug("Got from AUTHC cache {} for app {}", getKeyString(key),
info.toString());
 
-            } else if (value == null) {
-                logger.debug("Got NULL from cache app {} for key {}", getKeyString(key),
key.toString() );
+                } else if (value == null) {
+                    logger.debug("Got NULL from cache app {} for key {}", getKeyString(key),
key.toString());
+                }
             }
 
             return value;
@@ -83,13 +87,15 @@ public class ShiroCache<K, V> implements Cache<K,V> {
         if ( scopedCache != null ) {
             V ret = scopedCache.put(getKeyString(key), value, 5000);
 
-            if ( value instanceof UsergridAuthorizationInfo ) {
-                UsergridAuthorizationInfo info = (UsergridAuthorizationInfo)value;
-                logger.debug("Put to AUTHZ cache {} for app {}", getKeyString(key), info.toString());
+            if ( logger.isDebugEnabled() ) {
+                if (value instanceof UsergridAuthorizationInfo) {
+                    UsergridAuthorizationInfo info = (UsergridAuthorizationInfo) value;
+                    logger.debug("Put to AUTHZ cache {} for app {}", getKeyString(key), info.toString());
 
-            } else if ( value instanceof UsergridAuthenticationInfo ) {
-                UsergridAuthenticationInfo info = (UsergridAuthenticationInfo)value;
-                logger.debug("Put to AUTHC cache {} for app {}", getKeyString(key), info.toString());
+                } else if (value instanceof UsergridAuthenticationInfo) {
+                    UsergridAuthenticationInfo info = (UsergridAuthenticationInfo) value;
+                    logger.debug("Put to AUTHC cache {} for app {}", getKeyString(key), info.toString());
+                }
             }
 
             return ret;
@@ -129,53 +135,68 @@ public class ShiroCache<K, V> implements Cache<K,V> {
     /** get cache for application scope */
     private ScopedCache<String, V> getCacheScope( K key ) {
 
-        if ( key instanceof SimplePrincipalCollection) {
+        UUID applicationId;
 
+        if ( key instanceof SimplePrincipalCollection) {
             SimplePrincipalCollection spc = (SimplePrincipalCollection)key;
 
-            if ( spc.getPrimaryPrincipal() instanceof AdminUserPrincipal ) {
+            if ( spc.getPrimaryPrincipal() instanceof UserPrincipal ) {
+                UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal();
+                applicationId = p.getApplicationId();
+
+            } else  if ( spc.getPrimaryPrincipal() instanceof ApplicationPrincipal ) {
+                ApplicationPrincipal p = (ApplicationPrincipal)spc.getPrimaryPrincipal();
+                applicationId = p.getApplicationId();
 
-                AdminUserPrincipal p = (AdminUserPrincipal) spc.getPrimaryPrincipal();
-                CacheScope scope = new CacheScope(new SimpleId(p.getApplicationId(), "application"));
-                ScopedCache<String, V> scopedCache = cacheFactory.getScopedCache(scope);
-                return scopedCache;
+            } else  if ( spc.getPrimaryPrincipal() instanceof OrganizationPrincipal ) {
+                applicationId = CpNamingUtils.MANAGEMENT_APPLICATION_ID;
 
             } else {
-                throw new RuntimeException("Cannot determine application ID for cache scope");
+                logger.error("Unknown principal type: " + spc.getPrimaryPrincipal().getClass().getSimpleName());
+                throw new RuntimeException("Unknown principal type: "
+                    + spc.getPrimaryPrincipal().getClass().getSimpleName());
             }
 
-        } else if ( key instanceof AdminUserPrincipal ) {
+        } else if ( key instanceof UserPrincipal ) {
+            UserPrincipal p = (UserPrincipal)key;
+            applicationId = p.getApplicationId();
 
-            AdminUserPrincipal p = (AdminUserPrincipal)key;
-            CacheScope scope = new CacheScope(new SimpleId(p.getApplicationId(), "application"));
-            ScopedCache<String, V> scopedCache = cacheFactory.getScopedCache(scope);
-            return scopedCache;
+        } else if ( key instanceof ApplicationPrincipal ) {
+            ApplicationPrincipal p = (ApplicationPrincipal)key;
+            applicationId = p.getApplicationId();
+
+        } else if ( key instanceof OrganizationPrincipal ) {
+            applicationId = CpNamingUtils.MANAGEMENT_APPLICATION_ID;
 
         } else {
-            throw new RuntimeException("Cannot determine application ID for cache scope");
+            logger.error("Unknown key type: " + key.getClass().getSimpleName());
+            throw new RuntimeException("Unknown key type: " + key.getClass().getSimpleName());
         }
+
+        CacheScope scope = new CacheScope(new SimpleId(applicationId, "application"));
+        ScopedCache<String, V> scopedCache = cacheFactory.getScopedCache(scope);
+        return scopedCache;
     }
 
 
-    /** key is the user UUID in string form */
+    /** key is the user UUID in string form + class name of key */
     private String getKeyString( K key ) {
 
         if ( key instanceof SimplePrincipalCollection) {
             SimplePrincipalCollection spc = (SimplePrincipalCollection)key;
 
             if ( spc.getPrimaryPrincipal() instanceof UserPrincipal) {
-                AdminUserPrincipal p = (AdminUserPrincipal) spc.getPrimaryPrincipal();
+                UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal();
                 return p.getUser().getUuid().toString();
             }
         }
 
-        return key.toString();
+        return key.toString() + "_" + key.getClass().getSimpleName();
     }
 
     public void invalidate( UUID applicationId ) {
         CacheScope scope = new CacheScope( new SimpleId(applicationId, "application") );
         ScopedCache cache = cacheFactory.getScopedCache(scope);
         cache.invalidate();
-
     }
 }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
index 453fe54..317b742 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/ApplicationResourceIT.java
@@ -17,7 +17,6 @@
 package org.apache.usergrid.rest.applications;
 
 import com.fasterxml.jackson.databind.JsonNode;
-import com.sun.jersey.api.client.UniformInterfaceException;
 import junit.framework.Assert;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.shiro.codec.Base64;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
index 777b04e..2194222 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/ConnectionResourceTest.java
@@ -17,33 +17,26 @@
 package org.apache.usergrid.rest.applications.collection.users;
 
 
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 import org.apache.usergrid.rest.test.resource.AbstractRestIT;
 import org.apache.usergrid.rest.test.resource.endpoints.CollectionEndpoint;
 import org.apache.usergrid.rest.test.resource.model.ApiResponse;
 import org.apache.usergrid.rest.test.resource.model.Collection;
 import org.apache.usergrid.rest.test.resource.model.Entity;
 import org.apache.usergrid.rest.test.resource.model.QueryParameters;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
-import com.sun.jersey.api.client.UniformInterfaceException;
+import javax.ws.rs.NotFoundException;
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
+import static org.junit.Assert.*;
 
 
 /**
- * // TODO: Document this
- *
- * @author ApigeeCorporation
- * @since 4.0
+ * TODO: Document this
  */
 public class ConnectionResourceTest extends AbstractRestIT {
     private static Logger log = LoggerFactory.getLogger( ConnectionResourceTest.class );
@@ -78,11 +71,11 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         try {
 
-            this.app().collection( "users" ).entity( scott ).collection( "likes" ).collection(
"peeps" ).entity( peep )
-                .get();
+            this.app().collection( "users" ).entity( scott )
+                .collection("likes").collection( "peeps" ).entity( peep ).get();
             fail( "This should throw an exception" );
         }
-        catch ( UniformInterfaceException uie ) {
+        catch ( NotFoundException uie ) {
             // Should return a 404 Not Found
             assertEquals( 404, uie.getResponse().getStatus() );
         }
@@ -103,8 +96,8 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         refreshIndex();
         //create the connection: thing1 likes thing2
-        this.app().collection( "things" ).entity( thing1 ).connection( "likes" ).collection(
"things" ).entity( thing2 )
-            .post();
+        this.app().collection( "things" ).entity( thing1 )
+            .connection("likes").collection( "things" ).entity( thing2 ).post();
         refreshIndex();
 
         //test we have the "likes" in our connection meta data response
@@ -160,8 +153,8 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         refreshIndex();
         //create the connection: thing1 likes thing2
-        this.app().collection( "things" ).entity( thing1 ).connection( "likes" ).collection(
"things" ).entity( thing2 )
-            .post();
+        this.app().collection( "things" ).entity( thing1 )
+            .connection("likes").collection( "things" ).entity( thing2 ).post();
         //delete thing2
         this.app().collection( "things" ).entity( thing2 ).delete();
 
@@ -172,7 +165,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
             thing2 = this.app().collection( "things" ).entity( thing2 ).get();
             fail( "This should throw an exception" );
         }
-        catch ( UniformInterfaceException uie ) {
+        catch ( NotFoundException uie ) {
             // Should return a 404 Not Found
             assertEquals( 404, uie.getResponse().getStatus() );
         }
@@ -196,8 +189,8 @@ public class ConnectionResourceTest extends AbstractRestIT {
 
         refreshIndex();
         //create the connection: thing1 likes thing2
-        this.app().collection( "things" ).entity( thing1 ).connection( "likes" ).collection(
"things" ).entity( thing2 )
-            .post();
+        this.app().collection( "things" ).entity( thing1 )
+            .connection("likes").collection( "things" ).entity( thing2 ).post();
         //delete thing1
         this.app().collection( "things" ).entity( thing1 ).delete();
 
@@ -208,7 +201,7 @@ public class ConnectionResourceTest extends AbstractRestIT {
             thing1 = this.app().collection( "things" ).entity( thing1 ).get();
             fail( "This should throw an exception" );
         }
-        catch ( UniformInterfaceException uie ) {
+        catch ( NotFoundException uie ) {
             // Should return a 404 Not Found
             assertEquals( 404, uie.getResponse().getStatus() );
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
index 5bc2d46..340b75f 100644
--- a/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
+++ b/stack/rest/src/test/java/org/apache/usergrid/rest/applications/collection/users/PermissionsResourceIT.java
@@ -145,7 +145,8 @@ public class PermissionsResourceIT extends AbstractRestIT {
 
         // now delete the group
 
-        ApiResponse response = this.app().collection("groups").entity(groupPath).collection("users").entity(user).delete();
+        ApiResponse response = this.app()
+            .collection("groups").entity(groupPath).collection("users").entity(user).delete();
 
         assertNull( response.getError() );
 
@@ -154,7 +155,8 @@ public class PermissionsResourceIT extends AbstractRestIT {
         //Check that the user no longer exists in the group
         int status = 0;
         try {
-            this.app().collection("users").entity(user).collection("groups").entity( groupPath
).collection( "users" ).entity( user ).get();
+            this.app().collection("users").entity(user)
+                .collection("groups").entity( groupPath ).collection( "users" ).entity( user
).get();
             fail("Should not have been able to retrieve the user as it was deleted");
         }catch (ClientErrorException e){
             status=e.getResponse().getStatus();
@@ -165,9 +167,9 @@ public class PermissionsResourceIT extends AbstractRestIT {
 
 
     /**
-     * For the record, you should NEVER allow the guest role to add roles. This is a gaping
security hole and a VERY BAD
-     * IDEA! That being said, this should technically work, and needs testing.
-     *
+     * For the record, you should NEVER allow the guest role to add roles.
+     * This is a gaping security hole and a VERY BAD IDEA!
+     * That being said, this should technically work, and needs testing.
      * Tests that you can allow a guest role to add additional roles.
      */
     @Test
@@ -193,10 +195,10 @@ public class PermissionsResourceIT extends AbstractRestIT {
     @Test
     public void getNonExistantEntityReturns404() throws Exception {
 
-        //Call a get on a existing entity with no access token and check if we get a 401
+        // Call a get on a existing entity with no access token and check if we get a 401
         try {
             this.app().collection( "roles" ).entity( "guest" ).get( false );
-        }catch(ClientErrorException uie){
+        } catch(ClientErrorException uie){
             assertEquals( 401,uie.getResponse().getStatus() );
         }
 
@@ -204,16 +206,16 @@ public class PermissionsResourceIT extends AbstractRestIT {
         addPermission(  "guest", "get:/**" );
 
 
-        //Call a get on a non existing entity that doesn't need permissions and check it
we get a 404.
+        // Call a get on a non existing entity that doesn't need permissions and check it
we get a 404.
         try {
             this.app().collection( "roles" ).entity( "banana" ).get( false );
-        }catch(ClientErrorException uie){
+        } catch(ClientErrorException uie){
             assertEquals( 404,uie.getResponse().getStatus() );
         }
 
         try {
             this.app().collection( "roles" ).entity( UUIDUtils.newTimeUUID() ).get( false
);
-        }catch(ClientErrorException uie){
+        } catch(ClientErrorException uie){
             assertEquals( 404,uie.getResponse().getStatus() );
         }
     }
@@ -226,13 +228,14 @@ public class PermissionsResourceIT extends AbstractRestIT {
      */
     @Test
     public void applicationPermissions() throws Exception {
-        //Creates two new roles: reviewer1 and reviewer2
+
+        // Creates two new roles: reviewer1 and reviewer2
         createRoleUser( "reviewer1",  "reviewer1@usergrid.com" );
-        createRoleUser(  "reviewer2", "reviewer2@usergrid.com" );
+        createRoleUser( "reviewer2", "reviewer2@usergrid.com" );
 
         Entity  data = new Entity().chainPut("name", "reviewer");
 
-        //Creates a new role "reviewer"
+        // Creates a new role "reviewer"
         Entity node = this.app().collection("roles").post(data);
 
         assertNull( node.getError() );
@@ -251,37 +254,38 @@ public class PermissionsResourceIT extends AbstractRestIT {
         // Grants a permission GET on the guests for the reviews url
         addPermission(  "guest", "get:/reviews/**" );
 
-        //Creates a reviewer group
+        // Creates a reviewer group
         Entity group = new Entity().chainPut( "path", "reviewergroup" ).chainPut("name","reviewergroup");
 
         this.app().collection("groups").post(group);
 
         refreshIndex();
 
-        //Adds the reviewer to the reviewerGroup
+        // Adds the reviewer to the reviewerGroup
         this.app().collection("groups").entity("reviewergroup").collection("roles").entity("reviewer").post();
 
         refreshIndex();
 
-        //Adds reviewer2 user to the reviewergroup
+        // Adds reviewer2 user to the reviewergroup
         this.app().collection("users").entity("reviewer2").collection("groups").entity("reviewergroup").post();
 
         refreshIndex();
 
-        //Adds reviewer1 to the reviewer role
+        // Adds reviewer1 to the reviewer role
         this.app().collection("users").entity("reviewer1").collection("roles").entity("reviewer").post();
 
         refreshIndex();
 
-        //Set the current context to reviewer1
+        // Set the current context to reviewer1
         this.app().token().post(new Token("reviewer1","password"));
 
-        //Post reviews to the reviews collection as reviewer1
-        Entity review =
-                new Entity().chainPut("rating", "4").chainPut("name", "noca").chainPut("review",
"Excellent service and food");
+        // Post reviews to the reviews collection as reviewer1
+        Entity review = new Entity()
+            .chainPut("rating", "4").chainPut("name", "noca").chainPut("review", "Excellent
service and food");
         this.app().collection("reviews").post( review );
 
-        review = new Entity().chainPut ("rating", "4").chainPut( "name", "4peaks").chainPut("review",
"Huge beer selection" );
+        review = new Entity()
+            .chainPut ("rating", "4").chainPut( "name", "4peaks").chainPut("review", "Huge
beer selection" );
         this.app().collection("reviews").post(review);
 
         refreshIndex();
@@ -294,7 +298,7 @@ public class PermissionsResourceIT extends AbstractRestIT {
         assertEquals( "noca",reviews.next().get("name") );
         assertEquals("4peaks", reviews.next().get( "name" ));
 
-        //Try to delete the reviews, but it should fail due to have having delete permission
in the grants.
+        // Try to delete the reviews, but it should fail due to have having delete permission
in the grants.
         int status = 0;
         try {
             this.app().collection("reviews").entity("noca").delete();
@@ -308,7 +312,7 @@ public class PermissionsResourceIT extends AbstractRestIT {
 
         status = 0;
 
-        //Try to delete the reviews, but it should fail due to have having delete permission
in the grants.
+        // Try to delete the reviews, but it should fail due to have having delete permission
in the grants.
         try {
             this.app().collection("reviews").entity("4peaks").delete();
             fail( "this should have failed due to having insufficient permissions" );
@@ -327,10 +331,12 @@ public class PermissionsResourceIT extends AbstractRestIT {
         this.app().token().post(new Token("reviewer2", "password"));
 
         // post 2 reviews as reviewer2
-        review = new Entity().chainPut("rating", "4").chainPut("name", "cowboyciao").chainPut("review",
"Great atmosphoere");
+        review = new Entity()
+            .chainPut("rating", "4").chainPut("name", "cowboyciao").chainPut("review", "Great
atmosphoere");
         this.app().collection("reviews").post(review);
 
-        review = new Entity().chainPut( "rating", "4" ).chainPut("name", "currycorner").chainPut(
"review", "Authentic" );
+        review = new Entity()
+            .chainPut( "rating", "4" ).chainPut("name", "currycorner").chainPut( "review",
"Authentic" );
         this.app().collection("reviews").post(review);
 
         refreshIndex();
@@ -525,7 +531,8 @@ public class PermissionsResourceIT extends AbstractRestIT {
         this.app().token().post(new Token("examplepatient","password"));
         refreshIndex();
         //not working yet, used to be ignored
-//        this.app().collection("users").entity("exampledoctor").connection("following").collection("users").entity("examplepatient").post();
+        //        this.app().collection("users").entity("exampledoctor").connection("following")
+        // .collection("users").entity("examplepatient").post();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
index d11cf9a..65563a8 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/ApplicationInfo.java
@@ -30,9 +30,11 @@ import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
 
 public class ApplicationInfo {
 
-    private final UUID id;
-    private final String name;
+    private UUID id;
+    private String name;
 
+    /** Needed for Jackson since this class is serialized to the Shiro Cache */
+    public ApplicationInfo() {}
 
     /**
      * @param id The application ID (not the same as the ID of the application_info).

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
index 03b798c..ecf0ae2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
+++ b/stack/services/src/main/java/org/apache/usergrid/management/cassandra/ManagementServiceImpl.java
@@ -35,6 +35,9 @@ import org.apache.usergrid.management.*;
 import org.apache.usergrid.management.exceptions.*;
 import org.apache.usergrid.persistence.*;
 import org.apache.usergrid.persistence.Query.Level;
+import org.apache.usergrid.persistence.cache.CacheFactory;
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
 import org.apache.usergrid.persistence.core.scope.ApplicationScope;
 import org.apache.usergrid.persistence.entities.Application;
 import org.apache.usergrid.persistence.entities.Group;
@@ -44,6 +47,7 @@ import org.apache.usergrid.persistence.exceptions.DuplicateUniquePropertyExistsE
 import org.apache.usergrid.persistence.exceptions.EntityNotFoundException;
 import org.apache.usergrid.persistence.index.query.Identifier;
 import org.apache.usergrid.persistence.model.entity.Id;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
 import org.apache.usergrid.security.AuthPrincipalInfo;
 import org.apache.usergrid.security.AuthPrincipalType;
 import org.apache.usergrid.security.crypto.EncryptionService;
@@ -151,6 +155,8 @@ public class ManagementServiceImpl implements ManagementService {
 
     protected EncryptionService encryptionService;
 
+    protected CacheFactory cacheFactory;
+
 
 
     /** Must be constructed with a CassandraClientPool. */
@@ -1658,7 +1664,12 @@ public class ManagementServiceImpl implements ManagementService {
                     + ")</a> created a new application named " + applicationName, null
);
         }
 
-
+        if ( cacheFactory == null ) {
+            cacheFactory = injector.getInstance( CacheFactory.class );
+        }
+        ScopedCache scopedCache = cacheFactory.getScopedCache(
+            new CacheScope( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application"
)));
+        scopedCache.invalidate();
 
         return new ApplicationInfo( applicationId, appInfo.getName() );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/security/oauth/ClientCredentialsInfo.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/oauth/ClientCredentialsInfo.java
b/stack/services/src/main/java/org/apache/usergrid/security/oauth/ClientCredentialsInfo.java
index 1f38bf1..22dc3ca 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/oauth/ClientCredentialsInfo.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/oauth/ClientCredentialsInfo.java
@@ -29,9 +29,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class ClientCredentialsInfo {
 
-    private final String id;
-    private final String secret;
+    private String id;
+    private String secret;
 
+    /** Needed for Jackson since this class is serialized to the Shiro Cache */
+    public ClientCredentialsInfo() {}
 
     public ClientCredentialsInfo( String id, String secret ) {
         this.id = id;

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/AbstractClientCredentials.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/AbstractClientCredentials.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/AbstractClientCredentials.java
index 7e0ec97..cbe57aa 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/AbstractClientCredentials.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/AbstractClientCredentials.java
@@ -23,6 +23,11 @@ import org.apache.usergrid.security.oauth.ClientCredentialsInfo;
 public class AbstractClientCredentials extends ClientCredentialsInfo
         implements ClientCredentials, PrincipalCredentials {
 
+    /** Needed for Jackson since this class is serialized to the Shiro Cache */
+    public AbstractClientCredentials() {
+        super();
+    }
+
     public AbstractClientCredentials( String key, String secret ) {
         super( key, secret );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/ApplicationUserAccessToken.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/ApplicationUserAccessToken.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/ApplicationUserAccessToken.java
index c755a29..5ac9fd5 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/ApplicationUserAccessToken.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/ApplicationUserAccessToken.java
@@ -19,6 +19,9 @@ package org.apache.usergrid.security.shiro.credentials;
 
 public class ApplicationUserAccessToken extends AbstractAccessTokenCredentials implements
ApplicationUserCredentials {
 
+    /** Needed for Jackson since this class is serialized to the Shiro Cache */
+    public ApplicationUserAccessToken() {}
+
     public ApplicationUserAccessToken( String token ) {
         super( token );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/OrganizationClientCredentials.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/OrganizationClientCredentials.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/OrganizationClientCredentials.java
index 066b3ed..ad27dd2 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/OrganizationClientCredentials.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/credentials/OrganizationClientCredentials.java
@@ -19,6 +19,11 @@ package org.apache.usergrid.security.shiro.credentials;
 
 public class OrganizationClientCredentials extends AbstractClientCredentials implements OrganizationCredentials
{
 
+    /** Needed for Jackson since this class is serialized to the Shiro Cache */
+    public OrganizationClientCredentials() {
+        super();
+    }
+
     public OrganizationClientCredentials( String key, String secret ) {
         super( key, secret );
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
index ee322d2..5b6bdbe 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/AbstractConnectionsService.java
@@ -285,7 +285,8 @@ public class AbstractConnectionsService extends AbstractService {
             count = Query.MAX_LIMIT;
             level = Level.ALL_PROPERTIES;
             if (logger.isDebugEnabled()) {
-            	logger.debug("Query does not have more parameters, overwriting limit to: {}
and level to {}" , count, level.name());
+            	logger.debug("Query does not have more parameters, overwriting limit to: {}
and level to {}" ,
+                    count, level.name());
             }
         }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/services/groups/GroupsService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/groups/GroupsService.java
b/stack/services/src/main/java/org/apache/usergrid/services/groups/GroupsService.java
index 3240dc1..4ffe5fb 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/groups/GroupsService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/groups/GroupsService.java
@@ -23,6 +23,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.persistence.EntityRef;
@@ -91,12 +93,16 @@ public class GroupsService extends AbstractPathBasedColllectionService
{
 
     public ServiceResults addGroupRole( UUID groupId, String roleName ) throws Exception
{
         em.addGroupToRole( groupId, roleName );
+        ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+        scopedCache.invalidate();
         return getGroupRoles( groupId );
     }
 
 
     public ServiceResults deleteGroupRole( UUID groupId, String roleName ) throws Exception
{
         em.removeGroupFromRole( groupId, roleName );
+        ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+        scopedCache.invalidate();
         return getGroupRoles( groupId );
     }
 
@@ -149,6 +155,8 @@ public class GroupsService extends AbstractPathBasedColllectionService
{
             }
 
             em.grantGroupPermission( entityRef.getUuid(), permission );
+            ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+            scopedCache.invalidate();
 
             return genericServiceResults().withData( em.getGroupPermissions( entityRef.getUuid()
) );
         }
@@ -216,6 +224,8 @@ public class GroupsService extends AbstractPathBasedColllectionService
{
             for ( String permission : permissions ) {
                 em.revokeGroupPermission( entityRef.getUuid(), permission );
             }
+            ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+            scopedCache.invalidate();
 
             return genericServiceResults().withData( em.getGroupPermissions( entityRef.getUuid()
) );
         }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
b/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
index 42aec04..e2a2002 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/users/UsersService.java
@@ -24,6 +24,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.usergrid.management.UserInfo;
@@ -212,6 +214,8 @@ public class UsersService extends AbstractCollectionService {
             }
 
             em.grantUserPermission( entityRef.getUuid(), permission );
+            ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+            scopedCache.invalidate();
 
             return genericServiceResults().withData( em.getUserPermissions( entityRef.getUuid()
) );
         }
@@ -280,6 +284,9 @@ public class UsersService extends AbstractCollectionService {
                 em.revokeUserPermission( entityRef.getUuid(), permission );
             }
 
+            ScopedCache scopedCache = cacheFactory.getScopedCache(new CacheScope(em.getApplication().asId()));
+            scopedCache.invalidate();
+
             return genericServiceResults().withData( em.getUserPermissions( entityRef.getUuid()
) );
         }
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b9a7ab1c/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
index 2c34deb..1ed10df 100644
--- a/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
+++ b/stack/services/src/test/java/org/apache/usergrid/ServiceApplication.java
@@ -22,6 +22,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.UUID;
 
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
 import org.junit.runner.Description;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;


Mime
View raw message