activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r1086219 - /activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java
Date Mon, 28 Mar 2011 13:02:23 GMT
Author: dejanb
Date: Mon Mar 28 13:02:23 2011
New Revision: 1086219

URL: http://svn.apache.org/viewvc?rev=1086219&view=rev
Log:
https://issues.apache.org/jira/browse/AMQ-3244 - reload=false for PropertiesLoginModule

Modified:
    activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java

Modified: activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java?rev=1086219&r1=1086218&r2=1086219&view=diff
==============================================================================
--- activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java
(original)
+++ activemq/trunk/activemq-jaas/src/main/java/org/apache/activemq/jaas/PropertiesLoginModule.java
Mon Mar 28 13:02:23 2011
@@ -52,53 +52,75 @@ public class PropertiesLoginModule imple
     private CallbackHandler callbackHandler;
 
     private boolean debug;
-    private String usersFile;
-    private String groupsFile;
-    private Properties users = new Properties();
-    private Properties groups = new Properties();
+    private boolean reload = true;
+    private static String usersFile;
+    private static String groupsFile;
+    private static Properties users;
+    private static Properties groups;
     private String user;
     private Set<Principal> principals = new HashSet<Principal>();
     private File baseDir;
     private boolean loginSucceeded;
 
+
     public void initialize(Subject subject, CallbackHandler callbackHandler, Map sharedState,
Map options) {
         this.subject = subject;
         this.callbackHandler = callbackHandler;
         loginSucceeded = false;
 
-        if (System.getProperty("java.security.auth.login.config") != null) {
-            baseDir = new File(System.getProperty("java.security.auth.login.config")).getParentFile();
-        } else {
-            baseDir = new File(".");
-        }
-
         debug = "true".equalsIgnoreCase((String)options.get("debug"));
-        usersFile = (String)options.get(USER_FILE) + "";
-        groupsFile = (String)options.get(GROUP_FILE) + "";
+        if (options.get("reload") != null) {
+            reload = "true".equalsIgnoreCase((String)options.get("reload"));
+        }
 
-        if (debug) {
-            LOG.debug("Initialized debug=" + debug + " usersFile=" + usersFile + " groupsFile="
+ groupsFile + " basedir=" + baseDir);
+        if (reload || users == null) {
+            setBaseDir();
+            usersFile = (String)options.get(USER_FILE) + "";
+            File uf = new File(baseDir, usersFile);
+            try {
+                users = new Properties();
+                java.io.FileInputStream in = new java.io.FileInputStream(uf);
+                users.load(in);
+                in.close();
+            } catch (IOException ioe) {
+                LOG.warn("Unable to load user properties file " + uf);
+            }
+            if (debug) {
+                LOG.debug("Using usersFile=" + usersFile);
+            }
+        }
+        if (reload || groups == null) {
+            setBaseDir();
+            groupsFile = (String)options.get(GROUP_FILE) + "";
+            File gf = new File(baseDir, groupsFile);
+            try {
+                groups = new Properties();
+                java.io.FileInputStream in = new java.io.FileInputStream(gf);
+                groups.load(in);
+                in.close();
+            } catch (IOException ioe) {
+                LOG.warn("Unable to load group properties file " + gf);
+            }
+            if (debug) {
+                LOG.debug("Using groupsFile=" + groupsFile);
+            }
         }
     }
 
-    public boolean login() throws LoginException {
-        File f = new File(baseDir, usersFile);
-        try {
-            java.io.FileInputStream in = new java.io.FileInputStream(f);
-            users.load(in);
-            in.close();
-        } catch (IOException ioe) {
-            throw new LoginException("Unable to load user properties file " + f);
-        }
-        f = new File(baseDir, groupsFile);
-        try {
-            java.io.FileInputStream in = new java.io.FileInputStream(f);
-            groups.load(in);
-            in.close();
-        } catch (IOException ioe) {
-            throw new LoginException("Unable to load group properties file " + f);
+    private void setBaseDir() {
+        if (baseDir == null) {
+            if (System.getProperty("java.security.auth.login.config") != null) {
+                baseDir = new File(System.getProperty("java.security.auth.login.config")).getParentFile();
+            } else {
+                baseDir = new File(".");
+            }
+            if (debug) {
+                LOG.debug("Using basedir=" + baseDir);
+            }
         }
+    }
 
+    public boolean login() throws LoginException {
         Callback[] callbacks = new Callback[2];
 
         callbacks[0] = new NameCallback("Username: ");
@@ -124,7 +146,6 @@ public class PropertiesLoginModule imple
             throw new FailedLoginException("Password does not match");
         }
         loginSucceeded = true;
-        users.clear();
 
         if (debug) {
             LOG.debug("login " + user);
@@ -180,7 +201,6 @@ public class PropertiesLoginModule imple
     }
 
     private void clear() {
-        groups.clear();
         user = null;
         loginSucceeded = false;
     }



Mime
View raw message