You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by mr...@apache.org on 2016/06/02 17:07:36 UTC

[18/54] [abbrv] usergrid git commit: Invalidate ShiroCache when admin user added to org.

Invalidate ShiroCache when admin user added to org.


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

Branch: refs/heads/apm
Commit: 4aa73aa49f72ee578d4ec5a9a8f98bdc6be0b739
Parents: 6488b05
Author: Dave Johnson <sn...@apache.org>
Authored: Wed Apr 20 14:43:06 2016 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Wed Apr 20 14:43:06 2016 -0400

----------------------------------------------------------------------
 .../cassandra/ManagementServiceImpl.java        | 93 ++++++++++----------
 1 file changed, 48 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/4aa73aa4/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 a586c26..73a56c8 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
@@ -17,7 +17,6 @@
 package org.apache.usergrid.management.cassandra;
 
 
-import com.google.common.base.Optional;
 import com.google.common.base.Preconditions;
 import com.google.common.cache.CacheBuilder;
 import com.google.common.cache.CacheLoader;
@@ -88,6 +87,8 @@ import static org.apache.commons.codec.digest.DigestUtils.sha;
 import static org.apache.commons.lang.StringUtils.isBlank;
 import static org.apache.usergrid.locking.LockHelper.getUniqueUpdateLock;
 import static org.apache.usergrid.management.AccountCreationProps.*;
+import static org.apache.usergrid.management.OrganizationConfigProps.ORGPROPERTIES_ADMIN_SYSADMIN_EMAIL;
+import static org.apache.usergrid.management.OrganizationConfigProps.WorkflowUrl;
 import static org.apache.usergrid.persistence.CredentialsInfo.getCredentialsSecret;
 import static org.apache.usergrid.persistence.Schema.*;
 import static org.apache.usergrid.persistence.Schema.PROPERTY_UUID;
@@ -107,7 +108,6 @@ import static org.apache.usergrid.utils.ConversionUtils.uuid;
 import static org.apache.usergrid.utils.ListUtils.anyNull;
 import static org.apache.usergrid.utils.MapUtils.hashMap;
 import static org.apache.usergrid.utils.PasswordUtils.mongoPassword;
-import static org.apache.usergrid.management.OrganizationConfigProps.*;
 
 
 public class ManagementServiceImpl implements ManagementService {
@@ -173,6 +173,37 @@ public class ManagementServiceImpl implements ManagementService {
     protected LocalShiroCache localShiroCache;
 
 
+    private LoadingCache<UUID, OrganizationConfig> orgConfigByAppCache = CacheBuilder.newBuilder().maximumSize( 1000 )
+        .expireAfterWrite( Long.valueOf( System.getProperty(ORG_CONFIG_CACHE_PROP, "30000") ) , TimeUnit.MILLISECONDS)
+        .build( new CacheLoader<UUID, OrganizationConfig>() {
+            public OrganizationConfig load( UUID applicationInfoId ) {
+
+                try {
+
+                    if (applicationInfoId != null && applicationInfoId != CpNamingUtils.MANAGEMENT_APPLICATION_ID) {
+
+                        final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
+
+                        Results r = em.getSourceEntities(
+                            new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
+                            ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES);
+
+                        Group org = (Group) r.getEntity();
+                        if (org != null) {
+                            Map<Object, Object> entityProperties = em.getDictionaryAsMap(org, ORGANIZATION_CONFIG_DICTIONARY);
+                            return new OrganizationConfig(orgConfigProperties, org.getUuid(), org.getPath(), entityProperties, false);
+                        }
+                    }
+
+                    return new OrganizationConfig(orgConfigProperties);
+
+                } catch (Exception e) {
+                    return new OrganizationConfig(orgConfigProperties);
+                }
+            }}
+        );
+
+
 
     /** Must be constructed with a CassandraClientPool. */
     public ManagementServiceImpl(Injector injector) {
@@ -1678,6 +1709,8 @@ public class ManagementServiceImpl implements ManagementService {
         em.addToCollection(new SimpleEntityRef(Group.ENTITY_TYPE, organization.getUuid()), "users",
             new SimpleEntityRef(User.ENTITY_TYPE, user.getUuid()));
 
+        invalidateManagementAppAuthCache();
+
         if ( email ) {
             sendAdminUserInvitedEmail( user, organization );
         }
@@ -1713,6 +1746,8 @@ public class ManagementServiceImpl implements ManagementService {
 
         em.removeFromCollection(new SimpleEntityRef(Group.ENTITY_TYPE, organizationId), "users",
             new SimpleEntityRef(User.ENTITY_TYPE, userId));
+
+        invalidateManagementAppAuthCache();
     }
 
 
@@ -1773,15 +1808,13 @@ public class ManagementServiceImpl implements ManagementService {
                     + ")</a> created a new application named " + applicationName, null );
         }
 
-        ScopedCache scopedCache = cacheFactory.getScopedCache(
-            new CacheScope( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application" )));
-        scopedCache.invalidate();
-        localShiroCache.invalidateAll();
+        invalidateManagementAppAuthCache();
 
         return new ApplicationInfo( applicationId, appInfo.getName() );
     }
 
 
+
     @Override
     public void deleteApplication(UUID applicationId) throws Exception {
         emf.deleteApplication( applicationId );
@@ -1835,10 +1868,7 @@ public class ManagementServiceImpl implements ManagementService {
                     + ")</a> restored an application named " + appInfo.getName(), null );
         }
 
-        ScopedCache scopedCache = cacheFactory.getScopedCache(
-            new CacheScope( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application" )));
-        scopedCache.invalidate();
-        localShiroCache.invalidateAll();
+        invalidateManagementAppAuthCache();
 
         return new ApplicationInfo( applicationId, appInfo.getName() );
     }
@@ -2274,6 +2304,8 @@ public class ManagementServiceImpl implements ManagementService {
     public void activateAdminUser( UUID userId ) throws Exception {
         EntityManager em = emf.getEntityManager( smf.getManagementAppId() );
         em.setProperty( new SimpleEntityRef( User.ENTITY_TYPE, userId ), "activated", true );
+
+        invalidateManagementAppAuthCache();
     }
 
 
@@ -3424,39 +3456,10 @@ public class ManagementServiceImpl implements ManagementService {
     }
 
 
-    private LoadingCache<UUID, OrganizationConfig> orgConfigByAppCache =
-        CacheBuilder.newBuilder().maximumSize( 1000 )
-            .expireAfterWrite( Long.valueOf( System.getProperty(ORG_CONFIG_CACHE_PROP, "30000") ) , TimeUnit.MILLISECONDS)
-            .build( new CacheLoader<UUID, OrganizationConfig>() {
-                public OrganizationConfig load( UUID applicationInfoId ) {
-
-                    try {
-
-                        if (applicationInfoId != null && applicationInfoId != CpNamingUtils.MANAGEMENT_APPLICATION_ID) {
-
-                            final EntityManager em = emf.getEntityManager(smf.getManagementAppId());
-
-                            Results r = em.getSourceEntities(
-                                new SimpleEntityRef(CpNamingUtils.APPLICATION_INFO, applicationInfoId),
-                                ORG_APP_RELATIONSHIP, Group.ENTITY_TYPE, Level.ALL_PROPERTIES);
-
-                            Group org = (Group) r.getEntity();
-
-                            if (org != null) {
-                                Map<Object, Object> entityProperties = em.getDictionaryAsMap(org, ORGANIZATION_CONFIG_DICTIONARY);
-                                return new OrganizationConfig(orgConfigProperties, org.getUuid(), org.getPath(), entityProperties, false);
-                            }
-
-                        }
-
-                        return new OrganizationConfig(orgConfigProperties);
-
-                    }catch (Exception e){
-
-                        return new OrganizationConfig(orgConfigProperties);
-
-                    }
-                }}
-            );
-
+    private void invalidateManagementAppAuthCache() {
+        ScopedCache scopedCache = cacheFactory.getScopedCache(
+            new CacheScope( new SimpleId( CpNamingUtils.MANAGEMENT_APPLICATION_ID, "application" )));
+        scopedCache.invalidate();
+        localShiroCache.invalidateAll();
+    }
 }