You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2015/09/16 18:36:23 UTC
usergrid git commit: Beginnings of a new Cache module and classes for
plugging it into Shiro.
Repository: usergrid
Updated Branches:
refs/heads/usergrid-1007-shiro-cache [created] 014986419
Beginnings of a new Cache module and classes for plugging it into Shiro.
Project: http://git-wip-us.apache.org/repos/asf/usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/usergrid/commit/01498641
Tree: http://git-wip-us.apache.org/repos/asf/usergrid/tree/01498641
Diff: http://git-wip-us.apache.org/repos/asf/usergrid/diff/01498641
Branch: refs/heads/usergrid-1007-shiro-cache
Commit: 0149864190ad4d80a509962671a2b50bbf946df5
Parents: 723ee3a
Author: Dave Johnson <sn...@apache.org>
Authored: Wed Sep 16 12:35:16 2015 -0400
Committer: Dave Johnson <sn...@apache.org>
Committed: Wed Sep 16 12:35:16 2015 -0400
----------------------------------------------------------------------
stack/corepersistence/cache/pom.xml | 66 +++++++++++++++++
.../persistence/cache/CacheFactory.java | 27 +++++++
.../usergrid/persistence/cache/CacheScope.java | 38 ++++++++++
.../usergrid/persistence/cache/ScopedCache.java | 33 +++++++++
.../persistence/cache/guice/CacheModule.java | 47 ++++++++++++
.../cache/impl/CacheFactoryImpl.java | 33 +++++++++
.../persistence/cache/impl/ScopedCacheImpl.java | 48 ++++++++++++
.../cache/impl/ScopedCacheSerialization.java | 33 +++++++++
.../impl/ScopedCacheSerializationImpl.java | 42 +++++++++++
.../persistence/cache/ScopedCacheTest.java | 60 +++++++++++++++
stack/corepersistence/pom.xml | 13 ++++
.../rest/security/shiro/ShiroCache.java | 78 ++++++++++++++++++++
.../rest/security/shiro/ShiroCacheManager.java | 40 ++++++++++
.../main/resources/usergrid-rest-context.xml | 5 +-
stack/rest/src/test/resources/log4j.properties | 2 +
15 files changed, 564 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/pom.xml b/stack/corepersistence/cache/pom.xml
new file mode 100644
index 0000000..dc71284
--- /dev/null
+++ b/stack/corepersistence/cache/pom.xml
@@ -0,0 +1,66 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <parent>
+ <artifactId>persistence</artifactId>
+ <groupId>org.apache.usergrid</groupId>
+ <version>2.1.0-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <description>The module for handling cache operations</description>
+
+ <artifactId>cache</artifactId>
+ <name>Usergrid Cache</name>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>${commons.lang.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>${project.version}</version>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>collection</artifactId>
+ <version>${project.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+</project>
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheFactory.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheFactory.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheFactory.java
new file mode 100644
index 0000000..4f0a17d
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheFactory.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.cache;
+
+
+/**
+ * Access to caches.
+ */
+public interface CacheFactory<K, V> {
+
+ ScopedCache<K,V> getScopedCache( CacheScope scope );
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
new file mode 100644
index 0000000..2440adc
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/CacheScope.java
@@ -0,0 +1,38 @@
+/*
+ * 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.persistence.cache;
+
+import org.apache.usergrid.persistence.core.scope.ApplicationScope;
+import org.apache.usergrid.persistence.model.entity.Id;
+
+
+/**
+ * For caches scoped by application.
+ */
+public class CacheScope implements ApplicationScope {
+
+ private Id appId;
+
+ public CacheScope( Id appId ) {
+ this.appId = appId;
+ }
+
+ @Override
+ public Id getApplication() {
+ return appId;
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/ScopedCache.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/ScopedCache.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/ScopedCache.java
new file mode 100644
index 0000000..34fdabd
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/ScopedCache.java
@@ -0,0 +1,33 @@
+/*
+ * 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.persistence.cache;
+
+
+/**
+ * Cache divided into scopes which can be individually invalidated.
+ */
+public interface ScopedCache<K,V> {
+
+ /** Put value into scope with ttl */
+ void put( K key, V value, long ttl );
+
+ /** Get value from scope */
+ V get( K key );
+
+ /** Delete all cache data of all types in this scope */
+ void invalidate();
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
new file mode 100644
index 0000000..7646ad0
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/guice/CacheModule.java
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. 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. For additional information regarding
+ * copyright in this work, please see the NOTICE file in the top level
+ * directory of this distribution.
+ */
+package org.apache.usergrid.persistence.cache.guice;
+
+import com.google.inject.AbstractModule;
+import com.google.inject.TypeLiteral;
+import org.apache.usergrid.persistence.cache.CacheFactory;
+import org.apache.usergrid.persistence.cache.impl.CacheFactoryImpl;
+import org.apache.usergrid.persistence.cache.impl.ScopedCacheSerialization;
+import org.apache.usergrid.persistence.cache.impl.ScopedCacheSerializationImpl;
+
+import java.util.Map;
+
+
+/**
+ * Wire up cache impl.
+ */
+public class CacheModule extends AbstractModule {
+
+ @Override
+ protected void configure() {
+
+ bind( CacheFactory.class ).to( CacheFactoryImpl.class );
+ bind( ScopedCacheSerialization.class ).to( ScopedCacheSerializationImpl.class );
+
+ bind( new TypeLiteral<CacheFactory<String, Map<String, Object>>>() {} )
+ .to( new TypeLiteral<CacheFactoryImpl<String, Map<String, Object>>>() {} );
+
+ }
+}
+
+
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
new file mode 100644
index 0000000..8d35321
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/CacheFactoryImpl.java
@@ -0,0 +1,33 @@
+/*
+ * 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.persistence.cache.impl;
+
+import org.apache.usergrid.persistence.cache.CacheFactory;
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
+
+/**
+ * Access to caches.
+ */
+public class CacheFactoryImpl<K,V> implements CacheFactory<K,V> {
+
+ @Override
+ public ScopedCache<K,V> getScopedCache( CacheScope scope ) {
+ return new ScopedCacheImpl<K,V>(scope);
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
new file mode 100644
index 0000000..ad5b7b4
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheImpl.java
@@ -0,0 +1,48 @@
+/*
+ * 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.persistence.cache.impl;
+
+import org.apache.usergrid.persistence.cache.CacheScope;
+import org.apache.usergrid.persistence.cache.ScopedCache;
+
+
+/**
+ * Cache divided into scopes which can be individually invalidated.
+ */
+public class ScopedCacheImpl<K,V> implements ScopedCache<K,V> {
+
+ CacheScope scope;
+
+ public ScopedCacheImpl( CacheScope scope ) {
+ this.scope = scope;
+ }
+
+ @Override
+ public void put(K key, V value, long ttl) {
+
+ }
+
+ @Override
+ public V get(K key) {
+ return null;
+ }
+
+ @Override
+ public void invalidate() {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
new file mode 100644
index 0000000..02813aa
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerialization.java
@@ -0,0 +1,33 @@
+/*
+ * 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.persistence.cache.impl;
+
+
+import org.apache.usergrid.persistence.cache.CacheScope;
+
+
+/**
+ * Serialize cache to/from Cassandra.
+ */
+public interface ScopedCacheSerialization<K,V> {
+
+ V readValue( CacheScope scope, K key );
+
+ void writeValue( CacheScope scope, K key, V value );
+
+ void invalidate( CacheScope scope );
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/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
new file mode 100644
index 0000000..385c088
--- /dev/null
+++ b/stack/corepersistence/cache/src/main/java/org/apache/usergrid/persistence/cache/impl/ScopedCacheSerializationImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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.persistence.cache.impl;
+
+import org.apache.usergrid.persistence.cache.CacheScope;
+
+
+/**
+ * Serialize cache to Cassandra.
+ */
+public class ScopedCacheSerializationImpl<K,V> implements ScopedCacheSerialization<K,V> {
+
+
+ @Override
+ public V readValue(CacheScope scope, K key) {
+ return null;
+ }
+
+ @Override
+ public void writeValue(CacheScope scope, K key, V value) {
+
+ }
+
+ @Override
+ public void invalidate(CacheScope scope) {
+
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
----------------------------------------------------------------------
diff --git a/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
new file mode 100644
index 0000000..60f34c3
--- /dev/null
+++ b/stack/corepersistence/cache/src/test/java/org/apache/usergrid/persistence/cache/ScopedCacheTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.persistence.cache;
+
+
+import com.google.inject.Inject;
+import org.apache.usergrid.persistence.cache.guice.CacheModule;
+import org.apache.usergrid.persistence.core.test.ITRunner;
+import org.apache.usergrid.persistence.core.test.UseModules;
+import org.apache.usergrid.persistence.model.entity.SimpleId;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Map;
+
+import static junit.framework.TestCase.assertNotNull;
+
+
+@RunWith( ITRunner.class )
+@UseModules( { CacheModule.class } )
+public class ScopedCacheTest {
+
+ @Inject
+ protected CacheFactory<String, Map<String, Object>> cf;
+
+ protected CacheScope scope;
+
+
+ @Before
+ public void mockApp(){
+ this.scope = new CacheScope( new SimpleId( "application" ) );
+ }
+
+
+ @Test
+ public void testBasicOperation() {
+
+ ScopedCache cache = cf.getScopedCache(scope);
+ assertNotNull( cache );
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/stack/corepersistence/pom.xml
----------------------------------------------------------------------
diff --git a/stack/corepersistence/pom.xml b/stack/corepersistence/pom.xml
index 4b47bc0..35764b4 100644
--- a/stack/corepersistence/pom.xml
+++ b/stack/corepersistence/pom.xml
@@ -21,6 +21,18 @@ limitations under the License.
<modelVersion>4.0.0</modelVersion>
<description>Prototype for refactoring persistence of usergrid</description>
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.usergrid</groupId>
+ <artifactId>common</artifactId>
+ <version>2.1.0-SNAPSHOT</version>
+ </dependency>
+ </dependencies>
<groupId>org.apache.usergrid</groupId>
<artifactId>persistence</artifactId>
@@ -86,6 +98,7 @@ limitations under the License.
<module>common</module>
<module>map</module>
<module>queue</module>
+ <module>cache</module>
</modules>
<build>
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/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
new file mode 100644
index 0000000..bdc0e2f
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCache.java
@@ -0,0 +1,78 @@
+/*
+ * 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 org.apache.shiro.cache.Cache;
+import org.apache.shiro.cache.CacheException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.Set;
+
+
+/**
+ * Plugin Usergrid cache for Shiro.
+ */
+public class ShiroCache<K, V> implements Cache<K,V> {
+
+ private static final Logger logger = LoggerFactory.getLogger( ShiroCacheManager.class );
+ private Cache<K,V> wrappedCache;
+
+ public ShiroCache(Cache<K,V> ehc) {
+ this.wrappedCache = ehc;
+ }
+
+ @Override
+ public V get(K key) throws CacheException {
+ V value = wrappedCache.get(key);
+ //logger.debug("SnoopCache: Returning key = {} value = {}", key, value);
+ return value;
+ }
+
+ @Override
+ public V put(K key, V value) throws CacheException {
+ logger.debug( "SnoopCache: Key class={} value value={}",
+ key.getClass().getSimpleName(), value.getClass().getSimpleName() );
+ return wrappedCache.put(key, value);
+ }
+
+ @Override
+ public V remove(K key) throws CacheException {
+ return remove(key);
+ }
+
+ @Override
+ public void clear() throws CacheException {
+ wrappedCache.clear();
+ }
+
+ @Override
+ public int size() {
+ return wrappedCache.size();
+ }
+
+ @Override
+ public Set<K> keys() {
+ return wrappedCache.keys();
+ }
+
+ @Override
+ public Collection<V> values() {
+ return wrappedCache.values();
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/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
new file mode 100644
index 0000000..5aaef9f
--- /dev/null
+++ b/stack/rest/src/main/java/org/apache/usergrid/rest/security/shiro/ShiroCacheManager.java
@@ -0,0 +1,40 @@
+/*
+ * 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 org.apache.shiro.cache.Cache;
+import org.apache.shiro.cache.CacheException;
+import org.apache.shiro.cache.CacheManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Plugin Usergrid cache for Shiro.
+ */
+public class ShiroCacheManager implements CacheManager {
+
+ private static final Logger logger = LoggerFactory.getLogger( ShiroCacheManager.class );
+
+ public ShiroCacheManager() {
+ }
+
+ @Override
+ public <K, V> Cache<K, V> getCache(String name) throws CacheException {
+ return new ShiroCache( null ); // TODO: plugin our cache here
+ }
+}
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/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 d7ff92c..6198e29 100644
--- a/stack/rest/src/main/resources/usergrid-rest-context.xml
+++ b/stack/rest/src/main/resources/usergrid-rest-context.xml
@@ -53,7 +53,10 @@
<property name="realm" ref="realm" />
</bean>
- <bean id="cacheManager" class="org.apache.shiro.cache.MemoryConstrainedCacheManager" />
+ <!--
+ <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" />
http://git-wip-us.apache.org/repos/asf/usergrid/blob/01498641/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 71dd540..43c6e85 100644
--- a/stack/rest/src/test/resources/log4j.properties
+++ b/stack/rest/src/test/resources/log4j.properties
@@ -32,6 +32,8 @@ log4j.logger.org.apache.usergrid=INFO
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
log4j.logger.org.apache.usergrid.persistence.cassandra.DB=WARN