usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [08/24] usergrid git commit: Couple more steps to hook in our cache for Shiro.
Date Wed, 21 Oct 2015 20:36:25 GMT
Couple more steps to hook in our cache for Shiro.


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

Branch: refs/heads/master
Commit: b75e8325bd980b3769a64a86e6ec5e3ed956213b
Parents: dc7681f
Author: Dave Johnson <snoopdave@apache.org>
Authored: Tue Sep 22 16:27:30 2015 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Tue Sep 22 16:27:30 2015 -0400

----------------------------------------------------------------------
 .../main/resources/usergrid-rest-context.xml    |  5 ---
 stack/rest/src/test/resources/log4j.properties  |  6 +--
 .../apache/usergrid/security/shiro/Realm.java   | 42 ++++++++++++++++----
 .../resources/usergrid-services-context.xml     |  9 ++++-
 4 files changed, 44 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/b75e8325/stack/rest/src/main/resources/usergrid-rest-context.xml
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/resources/usergrid-rest-context.xml b/stack/rest/src/main/resources/usergrid-rest-context.xml
index 6198e29..5e925bf 100644
--- a/stack/rest/src/main/resources/usergrid-rest-context.xml
+++ b/stack/rest/src/main/resources/usergrid-rest-context.xml
@@ -53,11 +53,6 @@
 		<property name="realm" ref="realm" />
 	</bean>
 
-    <!--
-    <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>
-    -->
-    <bean id="cacheManager" class="org.apache.usergrid.rest.security.shiro.ShiroCacheManager"
/>
-
     <bean id="jobServiceBootstrap" class="org.apache.usergrid.rest.JobServiceBoostrap"
/>
 
 	<!-- override the task executor -->

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b75e8325/stack/rest/src/test/resources/log4j.properties
----------------------------------------------------------------------
diff --git a/stack/rest/src/test/resources/log4j.properties b/stack/rest/src/test/resources/log4j.properties
index 41d2a94..3c532ae 100644
--- a/stack/rest/src/test/resources/log4j.properties
+++ b/stack/rest/src/test/resources/log4j.properties
@@ -26,17 +26,15 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
 log4j.appender.stdout.layout.ConversionPattern=%d %p (%t) %c{1} - %m%n
 
-log4j.logger.org.glassfish=DEBUG
+log4j.logger.org.glassfish=ERROR
 log4j.logger.org.apache.shiro=DEBUG
-log4j.logger.org.apache.usergrid=INFO
-log4j.logger.org.apache.usergrid.persistence.cache=DEBUG
+#log4j.logger.org.apache.usergrid.persistence.cache=DEBUG
 
 #log4j.logger.org.apache.usergrid.cassandra=DEBUG
 #log4j.logger.org.apache.usergrid.persistence.cassandra=DEBUG
 log4j.category.org.apache=ERROR
 log4j.category.org.apache.usergrid=WARN
 log4j.category.org.apache.usergrid.rest=INFO
-log4j.category.org.apache.shiro=DEBUG
 log4j.category.org.apache.usergrid.rest.security.shiro=DEBUG
 
 log4j.logger.org.apache.usergrid.persistence.cassandra.CounterUtils=ERROR

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b75e8325/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
index a793fdb..013fd70 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/Realm.java
@@ -114,19 +114,23 @@ public class Realm extends AuthorizingRealm {
     public Realm( CacheManager cacheManager ) {
         super( cacheManager );
         setCredentialsMatcher( new AllowAllCredentialsMatcher() );
-        setPermissionResolver( new CustomPermissionResolver() );
+        setPermissionResolver(new CustomPermissionResolver());
+        setCachingEnabled(true);
+        setAuthenticationCachingEnabled(true);
     }
 
 
     public Realm( CredentialsMatcher matcher ) {
-        super( new AllowAllCredentialsMatcher() );
-        setPermissionResolver( new CustomPermissionResolver() );
+        super(new AllowAllCredentialsMatcher());
+        setPermissionResolver(new CustomPermissionResolver());
     }
 
 
     public Realm( CacheManager cacheManager, CredentialsMatcher matcher ) {
         super( cacheManager, new AllowAllCredentialsMatcher() );
         setPermissionResolver( new CustomPermissionResolver() );
+        setCachingEnabled(true);
+        setAuthenticationCachingEnabled(true);
     }
 
 
@@ -136,7 +140,7 @@ public class Realm extends AuthorizingRealm {
             logger.debug( "Replacing {} with AllowAllCredentialsMatcher", credentialsMatcher
);
             credentialsMatcher = new AllowAllCredentialsMatcher();
         }
-        super.setCredentialsMatcher( credentialsMatcher );
+        super.setCredentialsMatcher(credentialsMatcher);
     }
 
 
@@ -146,7 +150,7 @@ public class Realm extends AuthorizingRealm {
             logger.debug( "Replacing {} with AllowAllCredentialsMatcher", permissionResolver
);
             permissionResolver = new CustomPermissionResolver();
         }
-        super.setPermissionResolver( permissionResolver );
+        super.setPermissionResolver(permissionResolver);
     }
 
 
@@ -499,7 +503,7 @@ public class Realm extends AuthorizingRealm {
         Subject currentUser = SecurityUtils.getSubject();
         Session session = currentUser.getSession();
         session.setAttribute( "applications", applicationSet );
-        session.setAttribute( "organizations", organizationSet );
+        session.setAttribute("organizations", organizationSet);
         if ( organization != null ) {
             session.setAttribute( "organization", organization );
         }
@@ -540,7 +544,7 @@ public class Realm extends AuthorizingRealm {
 
     public static void role( SimpleAuthorizationInfo info, PrincipalIdentifier principal,
String role ) {
         logger.debug( "Principal {} added to role: {}", principal, role );
-        info.addRole( role );
+        info.addRole(role);
     }
 
 
@@ -566,6 +570,30 @@ public class Realm extends AuthorizingRealm {
 
 
     @Override
+    public boolean isAuthorizationCachingEnabled() {
+        return getCacheManager() != null;
+    }
+
+    public boolean isAuthenticationCachingEnabled() {
+        return getCacheManager() != null;
+    }
+
+    @Override
+    public boolean isCachingEnabled() {
+        return getCacheManager() != null;
+    }
+
+    @Override
+    public void setCacheManager(CacheManager cacheManager) {
+        super.setCacheManager(cacheManager);
+    }
+
+    @Override
+    public CacheManager getCacheManager() {
+        return super.getCacheManager();
+    }
+
+    @Override
     public boolean supports( AuthenticationToken token ) {
         return token instanceof PrincipalCredentialsToken;
     }

http://git-wip-us.apache.org/repos/asf/usergrid/blob/b75e8325/stack/services/src/main/resources/usergrid-services-context.xml
----------------------------------------------------------------------
diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml
index 74c4de2..60a4e92 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -31,8 +31,14 @@
 	<!--  scan for security -->
 	<context:component-scan base-package="org.apache.usergrid.security.crypto"  />
 
+    <!--
+    <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>
+    -->
+    <bean id="cacheManager" class="org.apache.usergrid.rest.security.shiro.ShiroCacheManager"
/>
+
 	<bean id="realm" class="org.apache.usergrid.security.shiro.Realm">
-		<property name="name" value="realm" />
+        <property name="name" value="realm" />
+        <property name="cacheManager" ref="cacheManager" />
 	</bean>
 
 	<bean id="securityManager" class="org.apache.shiro.mgt.DefaultSecurityManager">
@@ -48,7 +54,6 @@
 		<property name="arguments" ref="securityManager" />
 	</bean>
 
-
 	<bean id="taskExecutor" class="org.springframework.core.task.SyncTaskExecutor"/>
 
 	<bean id="tokenService" class="org.apache.usergrid.security.tokens.cassandra.TokenServiceImpl">


Mime
View raw message