You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@shiro.apache.org by "johnathan.james" <ha...@gmail.com> on 2014/05/12 05:42:21 UTC

Re: System properties in shiro.ini

A patch given to the public domain.. If you give credit, please credit
Johnathan E. James. And send me an email :) Thanks.

Index: src/main/java/org/apache/shiro/config/ReflectionBuilder.java
===================================================================
--- src/main/java/org/apache/shiro/config/ReflectionBuilder.java	(revision
1593866)
+++ src/main/java/org/apache/shiro/config/ReflectionBuilder.java	(working
copy)
@@ -95,6 +95,20 @@
         return (T) bean;
     }
 
+    private String getValue(String str) {
+    	String rtn = str;
+    	
+    	int beginIndex = str.indexOf("${");
+    	int endIndex = str.indexOf("}");
+    	
+    	if ((beginIndex == 0) && (endIndex == str.length() - 1)) {
+    		String propertyName = str.substring(2, endIndex);
+    		rtn = System.getProperty(propertyName);
+    	}
+    	
+    	return rtn;
+    }
+
     @SuppressWarnings({"unchecked"})
     public Map<String, ?> buildObjects(Map<String, String> kvPairs) {
         if (kvPairs != null && !kvPairs.isEmpty()) {
@@ -116,12 +130,12 @@
 
             // Create all instances
             for (Map.Entry<String, String> entry : instanceMap.entrySet())
{
-                createNewInstance((Map<String, Object>) objects,
entry.getKey(), entry.getValue());
+                createNewInstance((Map<String, Object>) objects,
entry.getKey(), getValue(entry.getValue()));
             }
 
             // Set all properties
             for (Map.Entry<String, String> entry : propertyMap.entrySet())
{
-                applyProperty(entry.getKey(), entry.getValue(), objects);
+                applyProperty(entry.getKey(), getValue(entry.getValue()),
objects);
             }
         }
 




--
View this message in context: http://shiro-user.582556.n2.nabble.com/System-properties-in-shiro-ini-tp7579627p7579946.html
Sent from the Shiro User mailing list archive at Nabble.com.