From 0d9fdad0b515d1c7ce0d1a8abb4bf391e3c44330 Mon Sep 17 00:00:00 2001 From: Sylvain Lebresne Date: Fri, 7 Oct 2011 15:29:22 +0000 Subject: [PATCH] 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 --- CHANGES.txt | 1 + NEWS.txt | 4 + conf/README.txt | 2 - examples/simple_authentication/README.txt | 14 ++++ .../conf}/access.properties | 0 .../conf}/passwd.properties | 0 .../cassandra/auth/SimpleAuthenticator.java | 0 .../cassandra/auth/SimpleAuthority.java | 0 .../apache/cassandra/auth/IAuthenticator.java | 3 + .../org/apache/cassandra/cli/CliClient.java | 6 +- .../org/apache/cassandra/cli/CliMain.java | 6 +- .../hadoop/ColumnFamilyOutputFormat.java | 6 +- .../hadoop/ColumnFamilyRecordReader.java | 6 +- .../cassandra/auth/SimpleAuthorityTest.java | 84 ------------------- 14 files changed, 34 insertions(+), 98 deletions(-) create mode 100644 examples/simple_authentication/README.txt rename {conf => examples/simple_authentication/conf}/access.properties (100%) rename {conf => examples/simple_authentication/conf}/passwd.properties (100%) rename {src/java => examples/simple_authentication/src}/org/apache/cassandra/auth/SimpleAuthenticator.java (100%) rename {src/java => examples/simple_authentication/src}/org/apache/cassandra/auth/SimpleAuthority.java (100%) delete mode 100644 test/unit/org/apache/cassandra/auth/SimpleAuthorityTest.java diff --git a/CHANGES.txt b/CHANGES.txt index 87bd3e1a8e..802bfa2287 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 diff --git a/NEWS.txt b/NEWS.txt index b1e46b7afe..d2da153975 100644 --- a/NEWS.txt +++ b/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 -------- diff --git a/conf/README.txt b/conf/README.txt index f160dd0ab9..c3fd98dc22 100644 --- a/conf/README.txt +++ b/conf/README.txt @@ -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 diff --git a/examples/simple_authentication/README.txt b/examples/simple_authentication/README.txt new file mode 100644 index 0000000000..3de5092fd2 --- /dev/null +++ b/examples/simple_authentication/README.txt @@ -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. diff --git a/conf/access.properties b/examples/simple_authentication/conf/access.properties similarity index 100% rename from conf/access.properties rename to examples/simple_authentication/conf/access.properties diff --git a/conf/passwd.properties b/examples/simple_authentication/conf/passwd.properties similarity index 100% rename from conf/passwd.properties rename to examples/simple_authentication/conf/passwd.properties diff --git a/src/java/org/apache/cassandra/auth/SimpleAuthenticator.java b/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthenticator.java similarity index 100% rename from src/java/org/apache/cassandra/auth/SimpleAuthenticator.java rename to examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthenticator.java diff --git a/src/java/org/apache/cassandra/auth/SimpleAuthority.java b/examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthority.java similarity index 100% rename from src/java/org/apache/cassandra/auth/SimpleAuthority.java rename to examples/simple_authentication/src/org/apache/cassandra/auth/SimpleAuthority.java diff --git a/src/java/org/apache/cassandra/auth/IAuthenticator.java b/src/java/org/apache/cassandra/auth/IAuthenticator.java index c343256bc9..113a646754 100644 --- a/src/java/org/apache/cassandra/auth/IAuthenticator.java +++ b/src/java/org/apache/cassandra/auth/IAuthenticator.java @@ -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(). */ diff --git a/src/java/org/apache/cassandra/cli/CliClient.java b/src/java/org/apache/cassandra/cli/CliClient.java index 56c793cb07..c755a1d96b 100644 --- a/src/java/org/apache/cassandra/cli/CliClient.java +++ b/src/java/org/apache/cassandra/cli/CliClient.java @@ -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); } diff --git a/src/java/org/apache/cassandra/cli/CliMain.java b/src/java/org/apache/cassandra/cli/CliMain.java index a279d4585c..b12a19af83 100644 --- a/src/java/org/apache/cassandra/cli/CliMain.java +++ b/src/java/org/apache/cassandra/cli/CliMain.java @@ -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 credentials = new HashMap(); - 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 { diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilyOutputFormat.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilyOutputFormat.java index 2d8e3362ee..1c0bc665b6 100644 --- a/src/java/org/apache/cassandra/hadoop/ColumnFamilyOutputFormat.java +++ b/src/java/org/apache/cassandra/hadoop/ColumnFamilyOutputFormat.java @@ -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 creds = new HashMap(); - 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); } diff --git a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java index 330153a504..a294df0f8e 100644 --- a/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java +++ b/src/java/org/apache/cassandra/hadoop/ColumnFamilyRecordReader.java @@ -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 creds = new HashMap(); - 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); } diff --git a/test/unit/org/apache/cassandra/auth/SimpleAuthorityTest.java b/test/unit/org/apache/cassandra/auth/SimpleAuthorityTest.java deleted file mode 100644 index cc1384c5d0..0000000000 --- a/test/unit/org/apache/cassandra/auth/SimpleAuthorityTest.java +++ /dev/null @@ -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 KEYSPACES_RESOURCE = Arrays.asList(Resources.ROOT, Resources.KEYSPACES); - private final List KEYSPACE1_RESOURCE = Arrays.asList(Resources.ROOT, Resources.KEYSPACES, "Keyspace1"); - private final List KEYSPACE2_RESOURCE = Arrays.asList(Resources.ROOT, Resources.KEYSPACES, "Keyspace2"); - private final List STANDARD1_RESOURCE = Arrays.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)); - } -}