diff --git a/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java b/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java index 1c2bf688c6..4148a33fa2 100644 --- a/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java +++ b/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java @@ -26,7 +26,9 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Properties; import java.util.Map; +import java.util.HashMap; +import org.apache.cassandra.avro.AccessLevel; import org.apache.cassandra.config.ConfigurationException; import org.apache.cassandra.thrift.AuthenticationException; import org.apache.cassandra.thrift.AuthorizationException; @@ -135,6 +137,39 @@ public class SimpleAuthenticator implements IAuthenticator } } + /** + * Loads the user access map for each keyspace from the deprecated access.properties file. + */ + @Deprecated + public Map> loadAccessFile() throws ConfigurationException + { + Map> keyspacesAccess = new HashMap(); + final String accessFilenameProperty = "access.properties"; + String afilename = System.getProperty(accessFilenameProperty); + Properties props = new Properties(); + try + { + FileInputStream in = new FileInputStream(afilename); + props.load(in); + in.close(); + } + catch (Exception e) + { + throw new ConfigurationException("Authorization table file given by property " + accessFilenameProperty + " could not be loaded: " + e.getMessage()); + } + for (String keyspace : props.stringPropertyNames()) + { + // structure: + // given keyspace X, users A B and C can be authorized like this (separate their names with spaces): + // X = A B C + Map usersAccess = new HashMap(); + for (String user : props.getProperty(keyspace).split(",")) + usersAccess.put(user, AccessLevel.FULL); + keyspacesAccess.put(keyspace, usersAccess); + } + return keyspacesAccess; + } + static String authenticationErrorMessage(PasswordMode mode, String username) { return String.format("Given password in password mode %s could not be validated for user %s", mode, username); diff --git a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java index a9a4e7a939..30938ce93b 100644 --- a/src/java/org/apache/cassandra/config/DatabaseDescriptor.java +++ b/src/java/org/apache/cassandra/config/DatabaseDescriptor.java @@ -32,7 +32,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.apache.cassandra.auth.AllowAllAuthenticator; +import org.apache.cassandra.auth.SimpleAuthenticator; import org.apache.cassandra.auth.IAuthenticator; +import org.apache.cassandra.avro.AccessLevel; import org.apache.cassandra.config.Config.RequestSchedulerId; import org.apache.cassandra.db.ClockType; import org.apache.cassandra.db.ColumnFamilyType; @@ -509,11 +511,18 @@ public class DatabaseDescriptor CFMetaData.fixMaxId(); } - /** reads xml. doesn't populate any internal structures. */ + /** + * Reads keyspaces from yaml: doesn't populate any internal structures. + * @Deprecated + */ public static Collection readTablesFromYaml() throws ConfigurationException { List defs = new ArrayList(); + /* If SimpleAuthenticator is in use, load the (deprecated) access.properties file, to apply it to keyspaces. */ + Map> keyspacesAccess = new HashMap(); + if (DatabaseDescriptor.getAuthenticator() instanceof SimpleAuthenticator) + keyspacesAccess = ((SimpleAuthenticator)DatabaseDescriptor.getAuthenticator()).loadAccessFile(); /* Read the table related stuff from config */ for (RawKeyspace keyspace : conf.keyspaces) @@ -622,8 +631,12 @@ public class DatabaseDescriptor cf.gc_grace_seconds, metadata); } - defs.add(new KSMetaData(keyspace.name, strategyClass, keyspace.replication_factor, null, null, cfDefs)); - + defs.add(new KSMetaData(keyspace.name, + strategyClass, + keyspace.replication_factor, + keyspacesAccess.get(keyspace.name), + null, + cfDefs)); } return defs;