mirror of https://github.com/apache/cassandra
Move SimpleAuthenticator and SimpleAuthority to examples/
patch by slebresne; reviewed by jbellis for CASSANDRA-2922 git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-1.0.0@1180076 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
91ee8d689f
commit
0d9fdad0b5
|
|
@ -24,6 +24,7 @@ Fixes merged from 0.8 below:
|
|||
* Fix missing fields in CLI `show schema` output (CASSANDRA-3304)
|
||||
* Nodetool no longer leaks threads and closes JMX connections (CASSANDRA-3309)
|
||||
* fix truncate allowing data to be replayed post-restart (CASSANDRA-3297)
|
||||
* Move SimpleAuthority and SimpleAuthenticator to examples (CASSANDRA-2922)
|
||||
|
||||
|
||||
1.0.0-rc2
|
||||
|
|
|
|||
4
NEWS.txt
4
NEWS.txt
|
|
@ -22,6 +22,10 @@ Upgrading
|
|||
- Cassandra 1.0 uses arena allocation to reduce old generation fragmentation.
|
||||
This means there is a minimum overhead of 1MB per ColumnFamily plus
|
||||
1MB per index.
|
||||
- The SimpleAuthenticator and SimpleAuthority classes have been moved to
|
||||
the example directory (and are thus not available from the binary
|
||||
distribution). They never provided actual security and in their current
|
||||
state are only meant as examples.
|
||||
|
||||
Features
|
||||
--------
|
||||
|
|
|
|||
|
|
@ -8,6 +8,4 @@ log4j-server.proprties: log4j configuration file for Cassandra server
|
|||
Optional configuration files
|
||||
============================
|
||||
|
||||
access.properties: used for authorization
|
||||
passwd.properties: used for authentication
|
||||
cassandra-topology.properties: used by PropertyFileSnitch
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
The files in this directory provide a (simplistic) example of how to add
|
||||
authentication and resource permissions to Cassandra by implementing the
|
||||
org.apache.cassandra.auth.{IAuthenticator, IAuthority} interfaces.
|
||||
|
||||
To try those examples, copy the two JAVA sources (in src/) into the main
|
||||
cassandra sources directory and the two configuration files (in conf/) in the
|
||||
main cassandra configuration directory.
|
||||
|
||||
You can then set the authenticator and authority properties in cassandra.yaml
|
||||
to use those classes. See the two configuration files access.properties and
|
||||
passwd.properties to configure the authorized users and permissions.
|
||||
|
||||
Please note that the code in this directory is for demonstration purposes. In
|
||||
particular, it does not provide a high level of security.
|
||||
|
|
@ -27,6 +27,9 @@ import org.apache.cassandra.thrift.AuthenticationException;
|
|||
|
||||
public interface IAuthenticator
|
||||
{
|
||||
public static final String USERNAME_KEY = "username";
|
||||
public static final String PASSWORD_KEY = "password";
|
||||
|
||||
/**
|
||||
* @return The user that a connection is initialized with, or 'null' if a user must call login().
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ import com.google.common.base.Charsets;
|
|||
import com.google.common.base.Joiner;
|
||||
|
||||
import org.antlr.runtime.tree.Tree;
|
||||
import org.apache.cassandra.auth.SimpleAuthenticator;
|
||||
import org.apache.cassandra.auth.IAuthenticator;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.db.ColumnFamilyStoreMBean;
|
||||
import org.apache.cassandra.db.compaction.CompactionInfo;
|
||||
|
|
@ -1833,8 +1833,8 @@ public class CliClient
|
|||
{
|
||||
/* remove quotes */
|
||||
password = password.replace("\'", "");
|
||||
credentials.put(SimpleAuthenticator.USERNAME_KEY, username);
|
||||
credentials.put(SimpleAuthenticator.PASSWORD_KEY, password);
|
||||
credentials.put(IAuthenticator.USERNAME_KEY, username);
|
||||
credentials.put(IAuthenticator.PASSWORD_KEY, password);
|
||||
authRequest = new AuthenticationRequest(credentials);
|
||||
thriftClient.login(authRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import java.util.*;
|
|||
|
||||
import jline.ConsoleReader;
|
||||
import jline.History;
|
||||
import org.apache.cassandra.auth.SimpleAuthenticator;
|
||||
import org.apache.cassandra.auth.IAuthenticator;
|
||||
import org.apache.cassandra.thrift.*;
|
||||
import org.apache.thrift.TException;
|
||||
import org.apache.thrift.protocol.TBinaryProtocol;
|
||||
|
|
@ -95,8 +95,8 @@ public class CliMain
|
|||
{
|
||||
// Authenticate
|
||||
Map<String, String> credentials = new HashMap<String, String>();
|
||||
credentials.put(SimpleAuthenticator.USERNAME_KEY, sessionState.username);
|
||||
credentials.put(SimpleAuthenticator.PASSWORD_KEY, sessionState.password);
|
||||
credentials.put(IAuthenticator.USERNAME_KEY, sessionState.username);
|
||||
credentials.put(IAuthenticator.PASSWORD_KEY, sessionState.password);
|
||||
AuthenticationRequest authRequest = new AuthenticationRequest(credentials);
|
||||
try
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ import java.util.Map;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.apache.cassandra.auth.SimpleAuthenticator;
|
||||
import org.apache.cassandra.auth.IAuthenticator;
|
||||
import org.apache.cassandra.thrift.*;
|
||||
import org.apache.hadoop.conf.Configuration;
|
||||
import org.apache.hadoop.mapreduce.*;
|
||||
|
|
@ -154,8 +154,8 @@ public class ColumnFamilyOutputFormat extends OutputFormat<ByteBuffer,List<Mutat
|
|||
if (ConfigHelper.getOutputKeyspaceUserName(conf) != null)
|
||||
{
|
||||
Map<String, String> creds = new HashMap<String, String>();
|
||||
creds.put(SimpleAuthenticator.USERNAME_KEY, ConfigHelper.getOutputKeyspaceUserName(conf));
|
||||
creds.put(SimpleAuthenticator.PASSWORD_KEY, ConfigHelper.getOutputKeyspacePassword(conf));
|
||||
creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getOutputKeyspaceUserName(conf));
|
||||
creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getOutputKeyspacePassword(conf));
|
||||
AuthenticationRequest authRequest = new AuthenticationRequest(creds);
|
||||
client.login(authRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ import java.util.*;
|
|||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
|
||||
import org.apache.cassandra.auth.SimpleAuthenticator;
|
||||
import org.apache.cassandra.auth.IAuthenticator;
|
||||
import org.apache.cassandra.config.ConfigurationException;
|
||||
import org.apache.cassandra.db.IColumn;
|
||||
import org.apache.cassandra.db.marshal.AbstractType;
|
||||
|
|
@ -120,8 +120,8 @@ public class ColumnFamilyRecordReader extends RecordReader<ByteBuffer, SortedMap
|
|||
if (ConfigHelper.getInputKeyspaceUserName(conf) != null)
|
||||
{
|
||||
Map<String, String> creds = new HashMap<String, String>();
|
||||
creds.put(SimpleAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
|
||||
creds.put(SimpleAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
|
||||
creds.put(IAuthenticator.USERNAME_KEY, ConfigHelper.getInputKeyspaceUserName(conf));
|
||||
creds.put(IAuthenticator.PASSWORD_KEY, ConfigHelper.getInputKeyspacePassword(conf));
|
||||
AuthenticationRequest authRequest = new AuthenticationRequest(creds);
|
||||
client.login(authRequest);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,84 +0,0 @@
|
|||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.apache.cassandra.auth;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SimpleAuthorityTest
|
||||
{
|
||||
private final SimpleAuthority authority = new SimpleAuthority();
|
||||
|
||||
private final AuthenticatedUser USER1 = new AuthenticatedUser("user1");
|
||||
private final AuthenticatedUser USER2 = new AuthenticatedUser("user2");
|
||||
private final AuthenticatedUser USER3 = new AuthenticatedUser("user3");
|
||||
|
||||
private final List<Object> KEYSPACES_RESOURCE = Arrays.<Object>asList(Resources.ROOT, Resources.KEYSPACES);
|
||||
private final List<Object> KEYSPACE1_RESOURCE = Arrays.<Object>asList(Resources.ROOT, Resources.KEYSPACES, "Keyspace1");
|
||||
private final List<Object> KEYSPACE2_RESOURCE = Arrays.<Object>asList(Resources.ROOT, Resources.KEYSPACES, "Keyspace2");
|
||||
private final List<Object> STANDARD1_RESOURCE = Arrays.<Object>asList(Resources.ROOT,
|
||||
Resources.KEYSPACES,
|
||||
"Keyspace1",
|
||||
"Standard1");
|
||||
|
||||
@Test
|
||||
public void testValidateConfiguration() throws Exception
|
||||
{
|
||||
authority.validateConfiguration();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorizeKeyspace() throws Exception
|
||||
{
|
||||
assertEquals(Permission.ALL, authority.authorize(USER1, KEYSPACE1_RESOURCE));
|
||||
assertEquals(Permission.ALL, authority.authorize(USER2, KEYSPACE1_RESOURCE));
|
||||
assertEquals(Permission.NONE, authority.authorize(USER3, KEYSPACE1_RESOURCE));
|
||||
|
||||
assertEquals("a keyspace not listed in the access file should be inaccessible",
|
||||
Permission.NONE,
|
||||
authority.authorize(USER1, KEYSPACE2_RESOURCE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorizeKeyspaceList() throws Exception
|
||||
{
|
||||
assertEquals("user1 should be able to modify the keyspace list",
|
||||
Permission.ALL,
|
||||
authority.authorize(USER1, KEYSPACES_RESOURCE));
|
||||
assertEquals("user2 should only be able to read the keyspace list",
|
||||
EnumSet.of(Permission.READ),
|
||||
authority.authorize(USER2, KEYSPACES_RESOURCE));
|
||||
assertEquals("user3 should only be able to read the keyspace list",
|
||||
EnumSet.of(Permission.READ),
|
||||
authority.authorize(USER3, KEYSPACES_RESOURCE));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthorizeColumnFamily() throws Exception
|
||||
{
|
||||
assertEquals(Permission.ALL, authority.authorize(USER1, STANDARD1_RESOURCE));
|
||||
assertEquals(EnumSet.of(Permission.READ), authority.authorize(USER2, STANDARD1_RESOURCE));
|
||||
assertEquals(Permission.NONE, authority.authorize(USER3, STANDARD1_RESOURCE));
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue