Author: jbellis
Date: Thu Aug 18 19:38:40 2011
New Revision: 1159372

URL: http://svn.apache.org/viewvc?rev=1159372&view=rev
Log:
load access.properties for each request so you don't have to restart server to 
see changes
patch by Thomas Peuss; reviewed by jbellis for CASSANDRA-3048

Modified:
    cassandra/trunk/src/java/org/apache/cassandra/auth/SimpleAuthority.java

Modified: 
cassandra/trunk/src/java/org/apache/cassandra/auth/SimpleAuthority.java
URL: 
http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/auth/SimpleAuthority.java?rev=1159372&r1=1159371&r2=1159372&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/auth/SimpleAuthority.java 
(original)
+++ cassandra/trunk/src/java/org/apache/cassandra/auth/SimpleAuthority.java Thu 
Aug 18 19:38:40 2011
@@ -21,20 +21,22 @@ package org.apache.cassandra.auth;
  */
 
 
+import java.io.BufferedInputStream;
 import java.io.FileInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.EnumSet;
 import java.util.List;
 import java.util.Properties;
 
 import org.apache.cassandra.config.ConfigurationException;
+import org.apache.cassandra.io.util.FileUtils;
 
 public class SimpleAuthority implements IAuthority
 {
     public final static String ACCESS_FILENAME_PROPERTY = "access.properties";
     // magical property for WRITE permissions to the keyspaces list
     public final static String KEYSPACES_WRITE_PROPERTY = "<modify-keyspaces>";
-    private Properties accessProperties = null;
 
     public EnumSet<Permission> authorize(AuthenticatedUser user, List<Object> 
resource)
     {
@@ -68,17 +70,13 @@ public class SimpleAuthority implements 
         }
         
         String accessFilename = System.getProperty(ACCESS_FILENAME_PROPERTY);
+        InputStream in=null;
         try
         {
-            // TODO: auto-reload when the file has been updated
-            if (accessProperties == null)   // Don't hit the disk on every 
invocation
-            {
-                FileInputStream in = new FileInputStream(accessFilename);
-                accessProperties = new Properties();
-                accessProperties.load(in);
-                in.close();
-            }
-            
+            in = new BufferedInputStream(new FileInputStream(accessFilename));
+            Properties accessProperties = new Properties();
+            accessProperties.load(in);
+
             // Special case access to the keyspace list
             if (keyspace == KEYSPACES_WRITE_PROPERTY)
             {
@@ -138,6 +136,10 @@ public class SimpleAuthority implements 
                                                      accessFilename,
                                                      e.getMessage()));
         }
+        finally
+        {
+            FileUtils.closeQuietly(in);
+        }
 
         return authorized;
     }


Reply via email to