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 2013/03/16 22:44:46 UTC

svn commit: r1457316 - in /shiro/branches/1.2.x/core/src: main/java/org/apache/shiro/config/ test/groovy/org/apache/shiro/config/ test/java/org/apache/shiro/config/

Author: lhazlewood
Date: Sat Mar 16 21:44:46 2013
New Revision: 1457316

URL: http://svn.apache.org/r1457316
Log:
SHIRO-413: ensured LifecycleUtils.init is called for objects created by the ReflectionBuilder.  Removed this duplicate functionality from the IniSecurityManagerFactory (don't want to call init twice)

Added:
    shiro/branches/1.2.x/core/src/test/java/org/apache/shiro/config/InitializableBean.java
Modified:
    shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
    shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
    shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy

Modified: shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java?rev=1457316&r1=1457315&r2=1457316&view=diff
==============================================================================
--- shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java (original)
+++ shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/IniSecurityManagerFactory.java Sat Mar 16 21:44:46 2013
@@ -31,7 +31,12 @@ import org.apache.shiro.util.Nameable;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * A {@link Factory} that creates {@link SecurityManager} instances based on {@link Ini} configuration.
@@ -132,23 +137,9 @@ public class IniSecurityManagerFactory e
             }
         }
 
-        initRealms(securityManager);
-
         return securityManager;
     }
 
-    private void initRealms(SecurityManager securityManager) {
-        Collection<Realm> realms = getRealms(securityManager);
-        if (!CollectionUtils.isEmpty(realms)) {
-            LifecycleUtils.init(realms);
-        }
-    }
-
-    private Collection<Realm> getRealms(SecurityManager securityManager) {
-        assertRealmSecurityManager(securityManager);
-        return ((RealmSecurityManager) securityManager).getRealms();
-    }
-
     protected Map<String, ?> createDefaults(Ini ini, Ini.Section mainSection) {
         Map<String, Object> defaults = new LinkedHashMap<String, Object>();
 

Modified: shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/ReflectionBuilder.java
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/ReflectionBuilder.java?rev=1457316&r1=1457315&r2=1457316&view=diff
==============================================================================
--- shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/ReflectionBuilder.java (original)
+++ shiro/branches/1.2.x/core/src/main/java/org/apache/shiro/config/ReflectionBuilder.java Sat Mar 16 21:44:46 2013
@@ -125,6 +125,9 @@ public class ReflectionBuilder {
             }
         }
 
+        //SHIRO-413: init method must be called for constructed objects that are Initializable
+        LifecycleUtils.init(objects.values());
+
         return objects;
     }
 

Modified: shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy?rev=1457316&r1=1457315&r2=1457316&view=diff
==============================================================================
--- shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy (original)
+++ shiro/branches/1.2.x/core/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy Sat Mar 16 21:44:46 2013
@@ -376,6 +376,17 @@ class ReflectionBuilderTest extends Groo
         assertEquals(2, children.size());
     }
 
+    //asserts SHIRO-413
+    void testInitializable() {
+        def defs = [
+                initializableBean: 'org.apache.shiro.config.InitializableBean'
+        ]
+        def builder = new ReflectionBuilder()
+        def objects = builder.buildObjects(defs)
+        def bean = objects.get('initializableBean') as InitializableBean
+        assertTrue bean.isInitialized()
+    }
+
     void testFactoryInstantiation() {
         Map<String, String> defs = new LinkedHashMap<String, String>();
         defs.put("simpleBeanFactory", "org.apache.shiro.config.SimpleBeanFactory");

Added: shiro/branches/1.2.x/core/src/test/java/org/apache/shiro/config/InitializableBean.java
URL: http://svn.apache.org/viewvc/shiro/branches/1.2.x/core/src/test/java/org/apache/shiro/config/InitializableBean.java?rev=1457316&view=auto
==============================================================================
--- shiro/branches/1.2.x/core/src/test/java/org/apache/shiro/config/InitializableBean.java (added)
+++ shiro/branches/1.2.x/core/src/test/java/org/apache/shiro/config/InitializableBean.java Sat Mar 16 21:44:46 2013
@@ -0,0 +1,20 @@
+package org.apache.shiro.config;
+
+import org.apache.shiro.ShiroException;
+import org.apache.shiro.util.Initializable;
+
+/**
+ * @since 1.2.2
+ */
+public class InitializableBean implements Initializable {
+
+    private volatile boolean initialized = false;
+
+    public void init() throws ShiroException {
+        initialized = true;
+    }
+
+    public boolean isInitialized() {
+        return initialized;
+    }
+}