mirror of https://github.com/apache/cassandra
apply access.properties to KSM during loadSchemaFromYaml. patch by stuhood, reviewed by gdusbabek. CASSANDRA-1237
git-svn-id: https://svn.apache.org/repos/asf/cassandra/trunk@980226 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
da2d195919
commit
c13bb7b2cb
|
|
@ -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<String,Map<String,AccessLevel>> loadAccessFile() throws ConfigurationException
|
||||
{
|
||||
Map<String,Map<String,AccessLevel>> 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<String,AccessLevel> 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);
|
||||
|
|
|
|||
|
|
@ -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<KSMetaData> readTablesFromYaml() throws ConfigurationException
|
||||
{
|
||||
List<KSMetaData> defs = new ArrayList<KSMetaData>();
|
||||
|
||||
/* If SimpleAuthenticator is in use, load the (deprecated) access.properties file, to apply it to keyspaces. */
|
||||
Map<String,Map<String,AccessLevel>> 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;
|
||||
|
|
|
|||
Loading…
Reference in New Issue