You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2010/05/17 23:28:45 UTC

svn commit: r945389 - in /incubator/shiro/trunk: core/src/main/java/org/apache/shiro/realm/text/ core/src/main/java/org/apache/shiro/session/mgt/ core/src/main/resources/org/apache/shiro/realm/text/ core/src/test/java/org/apache/shiro/config/ core/src/...

Author: lhazlewood
Date: Mon May 17 21:28:44 2010
New Revision: 945389

URL: http://svn.apache.org/viewvc?rev=945389&view=rev
Log:
Removing empty directories and unused files.  shiro-default-users.properties was removed because we don't default Realms anymore - that is the one part of Shiro that must be explicitly provided by end-users.  Updated test cases to use the IniRealm instead as it is easier to configure than a PropertiesRealm.

Added:
    incubator/shiro/trunk/core/src/test/resources/org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties
Removed:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/session/mgt/LocalSessionManager.java
    incubator/shiro/trunk/core/src/main/resources/org/apache/shiro/realm/text/default-shiro-users.properties
    incubator/shiro/trunk/samples/aspectj/src/main/java/org/apache/shiro/sample/bank/
    incubator/shiro/trunk/samples/aspectj/src/test/java/org/apache/shiro/sample/bank/
    incubator/shiro/trunk/samples/spring/src/main/java/org/apache/shiro/samples/spring/ui/
    incubator/shiro/trunk/web/src/main/java/org/apache/shiro/web/attr/
    incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/attr/
Modified:
    incubator/shiro/trunk/core/src/main/java/org/apache/shiro/realm/text/PropertiesRealm.java
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniSecurityManagerFactoryTest.java
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java
    incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java
    incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java

Modified: incubator/shiro/trunk/core/src/main/java/org/apache/shiro/realm/text/PropertiesRealm.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/main/java/org/apache/shiro/realm/text/PropertiesRealm.java?rev=945389&r1=945388&r2=945389&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/main/java/org/apache/shiro/realm/text/PropertiesRealm.java (original)
+++ incubator/shiro/trunk/core/src/main/java/org/apache/shiro/realm/text/PropertiesRealm.java Mon May 17 21:28:44 2010
@@ -42,17 +42,9 @@ import java.util.concurrent.TimeUnit;
  * This class allows processing of a single .properties file for user, role, and
  * permission configuration.
  * <p/>
- * For convenience, if the {@link #setResourcePath resourcePath} attribute is not set, this class defaults to lookup
- * the properties file definition from {@code classpath:shiro-users.properties} (root of the classpath).
- * This allows you to use this implementation by simply defining this file at the classpath root, instantiating this
- * class, and then calling {@link #init init()}.
- * <p/>
- * Or, you may of course specify any other file path using the {@code url:}, {@code file:}, or {@code classpath:}
- * prefixes.
- * <p/>
- * If none of these are specified, and the shiro-users.properties is not included at the root of the classpath,
- * a default failsafe configuration will be used.  This is not recommended as it only contains a few simple users and
- * roles which are probably of little value to production applications.
+ * The {@link #setResourcePath resourcePath} <em>MUST</em> be set before this realm can be initialized.  You
+ * can specify any resource path supported by
+ * {@link ResourceUtils#getInputStreamForPath(String) ResourceUtils.getInputStreamForPath} method.
  * <p/>
  * The Properties format understood by this implementation must be written as follows:
  * <p/>
@@ -103,7 +95,6 @@ public class PropertiesRealm extends Tex
     private static final String USERNAME_PREFIX = "user.";
     private static final String ROLENAME_PREFIX = "role.";
     private static final String DEFAULT_RESOURCE_PATH = "classpath:shiro-users.properties";
-    private static final String FAILSAFE_RESOURCE_PATH = "classpath:org/apache/shiro/realm/text/default-shiro-users.properties";
 
     /*-------------------------------------------
     |    I N S T A N C E   V A R I A B L E S    |
@@ -118,7 +109,6 @@ public class PropertiesRealm extends Tex
 
     public PropertiesRealm() {
         super();
-        onInit();
     }
 
     /*--------------------------------------------
@@ -149,8 +139,6 @@ public class PropertiesRealm extends Tex
     }
 
     /**
-     * TODO: RELOADING IS CURRENTLY DISABLED
-     * <p/>
      * Sets the interval in seconds at which the property file will be checked for changes and reloaded.  If this is
      * set to zero or less, property file reloading will be disabled.  If it is set to 1 or greater, then a
      * separate thread will be created to monitor the propery file for changes and reload the file if it is updated.
@@ -173,16 +161,7 @@ public class PropertiesRealm extends Tex
     }
 
     protected void afterRoleCacheSet() {
-        try {
-            loadProperties();
-        } catch (Exception e) {
-            if (log.isInfoEnabled()) {
-                log.info("Unable to find a shiro-users.properties file at location [" + this.resourcePath + "].  " +
-                        "Defaulting to Shiro's failsafe properties file (demo use only).");
-            }
-            this.resourcePath = FAILSAFE_RESOURCE_PATH;
-            loadProperties();
-        }
+        loadProperties();
         //we can only determine if files have been modified at runtime (not classpath entries or urls), so only
         //start the thread in this case:
         if (this.resourcePath.startsWith(ResourceUtils.FILE_PREFIX) && scheduler != null) {

Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniSecurityManagerFactoryTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniSecurityManagerFactoryTest.java?rev=945389&r1=945388&r2=945389&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniSecurityManagerFactoryTest.java (original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/config/IniSecurityManagerFactoryTest.java Mon May 17 21:28:44 2010
@@ -92,6 +92,8 @@ public class IniSecurityManagerFactoryTe
         Ini ini = new Ini();
         Ini.Section section = ini.addSection(IniSecurityManagerFactory.MAIN_SECTION_NAME);
         section.put("propsRealm", PropertiesRealm.class.getName());
+        section.put("propsRealm.resourcePath",
+                "classpath:org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties");
 
         IniSecurityManagerFactory factory = new IniSecurityManagerFactory(ini);
         SecurityManager sm = factory.getInstance();

Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java?rev=945389&r1=945388&r2=945389&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java (original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/DefaultSecurityManagerTest.java Mon May 17 21:28:44 2010
@@ -21,7 +21,8 @@ package org.apache.shiro.mgt;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.AuthenticationToken;
 import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.realm.text.PropertiesRealm;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.realm.text.IniRealm;
 import org.apache.shiro.session.ExpiredSessionException;
 import org.apache.shiro.session.Session;
 import org.apache.shiro.session.mgt.AbstractValidatingSessionManager;
@@ -46,7 +47,11 @@ public class DefaultSecurityManagerTest 
     @Before
     public void setup() {
         sm = new DefaultSecurityManager();
-        sm.setRealm(new PropertiesRealm());
+        Ini ini = new Ini();
+        Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME);
+        section.put("guest", "guest, guest");
+        section.put("lonestarr", "vespa, goodguy");
+        sm.setRealm(new IniRealm(ini));
         SecurityUtils.setSecurityManager(sm);
     }
 

Modified: incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java?rev=945389&r1=945388&r2=945389&view=diff
==============================================================================
--- incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java (original)
+++ incubator/shiro/trunk/core/src/test/java/org/apache/shiro/mgt/VMSingletonDefaultSecurityManagerTest.java Mon May 17 21:28:44 2010
@@ -21,7 +21,8 @@ package org.apache.shiro.mgt;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.AuthenticationToken;
 import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.realm.text.PropertiesRealm;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.realm.text.IniRealm;
 import org.apache.shiro.subject.Subject;
 import org.apache.shiro.util.ThreadContext;
 import org.junit.After;
@@ -50,7 +51,10 @@ public class VMSingletonDefaultSecurityM
     @Test
     public void testVMSingleton() {
         DefaultSecurityManager sm = new DefaultSecurityManager();
-        sm.setRealm(new PropertiesRealm());
+        Ini ini = new Ini();
+        Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME);
+        section.put("guest", "guest");
+        sm.setRealm(new IniRealm(ini));
         SecurityUtils.setSecurityManager(sm);
 
         Subject subject = SecurityUtils.getSubject();

Added: incubator/shiro/trunk/core/src/test/resources/org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/core/src/test/resources/org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties?rev=945389&view=auto
==============================================================================
--- incubator/shiro/trunk/core/src/test/resources/org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties (added)
+++ incubator/shiro/trunk/core/src/test/resources/org/apache/shiro/config/IniSecurityManagerFactoryTest.propsRealm.properties Mon May 17 21:28:44 2010
@@ -0,0 +1,30 @@
+#
+# 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.
+#
+
+# ------------------------------
+# Users and their assigned roles
+# ------------------------------
+# user 'root' with password 'secret' and the 'root' role
+user.root = secret,root
+
+# -------------------------------
+# Roles with assigned permissions
+# -------------------------------
+# 'root' role has all permissions, indicated by the wildcard '*'
+role.root = *

Modified: incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java?rev=945389&r1=945388&r2=945389&view=diff
==============================================================================
--- incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java (original)
+++ incubator/shiro/trunk/web/src/test/java/org/apache/shiro/web/DefaultWebSecurityManagerTest.java Mon May 17 21:28:44 2010
@@ -19,7 +19,8 @@
 package org.apache.shiro.web;
 
 import org.apache.shiro.authc.UsernamePasswordToken;
-import org.apache.shiro.realm.text.PropertiesRealm;
+import org.apache.shiro.config.Ini;
+import org.apache.shiro.realm.text.IniRealm;
 import org.apache.shiro.session.ExpiredSessionException;
 import org.apache.shiro.session.Session;
 import org.apache.shiro.session.mgt.AbstractSessionManager;
@@ -51,7 +52,10 @@ public class DefaultWebSecurityManagerTe
     public void setup() {
         sm = new DefaultWebSecurityManager();
         sm.setSessionMode(DefaultWebSecurityManager.NATIVE_SESSION_MODE);
-        sm.setRealm(new PropertiesRealm());
+        Ini ini = new Ini();
+        Ini.Section section = ini.addSection(IniRealm.USERS_SECTION_NAME);
+        section.put("lonestarr", "vespa");
+        sm.setRealm(new IniRealm(ini));
     }
 
     @After