Author: tveronezi
Date: Thu Dec 13 19:55:32 2012
New Revision: 1421457

URL: http://svn.apache.org/viewvc?rev=1421457&view=rev
Log:
The user can pass a "path", "uri" or the name of the file in the "conf" dir.

Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/security/jaas/ScriptLoginModule.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/security/jaas/ScriptLoginModule.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/security/jaas/ScriptLoginModule.java?rev=1421457&r1=1421456&r2=1421457&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/security/jaas/ScriptLoginModule.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/security/jaas/ScriptLoginModule.java
 Thu Dec 13 19:55:32 2012
@@ -87,23 +87,61 @@ public class ScriptLoginModule implement
         return new UserData(user, password);
     }
 
-    @Override
-    public boolean login() throws LoginException {
-        String scriptURI = (String) this.options.get("scriptURI");
-        if(scriptURI == null || "".equals(scriptURI.trim())) {
-            scriptURI = 
System.getProperty("openejb.ScriptLoginModule.scriptURI");
+    private File getScriptFile(String path) {
+        if (path == null  || "".equals(path)) {
+            final File result = new File(System.getProperty("openejb.home"), 
"conf/loginscript.js");
+            if (result.exists()) {
+                return result;
+            } else {
+                return null;
+            }
+        }
+
+        try {
+            final URI uri = URI.create(path);
+            final File result = new File(uri);
+            if (result.exists()) {
+                return result;
+            }
+        } catch (Exception e) {
+            // no-op
+        }
+
+        {
+            final File result = new File(path);
+            if (result.exists()) {
+                return result;
+            }
+        }
 
-            if(scriptURI == null || "".equals(scriptURI.trim())) {
-                throw new LoginException("No login script defined");
+        {
+            final File openEjbConf = new 
File(System.getProperty("openejb.home"), "conf");
+            final File result = new File(openEjbConf, path);
+            if (result.exists()) {
+                return result;
             }
         }
 
-        final URI uri = URI.create(scriptURI);
+        return null;
+    }
+
+    @Override
+    public boolean login() throws LoginException {
+        File script = getScriptFile((String) this.options.get("scriptURI"));
+        if (script == null) {
+            script = 
getScriptFile(System.getProperty("openejb.ScriptLoginModule.scriptURI"));
+            if (script == null) {
+                script = getScriptFile(System.getProperty(null));
+            }
+        }
+        if (script == null) {
+            throw new LoginException("No login script defined");
+        }
         final String scriptText;
         try {
-            scriptText = new Scanner(new File(uri)).useDelimiter("\\Z").next();
+            scriptText = new Scanner(script).useDelimiter("\\Z").next();
         } catch (FileNotFoundException e) {
-            throw new LoginException("Invalid login script URI. Value: " + 
scriptURI);
+            throw new LoginException("Invalid login script URI.");
         }
 
         this.userData = getUserData();


Reply via email to