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 2016/12/02 15:08:36 UTC

[1/2] usergrid-qakka git commit: Introducing Apache Shiro to provide Basic Auth for admin user credentials stores in qakka.properties.

Repository: usergrid-qakka
Updated Branches:
  refs/heads/master 2513d0a69 -> 3ad20f3df


Introducing Apache Shiro to provide Basic Auth for admin user credentials stores in qakka.properties.


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

Branch: refs/heads/master
Commit: bd31c02a73d8c3f13aca6b398558a14ce780d002
Parents: 2513d0a
Author: Dave Johnson <sn...@apache.org>
Authored: Fri Dec 2 10:07:44 2016 -0500
Committer: Dave Johnson <sn...@apache.org>
Committed: Fri Dec 2 10:07:44 2016 -0500

----------------------------------------------------------------------
 docs/qakka-example.properties                   | 116 +++++++++++++++++++
 pom.xml                                         |  24 ++++
 .../qakka/api/QakkaStandaloneFig.java           |  52 +++++++++
 .../qakka/api/impl/GuiceFeature.java            |   2 +-
 .../persistence/qakka/api/impl/GuiceModule.java |  49 ++++++++
 .../qakka/api/impl/GuiceShiroModule.java        |  29 +++++
 .../qakka/api/impl/GuiceStartupListener.java    |  71 ++++++++++++
 .../qakka/api/impl/GuiceWebModule.java          |  17 ++-
 .../qakka/api/impl/QakkaStandaloneModule.java   |  49 --------
 .../qakka/api/impl/ShiroAuthRealm.java          |  54 +++++++++
 .../qakka/api/impl/StartupListener.java         |  71 ------------
 src/main/webapp/WEB-INF/web.xml                 |  19 ++-
 .../persistence/qakka/api/AbstractRestTest.java |   4 +-
 .../qakka/api/QueueResourceTest.java            |  17 ++-
 14 files changed, 443 insertions(+), 131 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/docs/qakka-example.properties
----------------------------------------------------------------------
diff --git a/docs/qakka-example.properties b/docs/qakka-example.properties
new file mode 100644
index 0000000..6756042
--- /dev/null
+++ b/docs/qakka-example.properties
@@ -0,0 +1,116 @@
+# 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.
+
+
+# Example Usergrid Qakka Queue System Configuration 
+
+#------------------------------------------------------------------------------
+# Usergrid Cassandra config 
+
+## (Make sure cassandra.hosts is set correctly)
+
+# Comma separated list of Cassandra hosts that this instance should use
+cassandra.hosts=localhost
+
+# Name of keyspace to be used for queues and queue message payload data (must be replicated)
+cassandra.keyspace.application=qakka_test_application
+
+# Name of keyspace to be used for per region queue messages (must not be replicated) 
+cassandra.keyspace.queue-message=qakka_test_queue_messages
+
+# Number of connections to maintain in connection pool
+#cassandra.connections=30
+
+# Timeout pooled connections after this time
+cassandra.timeout.pool=20000
+
+
+#------------------------------------------------------------------------------
+# Usergrid Cluster Config  
+
+## (Make sure all of these are set correctly)
+
+usergrid.cluster_name=Test Cluster
+
+usergrid.cluster.hostname=localhost
+
+# Comma-separated list of regions
+usergrid.cluster.region.list=us-east
+
+# The local region of this Qakka instance
+usergrid.cluster.region.local=us-east
+
+# Comma-separated lists of cluster "seed" nodes each with format {region}:{hostname}
+usergrid.cluster.seeds=us-east:localhost
+
+# Port used for cluster communications.
+usergrid.cluster.port=3545
+
+
+#------------------------------------------------------------------------------
+# Authentication config
+
+queue.auth.enabled=true
+
+queue.auth.username=admin
+
+queue.auth.password=s3cr3t
+
+
+#------------------------------------------------------------------------------
+# Queue System Config
+
+# (You probably don't need to change these values)
+
+# Must be true for Qakka
+queue.standalone=true
+
+# Enable in memory cache for queue reads
+queue.inmemory.cache=true
+
+# Number of actors for processing queue gets/reads
+queue.num.actors=50
+
+# Number of actors for processing queue sends
+queue.sender.num.actors=100
+
+# Number of actors for processing queue writes
+queue.writer.num.actors=100
+
+# Timeout any queue send that takes longer than
+queue.send.timeout.seconds=5
+
+# Timeout any queue get/read that takes longer than
+queue.get.timeout.seconds=5
+
+# Shard size for storing queue messages
+queue.shard.max.size=400000
+
+# Frequency to check for new shards needed
+queue.shard.allocation.check.frequency.millis=1000
+
+# Allocate new shards some time in advance of when they are to be used
+queue.shard.allocation.advance.time.millis=200
+
+# Only write shard counters after this number opf changes
+queue.shard.counter.max-in-memory=100
+
+# Only write message counters after this number of changes 
+queue.message.counter.max-in-memory=100
+
+# On a queue get, wait some time for new messages to arrive
+queue.long.polling.time.millis=2000

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index b2807f6..868f688 100644
--- a/pom.xml
+++ b/pom.xml
@@ -225,6 +225,30 @@
             <artifactId>swagger-jersey2-jaxrs</artifactId>
             <version>1.5.0</version>
         </dependency>
+
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-core</artifactId>
+            <version>1.2.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-web</artifactId>
+            <version>1.2.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-guice</artifactId>
+            <version>1.2.3</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.shiro</groupId>
+            <artifactId>shiro-ehcache</artifactId>
+            <version>1.2.3</version>
+        </dependency>
         
     </dependencies>
 

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/QakkaStandaloneFig.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/QakkaStandaloneFig.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/QakkaStandaloneFig.java
new file mode 100644
index 0000000..9a3e621
--- /dev/null
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/QakkaStandaloneFig.java
@@ -0,0 +1,52 @@
+/*
+ * 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.qakka.api;
+
+import org.safehaus.guicyfig.Default;
+import org.safehaus.guicyfig.FigSingleton;
+import org.safehaus.guicyfig.GuicyFig;
+import org.safehaus.guicyfig.Key;
+
+import java.io.Serializable;
+
+/**
+ * Created by Dave Johnson (snoopdave@apache.org) on 12/1/16.
+ */
+@FigSingleton
+public interface QakkaStandaloneFig extends GuicyFig, Serializable {
+    
+    String QUEUE_AUTH_ENABLED = "queue.auth.enabled";
+    
+    String QUEUE_AUTH_USERNAME = "queue.auth.username";
+    
+    String QUEUE_AUTH_PASSWORD = "queue.auth.password";
+
+    @Key(QUEUE_AUTH_ENABLED)
+    @Default("false")
+    String getAuthEnabled();
+
+    @Key(QUEUE_AUTH_USERNAME)
+    @Default("admin")
+    String getAdminUsername();
+
+    @Key(QUEUE_AUTH_PASSWORD)
+    @Default("admin")
+    String getAdminPassword();
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceFeature.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceFeature.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceFeature.java
index 5131912..419b748 100644
--- a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceFeature.java
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceFeature.java
@@ -43,7 +43,7 @@ public class GuiceFeature implements Feature {
         GuiceBridge.getGuiceBridge().initializeGuiceBridge( serviceLocator );
 
         GuiceIntoHK2Bridge guiceBridge = serviceLocator.getService( GuiceIntoHK2Bridge.class );
-        guiceBridge.bridgeGuiceInjector( StartupListener.INJECTOR );
+        guiceBridge.bridgeGuiceInjector( GuiceStartupListener.INJECTOR );
 
         return true;
     }

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceModule.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceModule.java
new file mode 100644
index 0000000..7ea5bcf
--- /dev/null
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceModule.java
@@ -0,0 +1,49 @@
+/*
+ * 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.qakka.api.impl;
+
+import com.google.inject.AbstractModule;
+import com.netflix.config.ConfigurationManager;
+import org.apache.usergrid.persistence.qakka.QakkaModule;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Created by Dave Johnson (snoopdave@apache.org) on 11/28/16.
+ */
+public class GuiceModule extends AbstractModule {
+    private static final Logger logger = LoggerFactory.getLogger( GuiceModule.class );
+
+    static {
+        try {
+            // load properties from one properties file using Netflix Archaius so that GuicyFig will see them
+            ConfigurationManager.loadCascadedPropertiesFromResources( "qakka" );
+            logger.info("qakka.properties loaded");
+        } catch (Throwable t) {
+            logger.error("Unable to load qakka.properties");
+        }
+    }
+    
+    @Override
+    protected void configure() {
+        install( new QakkaModule() );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceShiroModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceShiroModule.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceShiroModule.java
new file mode 100644
index 0000000..05dbc75
--- /dev/null
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceShiroModule.java
@@ -0,0 +1,29 @@
+/*
+ * 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.qakka.api.impl;
+
+/**
+ * Created by Dave Johnson (snoopdave@apache.org) on 12/1/16.
+ */
+public class GuiceShiroModule extends org.apache.shiro.guice.ShiroModule {
+    
+    protected void configureShiro() {
+        bindRealm().to( ShiroAuthRealm.class );
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceStartupListener.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceStartupListener.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceStartupListener.java
new file mode 100644
index 0000000..f9148c9
--- /dev/null
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceStartupListener.java
@@ -0,0 +1,71 @@
+/*
+ * 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.qakka.api.impl;
+
+import com.google.inject.Guice;
+import com.google.inject.Injector;
+import com.google.inject.servlet.GuiceServletContextListener;
+import com.google.inject.servlet.ServletModule;
+import org.apache.usergrid.persistence.qakka.App;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.bridge.SLF4JBridgeHandler;
+
+import java.util.logging.LogManager;
+
+
+public class GuiceStartupListener extends GuiceServletContextListener {
+    private static final Logger logger = LoggerFactory.getLogger( GuiceStartupListener.class );
+
+    public static App APP = null;
+
+    public static Injector INJECTOR = null;
+
+    static {
+
+        try {
+            LogManager.getLogManager().reset();
+            SLF4JBridgeHandler.install();
+
+            logger.info("Creating injector and installing GuiceWebModule");
+            
+            INJECTOR = Guice.createInjector( new ServletModule() {
+                @Override
+                protected void configureServlets() {
+                    install( new GuiceWebModule() );
+                }
+            } );
+
+            logger.info("Starting Qakka and Akka Cluster...");
+            APP = INJECTOR.getInstance( App.class );
+            APP.start();
+
+        } catch ( Throwable t ) {
+            logger.error("Error static initializing StartupListener class", t);
+        }
+
+    }
+
+    @Override
+    protected Injector getInjector() {
+        return INJECTOR;
+    }
+}
+

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceWebModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceWebModule.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceWebModule.java
index 5ff7b93..fd889b3 100644
--- a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceWebModule.java
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/GuiceWebModule.java
@@ -19,9 +19,12 @@
 package org.apache.usergrid.persistence.qakka.api.impl;
 
 import com.google.inject.AbstractModule;
+import com.netflix.config.ConfigurationManager;
 import org.apache.usergrid.persistence.actorsystem.ActorSystemModule;
 import org.apache.usergrid.persistence.core.guice.CommonModule;
 import org.apache.usergrid.persistence.qakka.QakkaModule;
+import org.apache.usergrid.persistence.qakka.api.QakkaStandaloneFig;
+import org.safehaus.guicyfig.GuicyFigModule;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -32,6 +35,15 @@ import org.slf4j.LoggerFactory;
 public class GuiceWebModule extends AbstractModule {
     private static final Logger logger = LoggerFactory.getLogger( GuiceWebModule.class );
 
+    static {
+        try {
+            // load properties from one properties file using Netflix Archaius so that GuicyFig will see them
+            ConfigurationManager.loadCascadedPropertiesFromResources( "qakka" );
+            logger.info("qakka.properties loaded");
+        } catch (Throwable t) {
+            logger.error("Unable to load qakka.properties");
+        }
+    }
     
     @Override
     protected void configure() {
@@ -39,7 +51,10 @@ public class GuiceWebModule extends AbstractModule {
         
         install( new CommonModule() );
         install( new ActorSystemModule() );
-        install( new QakkaStandaloneModule() );
+        
+        install( new QakkaModule() );
+        install( new GuicyFigModule( QakkaStandaloneFig.class ) );
+        install( new GuiceShiroModule() );
     }
 
 }

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/QakkaStandaloneModule.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/QakkaStandaloneModule.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/QakkaStandaloneModule.java
deleted file mode 100644
index 6357aa8..0000000
--- a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/QakkaStandaloneModule.java
+++ /dev/null
@@ -1,49 +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.persistence.qakka.api.impl;
-
-import com.google.inject.AbstractModule;
-import com.netflix.config.ConfigurationManager;
-import org.apache.usergrid.persistence.qakka.QakkaModule;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-/**
- * Created by Dave Johnson (snoopdave@apache.org) on 11/28/16.
- */
-public class QakkaStandaloneModule extends AbstractModule {
-    private static final Logger logger = LoggerFactory.getLogger( QakkaStandaloneModule.class );
-
-    static {
-        try {
-            // load properties from one properties file using Netflix Archaius so that GuicyFig will see them
-            ConfigurationManager.loadCascadedPropertiesFromResources( "qakka" );
-            logger.info("qakka.properties loaded");
-        } catch (Throwable t) {
-            logger.error("Unable to load qakka.properties");
-        }
-    }
-    
-    @Override
-    protected void configure() {
-        install( new QakkaModule() );
-    }
-}

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/ShiroAuthRealm.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/ShiroAuthRealm.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/ShiroAuthRealm.java
new file mode 100644
index 0000000..d3385d3
--- /dev/null
+++ b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/ShiroAuthRealm.java
@@ -0,0 +1,54 @@
+/*
+ * 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.qakka.api.impl;
+
+import com.google.inject.Inject;
+import org.apache.shiro.authc.AuthenticationException;
+import org.apache.shiro.authc.AuthenticationInfo;
+import org.apache.shiro.authc.AuthenticationToken;
+import org.apache.shiro.authz.AuthorizationInfo;
+import org.apache.shiro.realm.AuthorizingRealm;
+import org.apache.shiro.subject.PrincipalCollection;
+import org.apache.usergrid.persistence.qakka.api.QakkaStandaloneFig;
+
+
+/**
+ * Created by Dave Johnson (snoopdave@apache.org) on 12/1/16.
+ */
+public class ShiroAuthRealm extends AuthorizingRealm {
+   
+    private QakkaStandaloneFig qakkaStandaloneFig;
+  
+    
+    @Inject 
+    public ShiroAuthRealm( QakkaStandaloneFig qakkaStandaloneFig ) {
+        this.qakkaStandaloneFig = qakkaStandaloneFig; 
+    }
+    
+    @Override
+    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principals) {
+        return null;
+    }
+
+    @Override
+    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/StartupListener.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/StartupListener.java b/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/StartupListener.java
deleted file mode 100644
index d5f0953..0000000
--- a/src/main/java/org/apache/usergrid/persistence/qakka/api/impl/StartupListener.java
+++ /dev/null
@@ -1,71 +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.persistence.qakka.api.impl;
-
-import com.google.inject.Guice;
-import com.google.inject.Injector;
-import com.google.inject.servlet.GuiceServletContextListener;
-import com.google.inject.servlet.ServletModule;
-import org.apache.usergrid.persistence.qakka.App;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.slf4j.bridge.SLF4JBridgeHandler;
-
-import java.util.logging.LogManager;
-
-
-public class StartupListener extends GuiceServletContextListener {
-    private static final Logger logger = LoggerFactory.getLogger( StartupListener.class );
-
-    public static App APP = null;
-
-    public static Injector INJECTOR = null;
-
-    static {
-
-        try {
-            LogManager.getLogManager().reset();
-            SLF4JBridgeHandler.install();
-
-            logger.info("Creating injector and installing GuiceWebModule");
-            
-            INJECTOR = Guice.createInjector( new ServletModule() {
-                @Override
-                protected void configureServlets() {
-                    install( new GuiceWebModule() );
-                }
-            } );
-
-            logger.info("Starting Qakka and Akka Cluster...");
-            APP = INJECTOR.getInstance( App.class );
-            APP.start();
-
-        } catch ( Throwable t ) {
-            logger.error("Error static initializing StartupListener class", t);
-        }
-
-    }
-
-    @Override
-    protected Injector getInjector() {
-        return INJECTOR;
-    }
-}
-

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/main/webapp/WEB-INF/web.xml
----------------------------------------------------------------------
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
index b875bac..5176b0c 100644
--- a/src/main/webapp/WEB-INF/web.xml
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -24,8 +24,17 @@
     <display-name>qakka</display-name>
 
     <listener>
-        <listener-class>org.apache.usergrid.persistence.qakka.api.impl.StartupListener</listener-class>
+        <listener-class>org.apache.usergrid.persistence.qakka.api.impl.GuiceStartupListener</listener-class>
     </listener>
+
+    <listener>
+        <listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
+    </listener>
+
+    <filter>
+        <filter-name>ShiroFilter</filter-name>
+        <filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
+    </filter>
  
     <filter>
         <filter-name>qakka</filter-name>
@@ -48,5 +57,13 @@
         <filter-name>qakka</filter-name>
         <url-pattern>/api/*</url-pattern>
     </filter-mapping>
+
+    <filter-mapping>
+        <filter-name>ShiroFilter</filter-name>
+        <url-pattern>/api</url-pattern>
+        <dispatcher>REQUEST</dispatcher>
+        <dispatcher>FORWARD</dispatcher>
+        <dispatcher>INCLUDE</dispatcher>
+    </filter-mapping>
     
 </web-app>

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/test/java/org/apache/usergrid/persistence/qakka/api/AbstractRestTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/usergrid/persistence/qakka/api/AbstractRestTest.java b/src/test/java/org/apache/usergrid/persistence/qakka/api/AbstractRestTest.java
index c3c9c5b..18a3ac7 100644
--- a/src/test/java/org/apache/usergrid/persistence/qakka/api/AbstractRestTest.java
+++ b/src/test/java/org/apache/usergrid/persistence/qakka/api/AbstractRestTest.java
@@ -22,7 +22,7 @@ package org.apache.usergrid.persistence.qakka.api;
 
 import org.apache.usergrid.persistence.qakka.KeyspaceDropper;
 import org.apache.usergrid.persistence.qakka.api.impl.JerseyResourceConfig;
-import org.apache.usergrid.persistence.qakka.api.impl.StartupListener;
+import org.apache.usergrid.persistence.qakka.api.impl.GuiceStartupListener;
 import org.glassfish.jersey.test.DeploymentContext;
 import org.glassfish.jersey.test.JerseyTest;
 import org.glassfish.jersey.test.ServletDeploymentContext;
@@ -57,7 +57,7 @@ abstract public class AbstractRestTest extends JerseyTest {
     @Override
     protected DeploymentContext configureDeployment() {
         if ( context == null ) {
-            context = ServletDeploymentContext.builder( configure() ) .addListener( StartupListener.class ).build();
+            context = ServletDeploymentContext.builder( configure() ) .addListener( GuiceStartupListener.class ).build();
         }
         return context;
     }

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/bd31c02a/src/test/java/org/apache/usergrid/persistence/qakka/api/QueueResourceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/usergrid/persistence/qakka/api/QueueResourceTest.java b/src/test/java/org/apache/usergrid/persistence/qakka/api/QueueResourceTest.java
index 517902d..e5356f9 100644
--- a/src/test/java/org/apache/usergrid/persistence/qakka/api/QueueResourceTest.java
+++ b/src/test/java/org/apache/usergrid/persistence/qakka/api/QueueResourceTest.java
@@ -28,7 +28,7 @@ import com.google.inject.Injector;
 import org.apache.commons.lang.RandomStringUtils;
 import org.apache.usergrid.persistence.qakka.QakkaFig;
 import org.apache.usergrid.persistence.qakka.URIStrategy;
-import org.apache.usergrid.persistence.qakka.api.impl.StartupListener;
+import org.apache.usergrid.persistence.qakka.api.impl.GuiceStartupListener;
 import org.apache.usergrid.persistence.qakka.core.QueueMessage;
 import org.junit.Assert;
 import org.junit.Test;
@@ -46,6 +46,11 @@ import java.util.*;
 import static org.junit.Assert.fail;
 
 
+/**
+ * Tests for the Qakka REST API.
+ * 
+ * FYI: There is also a complete set of Qakka tests in the Usergrid Queue modulea.
+ */
 public class QueueResourceTest extends AbstractRestTest {
     private static final Logger logger = LoggerFactory.getLogger( QueueResourceTest.class );
 
@@ -65,7 +70,7 @@ public class QueueResourceTest extends AbstractRestTest {
                 .post( Entity.entity( queueMap, MediaType.APPLICATION_JSON_TYPE));
 
         Assert.assertEquals( 201, response.getStatus() );
-        URIStrategy uriStrategy = StartupListener.INJECTOR.getInstance( URIStrategy.class );
+        URIStrategy uriStrategy = GuiceStartupListener.INJECTOR.getInstance( URIStrategy.class );
         Assert.assertEquals( uriStrategy.queueURI( queueName ).toString(), response.getHeaderString( "location" ) );
 
         // get queue by name
@@ -94,7 +99,7 @@ public class QueueResourceTest extends AbstractRestTest {
                 .post( Entity.entity( queueMap, MediaType.APPLICATION_JSON_TYPE));
 
         Assert.assertEquals( 201, response.getStatus() );
-        URIStrategy uriStrategy = StartupListener.INJECTOR.getInstance( URIStrategy.class );
+        URIStrategy uriStrategy = GuiceStartupListener.INJECTOR.getInstance( URIStrategy.class );
         Assert.assertEquals( uriStrategy.queueURI( queueName ).toString(), response.getHeaderString( "location" ) );
 
         // delete queue without confirm = true, should fail with bad request
@@ -379,7 +384,7 @@ public class QueueResourceTest extends AbstractRestTest {
 
             // wait for remaining of the messages to timeout
 
-            QakkaFig qakkaFig = StartupListener.INJECTOR.getInstance( QakkaFig.class );
+            QakkaFig qakkaFig = GuiceStartupListener.INJECTOR.getInstance( QakkaFig.class );
             Thread.sleep( 2 * qakkaFig.getQueueTimeoutSeconds() * 1000 );
 
             // now, the remaining messages cannot be acked because they timed out
@@ -404,7 +409,7 @@ public class QueueResourceTest extends AbstractRestTest {
     @Test
     public void testConvertDelayParameter() {
 
-        Injector injector = StartupListener.INJECTOR;
+        Injector injector = GuiceStartupListener.INJECTOR;
         QueueResource queueResource = injector.getInstance( QueueResource.class );
 
         Assert.assertEquals( 0L, queueResource.convertDelayParameter( "" ).longValue() );
@@ -423,7 +428,7 @@ public class QueueResourceTest extends AbstractRestTest {
     @Test
     public void testConvertExpirationParameter() {
 
-        Injector injector = StartupListener.INJECTOR;
+        Injector injector = GuiceStartupListener.INJECTOR;
         QueueResource queueResource = injector.getInstance( QueueResource.class );
 
         Assert.assertNull( queueResource.convertExpirationParameter( "" ) );


[2/2] usergrid-qakka git commit: Reorganize and document the properties file.

Posted by sn...@apache.org.
Reorganize and document the properties file.


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

Branch: refs/heads/master
Commit: 3ad20f3df86c2697017b84619e1b3feed6602366
Parents: bd31c02
Author: Dave Johnson <sn...@apache.org>
Authored: Fri Dec 2 10:08:18 2016 -0500
Committer: Dave Johnson <sn...@apache.org>
Committed: Fri Dec 2 10:08:18 2016 -0500

----------------------------------------------------------------------
 docs/qakka-example.properties       |  5 +++
 src/test/resources/qakka.properties | 56 ++++++++++++++++++++++----------
 2 files changed, 43 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/3ad20f3d/docs/qakka-example.properties
----------------------------------------------------------------------
diff --git a/docs/qakka-example.properties b/docs/qakka-example.properties
index 6756042..818db89 100644
--- a/docs/qakka-example.properties
+++ b/docs/qakka-example.properties
@@ -18,6 +18,11 @@
 
 # Example Usergrid Qakka Queue System Configuration 
 
+# When Qakka starts up it looks for this file, which must be named 
+# "qakka.properties" in the Java classpath. On Tomcat you should be 
+# able to place this file in the lib directory.
+
+
 #------------------------------------------------------------------------------
 # Usergrid Cassandra config 
 

http://git-wip-us.apache.org/repos/asf/usergrid-qakka/blob/3ad20f3d/src/test/resources/qakka.properties
----------------------------------------------------------------------
diff --git a/src/test/resources/qakka.properties b/src/test/resources/qakka.properties
index 94bfeff..6a13ad8 100644
--- a/src/test/resources/qakka.properties
+++ b/src/test/resources/qakka.properties
@@ -16,53 +16,73 @@
 # under the License.
 
 
-# Properties for JUnit tests
+# Usergrid Qakka Queue System JUnit test configuration 
 
-queue.standalone=true
+#------------------------------------------------------------------------------
+# Usergrid Cassandra config 
+
+cassandra.hosts=localhost
+
+cassandra.keyspace.application=qakka_test_application
+
+cassandra.keyspace.queue-message=qakka_test_queue_messages
+
+cassandra.keyspace-drop-and-create=true
+
+#cassandra.connections=30
+
+cassandra.timeout.pool=20000
+
+
+#------------------------------------------------------------------------------
+# Usergrid Cluster Config  
 
 usergrid.cluster_name=Test Cluster
 
 usergrid.cluster.hostname=localhost
 
-# Comma-separated list of regions to be considered
 usergrid.cluster.region.list=us-east
 
-# The regions of this local instance of Usergrid
 usergrid.cluster.region.local=us-east
 
-# Comma-separated lists of cluster seeds each with format {region}:{hostname}
 usergrid.cluster.seeds=us-east:localhost
 
-# Port used for cluster communications.
-usergrid.cluster.port=3545
+usergrid.cluster.port=4551
+
+
+#------------------------------------------------------------------------------
+# Authentication config
+
+queue.auth.enabled=false
+
+
+#------------------------------------------------------------------------------
+# Queue System Config
+
+queue.standalone=true
 
 queue.inmemory.cache=true
 
 queue.num.actors=50
+
 queue.sender.num.actors=100
+
 queue.writer.num.actors=100
 
 queue.send.timeout.seconds=5
+
 queue.get.timeout.seconds=5
 
 # set shard size and times low for testing purposes
 queue.shard.max.size=10
+
 queue.shard.allocation.check.frequency.millis=1000
+
 queue.shard.allocation.advance.time.millis=200
 
 # set low for testing purposes
 queue.shard.counter.max-in-memory=50
+
 queue.message.counter.max-in-memory=50
 
 queue.long.polling.time.millis=2000
-
-cassandra.hosts=localhost
-
-cassandra.keyspace.application=qakka_test_application
-
-cassandra.keyspace.queue-message=qakka_test_queue_messages
-
-cassandra.keyspace-drop-and-create=true
-
-#cassandra.connections=30
-cassandra.timeout.pool=20000