usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g...@apache.org
Subject [22/50] [abbrv] usergrid git commit: Invalidate ShiroCache when admin user added to org.
Date Mon, 02 May 2016 17:54:53 GMT
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/5beb53bc
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/5beb53bc
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/5beb53bc

Branch: refs/heads/USERGRID-1246-MASTER
Commit: 5beb53bcb267f33a1fcab84afb70c91e8cb5e75b
Parents: 423c865
Author: Dave Johnson <snoopdave@apache.org>
Authored: Wed Apr 20 14:43:06 2016 -0400
Committer: George Reyes <grey@apache.org>
Committed: Mon May 2 10:49:34 2016 -0700

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


http://git-wip-us.apache.org/repos/asf/usergrid/blob/5beb53bc/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();
+    }
 }


Mime
View raw message