usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From snoopd...@apache.org
Subject [39/39] usergrid git commit: Move ShiroCacheManager to Services module and fix RoleIT test problem with token "inactivity" feature
Date Wed, 14 Oct 2015 16:54:35 GMT
Move ShiroCacheManager to Services module and fix RoleIT test problem with token "inactivity"
feature


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

Branch: refs/heads/usergrid-1007-shiro-cache
Commit: 542763185f9749c3851e512860851eed2f684987
Parents: c02df0b
Author: Dave Johnson <snoopdave@apache.org>
Authored: Wed Oct 14 12:53:46 2015 -0400
Committer: Dave Johnson <snoopdave@apache.org>
Committed: Wed Oct 14 12:53:46 2015 -0400

----------------------------------------------------------------------
 .../rest/security/shiro/ShiroCache.java         | 198 -------------------
 .../rest/security/shiro/ShiroCacheManager.java  | 116 -----------
 .../usergrid/security/shiro/ShiroCache.java     | 171 ++++++++++++++++
 .../security/shiro/ShiroCacheManager.java       | 114 +++++++++++
 .../shiro/principals/OrganizationPrincipal.java |   8 +-
 .../shiro/principals/PrincipalIdentifier.java   |   3 +
 .../resources/usergrid-services-context.xml     |   2 +-
 .../org/apache/usergrid/management/RoleIT.java  |   7 +-
 .../resources/usergrid-custom-test.properties   |   3 +
 9 files changed, 302 insertions(+), 320 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/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
deleted file mode 100644
index 7fb7422..0000000
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.rest.security.shiro;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-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.model.entity.SimpleId;
-import org.apache.usergrid.security.shiro.UsergridAuthenticationInfo;
-import org.apache.usergrid.security.shiro.UsergridAuthorizationInfo;
-import org.apache.usergrid.security.shiro.principals.*;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Set;
-import java.util.UUID;
-
-
-/**
- * Plugin Usergrid cache for Shiro.
- */
-public class ShiroCache<K, V> implements Cache<K,V> {
-
-    private static final Logger logger = LoggerFactory.getLogger( ShiroCache.class );
-
-    private final CacheFactory<String, V> cacheFactory;
-    private final TypeReference typeRef;
-    private final Integer cacheTtl;
-
-    public ShiroCache( TypeReference typeRef, CacheFactory<String, V> cacheFactory,
Integer cacheTtl ) {
-        this.typeRef = typeRef;
-        this.cacheFactory = cacheFactory;
-        this.cacheTtl = cacheTtl;
-    }
-
-    @Override
-    public V get(K key) throws CacheException {
-        if ( cacheTtl == 0 ) return null;
-
-        ScopedCache<String, V> scopedCache = getCacheScope(key);
-        if ( scopedCache != null ) {
-            V value = scopedCache.get(getKeyString(key), typeRef);
-
-            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 == null) {
-                    logger.debug("Got NULL from cache app {} for key {}", getKeyString(key),
key.toString());
-                }
-            }
-
-            return value;
-        }
-        return null;
-    }
-
-    @Override
-    public V put(K key, V value) throws CacheException {
-        if ( cacheTtl == 0 ) return null;
-
-        ScopedCache<String, V> scopedCache = getCacheScope(key);
-        if ( scopedCache != null ) {
-            V ret = scopedCache.put(getKeyString(key), value, cacheTtl);
-
-            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());
-                }
-            }
-
-            return ret;
-        }
-        return null;
-    }
-
-    @Override
-    public V remove(K key) throws CacheException {
-        if ( cacheTtl == 0 ) return null;
-
-        ScopedCache<String, V> scopedCache = getCacheScope(key);
-        if ( scopedCache != null ) {
-            scopedCache.remove( getKeyString(key) );
-        }
-        return null;
-    }
-
-    @Override
-    public void clear() throws CacheException {
-        // no-op: Usergrid logic will invalidate cache as necessary
-    }
-
-    @Override
-    public int size() {
-        return 0; // TODO?
-    }
-
-    @Override
-    public Set<K> keys() {
-        return Collections.EMPTY_SET;
-    }
-
-    @Override
-    public Collection<V> values() {
-        return Collections.EMPTY_LIST;
-    }
-
-
-    /** get cache for application scope */
-    private ScopedCache<String, V> getCacheScope( K key ) {
-
-        // get the principal
-
-        PrincipalIdentifier principal;
-        if ( key instanceof SimplePrincipalCollection) {
-            SimplePrincipalCollection spc = (SimplePrincipalCollection) key;
-            principal = (PrincipalIdentifier) spc.getPrimaryPrincipal();
-
-        } else {
-            principal = (PrincipalIdentifier)key;
-        }
-
-        // get the id for the scope
-
-        UUID applicationId;
-        if ( principal instanceof UserPrincipal ) {
-            UserPrincipal p = (UserPrincipal)principal;
-            applicationId = p.getApplicationId();
-
-        } else if ( principal instanceof ApplicationPrincipal ) {
-            ApplicationPrincipal p = (ApplicationPrincipal)principal;
-            applicationId = p.getApplicationId();
-
-        } else if ( principal instanceof OrganizationPrincipal ) {
-            applicationId = CpNamingUtils.MANAGEMENT_APPLICATION_ID;
-
-        } else if ( principal instanceof ApplicationGuestPrincipal) {
-            ApplicationGuestPrincipal p = (ApplicationGuestPrincipal)principal;
-            applicationId = p.getApplicationId();
-
-        } else {
-            logger.error("Unknown key type: " + key.getClass().getSimpleName());
-            throw new RuntimeException("Unknown key type: " + principal.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 + class name of key */
-    private String getKeyString( K key ) {
-
-        if ( key instanceof SimplePrincipalCollection) {
-            SimplePrincipalCollection spc = (SimplePrincipalCollection)key;
-
-            if ( spc.getPrimaryPrincipal() instanceof UserPrincipal) {
-                UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal();
-                return p.getUser().getUuid().toString();
-            }
-        }
-
-        return key.toString() + "_" + key.getClass().getSimpleName();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCacheManager.java
----------------------------------------------------------------------
diff --git a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCacheManager.java
b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCacheManager.java
deleted file mode 100644
index 416dcd2..0000000
--- a/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCacheManager.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.usergrid.rest.security.shiro;
-
-import com.fasterxml.jackson.core.type.TypeReference;
-import com.google.inject.Injector;
-import com.google.inject.Key;
-import com.google.inject.TypeLiteral;
-import org.apache.shiro.cache.Cache;
-import org.apache.shiro.cache.CacheException;
-import org.apache.shiro.cache.CacheManager;
-import org.apache.usergrid.persistence.cache.CacheFactory;
-import org.apache.usergrid.security.shiro.UsergridAuthenticationInfo;
-import org.apache.usergrid.security.shiro.UsergridAuthorizationInfo;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Properties;
-
-
-/**
- * Plugin Usergrid cache for Shiro.
- */
-public class ShiroCacheManager implements CacheManager {
-
-    private static final Logger logger = LoggerFactory.getLogger(ShiroCacheManager.class);
-
-    @Autowired
-    private Injector injector;
-
-    private Map<String, ShiroCache> caches = new HashMap<>();
-
-    private Properties properties;
-
-    private Integer cacheTtl = null; // specified in seconds
-
-    private static final String CACHE_TTL_PROPERTY_NAME = "usergrid.auth.cache.time-to-live";
-
-
-    public ShiroCacheManager() {}
-
-
-    @Override
-    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
-        ShiroCache shiroCache = caches.get(name);
-
-        if (shiroCache == null) {
-
-            if ("realm.authorizationCache".equals(name)) {
-
-                TypeLiteral typeLit = new TypeLiteral<CacheFactory<String, UsergridAuthorizationInfo>>()
{};
-
-                shiroCache = new ShiroCache(
-                    new TypeReference<UsergridAuthorizationInfo>() {},
-                    (CacheFactory)injector.getInstance( Key.get(typeLit) ),
-                    getCacheTtl());
-
-            } else if ("realm.authenticationCache".equals(name)) {
-
-                TypeLiteral typeLit = new TypeLiteral<CacheFactory<String, UsergridAuthenticationInfo>>()
{};
-
-                shiroCache = new ShiroCache(
-                    new TypeReference<UsergridAuthenticationInfo>() {},
-                    (CacheFactory)injector.getInstance( Key.get(typeLit) ),
-                    getCacheTtl());
-
-            } else {
-                logger.error("Unknown Shiro Cache name: " + name);
-                throw new RuntimeException("Unknown Shiro Cache name: " + name);
-            }
-
-            caches.put(name, shiroCache);
-        }
-        return shiroCache;
-    }
-
-    private Integer getCacheTtl() {
-        if ( cacheTtl == null ) {
-            String cacheTtlString = properties.getProperty(CACHE_TTL_PROPERTY_NAME);
-            try {
-                cacheTtl = Integer.parseInt(cacheTtlString);
-            } catch ( NumberFormatException nfe ) {
-                cacheTtl = 3600;
-                logger.error("Error reading property {}, setting cache TTL to {} seconds",
CACHE_TTL_PROPERTY_NAME);
-            }
-        }
-        return cacheTtl;
-    }
-
-    public Properties getProperties() {
-        return properties;
-    }
-
-    @Autowired
-    public void setProperties(Properties properties) {
-        this.properties = properties;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/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
new file mode 100644
index 0000000..67da9cf
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCache.java
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.security.shiro;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+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.model.entity.SimpleId;
+import org.apache.usergrid.security.shiro.principals.*;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Set;
+import java.util.UUID;
+
+
+/**
+ * Plugin Usergrid cache for Shiro.
+ */
+public class ShiroCache<K, V> implements Cache<K,V> {
+
+    private static final Logger logger = LoggerFactory.getLogger( ShiroCache.class );
+
+    private final CacheFactory<String, V> cacheFactory;
+    private final TypeReference typeRef;
+    private final Integer cacheTtl;
+
+    public ShiroCache( TypeReference typeRef, CacheFactory<String, V> cacheFactory,
Integer cacheTtl ) {
+        this.typeRef = typeRef;
+        this.cacheFactory = cacheFactory;
+        this.cacheTtl = cacheTtl;
+    }
+
+    @Override
+    public V get(K key) throws CacheException {
+        if ( cacheTtl == 0 ) return null;
+
+        ScopedCache<String, V> scopedCache = getCacheScope(key);
+        if ( scopedCache != null ) {
+            V value = scopedCache.get(getKeyString(key), typeRef);
+
+            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 == null) {
+                    logger.debug("Got NULL from cache app {} for key {}", getKeyString(key),
key.toString());
+                }
+            }
+
+            return value;
+        }
+        return null;
+    }
+
+    @Override
+    public V put(K key, V value) throws CacheException {
+        if ( cacheTtl == 0 ) return null;
+
+        ScopedCache<String, V> scopedCache = getCacheScope(key);
+        if ( scopedCache != null ) {
+            V ret = scopedCache.put(getKeyString(key), value, cacheTtl);
+
+            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());
+                }
+            }
+
+            return ret;
+        }
+        return null;
+    }
+
+    @Override
+    public V remove(K key) throws CacheException {
+        if ( cacheTtl == 0 ) return null;
+
+        ScopedCache<String, V> scopedCache = getCacheScope(key);
+        if ( scopedCache != null ) {
+            scopedCache.remove( getKeyString(key) );
+        }
+        return null;
+    }
+
+    @Override
+    public void clear() throws CacheException {
+        // no-op: Usergrid logic will invalidate cache as necessary
+    }
+
+    @Override
+    public int size() {
+        return 0; // TODO?
+    }
+
+    @Override
+    public Set<K> keys() {
+        return Collections.EMPTY_SET;
+    }
+
+    @Override
+    public Collection<V> values() {
+        return Collections.EMPTY_LIST;
+    }
+
+
+    /** get cache for application scope */
+    private ScopedCache<String, V> getCacheScope( K key ) {
+
+        PrincipalIdentifier principal;
+        if ( key instanceof SimplePrincipalCollection) {
+            SimplePrincipalCollection spc = (SimplePrincipalCollection) key;
+            principal = (PrincipalIdentifier) spc.getPrimaryPrincipal();
+
+        } else {
+            principal = (PrincipalIdentifier)key;
+        }
+
+        CacheScope scope = new CacheScope(new SimpleId(principal.getApplicationId(), "application"));
+        ScopedCache<String, V> scopedCache = cacheFactory.getScopedCache(scope);
+        return scopedCache;
+    }
+
+
+    /** 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) {
+                UserPrincipal p = (UserPrincipal) spc.getPrimaryPrincipal();
+                return p.getUser().getUuid().toString();
+            }
+        }
+
+        return key.toString() + "_" + key.getClass().getSimpleName();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCacheManager.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCacheManager.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCacheManager.java
new file mode 100644
index 0000000..17d5cce
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/ShiroCacheManager.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.usergrid.security.shiro;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.google.inject.Injector;
+import com.google.inject.Key;
+import com.google.inject.TypeLiteral;
+import org.apache.shiro.cache.Cache;
+import org.apache.shiro.cache.CacheException;
+import org.apache.shiro.cache.CacheManager;
+import org.apache.usergrid.persistence.cache.CacheFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Properties;
+
+
+/**
+ * Plugin Usergrid cache for Shiro.
+ */
+public class ShiroCacheManager implements CacheManager {
+
+    private static final Logger logger = LoggerFactory.getLogger(ShiroCacheManager.class);
+
+    @Autowired
+    private Injector injector;
+
+    private Map<String, ShiroCache> caches = new HashMap<>();
+
+    private Properties properties;
+
+    private Integer cacheTtl = null; // specified in seconds
+
+    private static final String CACHE_TTL_PROPERTY_NAME = "usergrid.auth.cache.time-to-live";
+
+
+    public ShiroCacheManager() {}
+
+
+    @Override
+    public <K, V> Cache<K, V> getCache(String name) throws CacheException {
+        ShiroCache shiroCache = caches.get(name);
+
+        if (shiroCache == null) {
+
+            if ("realm.authorizationCache".equals(name)) {
+
+                TypeLiteral typeLit = new TypeLiteral<CacheFactory<String, UsergridAuthorizationInfo>>()
{};
+
+                shiroCache = new ShiroCache(
+                    new TypeReference<UsergridAuthorizationInfo>() {},
+                    (CacheFactory)injector.getInstance( Key.get(typeLit) ),
+                    getCacheTtl());
+
+            } else if ("realm.authenticationCache".equals(name)) {
+
+                TypeLiteral typeLit = new TypeLiteral<CacheFactory<String, UsergridAuthenticationInfo>>()
{};
+
+                shiroCache = new ShiroCache(
+                    new TypeReference<UsergridAuthenticationInfo>() {},
+                    (CacheFactory)injector.getInstance( Key.get(typeLit) ),
+                    getCacheTtl());
+
+            } else {
+                logger.error("Unknown Shiro Cache name: " + name);
+                throw new RuntimeException("Unknown Shiro Cache name: " + name);
+            }
+
+            caches.put(name, shiroCache);
+        }
+        return shiroCache;
+    }
+
+    private Integer getCacheTtl() {
+        if ( cacheTtl == null ) {
+            String cacheTtlString = properties.getProperty(CACHE_TTL_PROPERTY_NAME);
+            try {
+                cacheTtl = Integer.parseInt(cacheTtlString);
+            } catch ( NumberFormatException nfe ) {
+                cacheTtl = 3600;
+                logger.error("Error reading property {}, setting cache TTL to {} seconds",
CACHE_TTL_PROPERTY_NAME);
+            }
+        }
+        return cacheTtl;
+    }
+
+    public Properties getProperties() {
+        return properties;
+    }
+
+    @Autowired
+    public void setProperties(Properties properties) {
+        this.properties = properties;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/OrganizationPrincipal.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/OrganizationPrincipal.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/OrganizationPrincipal.java
index 5c815f0..30510c3 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/OrganizationPrincipal.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/OrganizationPrincipal.java
@@ -22,6 +22,7 @@ import java.util.UUID;
 
 import com.google.common.collect.HashBiMap;
 import org.apache.commons.lang.StringUtils;
+import org.apache.usergrid.corepersistence.util.CpNamingUtils;
 import org.apache.usergrid.management.ApplicationInfo;
 import org.apache.usergrid.management.ManagementService;
 import org.apache.usergrid.management.OrganizationInfo;
@@ -60,13 +61,18 @@ public class OrganizationPrincipal extends PrincipalIdentifier {
     }
 
     @Override
+    public UUID getApplicationId() {
+        return CpNamingUtils.MANAGEMENT_APPLICATION_ID;
+    }
+
+    @Override
     public void grant(
         UsergridAuthorizationInfo info,
         EntityManagerFactory emf,
         ManagementService management,
         TokenService tokens) {
 
-        // OrganizationPricipals are usually only through OAuth
+        // OrganizationPrincipals are usually only through OAuth
         // They have access to a single organization
 
         Map<UUID, String> organizationSet = HashBiMap.create();

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/PrincipalIdentifier.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/PrincipalIdentifier.java
b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/PrincipalIdentifier.java
index eb89d1e..b3df022 100644
--- a/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/PrincipalIdentifier.java
+++ b/stack/services/src/main/java/org/apache/usergrid/security/shiro/principals/PrincipalIdentifier.java
@@ -72,6 +72,9 @@ public abstract class PrincipalIdentifier {
         this.accessTokenCredentials = accessTokenCredentials;
     }
 
+    /** Return application UUID or null if none is associated with this prinicipal */
+
+    public abstract UUID getApplicationId();
 
     public abstract void grant(
         UsergridAuthorizationInfo info,

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/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 7e51d32..a3c353f 100644
--- a/stack/services/src/main/resources/usergrid-services-context.xml
+++ b/stack/services/src/main/resources/usergrid-services-context.xml
@@ -34,7 +34,7 @@
     <!--
     <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager"/>
     -->
-    <bean id="cacheManager" class="org.apache.usergrid.rest.security.shiro.ShiroCacheManager">
+    <bean id="cacheManager" class="org.apache.usergrid.security.shiro.ShiroCacheManager">
         <property name="properties" ref="properties" />
     </bean>
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
----------------------------------------------------------------------
diff --git a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
index 783e67c..e2a1941 100644
--- a/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
+++ b/stack/services/src/test/java/org/apache/usergrid/management/RoleIT.java
@@ -58,8 +58,7 @@ public class RoleIT {
     public void testRoleInactivity() throws Exception {
 
         OrganizationOwnerInfo ooi = setup.getMgmtSvc()
-                                         .createOwnerAndOrganization( "RoleIT", "edanuff5",
"Ed Anuff", "ed@anuff.com5",
-                                                 "test", true, false );
+            .createOwnerAndOrganization( "RoleIT", "edanuff5", "Ed Anuff", "ed@anuff.com5",
"test", true, false );
 
         OrganizationInfo organization = ooi.getOrganization();
 
@@ -74,7 +73,7 @@ public class RoleIT {
         properties.put( "activated", true );
         User user = em.create( User.ENTITY_TYPE, User.class, properties );
 
-        em.createRole( "logged-in", "Logged In", 1000 );
+        em.createRole( "logged-in", "Logged In", 2000 );
         setup.getEntityIndex().refresh(em.getApplicationId());
         em.addUserToRole( user.getUuid(), "logged-in" );
 
@@ -92,7 +91,7 @@ public class RoleIT {
 
         LOG.info( "Has role \"logged-in\"" );
 
-        Thread.sleep( 1000 );
+        Thread.sleep( 2100 );
 
         subject.login( token );
 

http://git-wip-us.apache.org/repos/asf/usergrid/blob/54276318/stack/services/src/test/resources/usergrid-custom-test.properties
----------------------------------------------------------------------
diff --git a/stack/services/src/test/resources/usergrid-custom-test.properties b/stack/services/src/test/resources/usergrid-custom-test.properties
index 5a20871..1c3d190 100644
--- a/stack/services/src/test/resources/usergrid-custom-test.properties
+++ b/stack/services/src/test/resources/usergrid-custom-test.properties
@@ -39,3 +39,6 @@ usergrid.use.default.queue=true
 
 # This property is required to be set and cannot be defaulted anywhere
 usergrid.cluster_name=usergrid
+
+# specified in seconds
+usergrid.auth.cache.time-to-live=1


Mime
View raw message