Skip to content

Commit b6930b5

Browse files
Revert "HCD-82 Enables auth* classes configuration" (#1607)
Reverts #1578
1 parent 054fbeb commit b6930b5

File tree

11 files changed

+72
-293
lines changed

11 files changed

+72
-293
lines changed

CHANGES.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
Future version (tbd)
22
* Require only MODIFY permission on base when updating table with MV (STAR-564)
33
Merged from 5.0:
4-
* Use ParameterizedClass for all auth-related implementations (CASSANDRA-19946 and partially CASSANDRA-18554)
54
* Enables IAuthenticator's to return own AuthenticateMessage (CASSANDRA-19984)
65
* Disable chronicle analytics (CASSANDRA-19656)
76
* Remove mocking in InternalNodeProbe spying on StorageServiceMBean (CASSANDRA-18152)

conf/cassandra.yaml

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@ batchlog_replay_throttle_in_kb: 1024
127127
# Authentication backend, implementing IAuthenticator; used to identify users
128128
# Out of the box, Cassandra provides org.apache.cassandra.auth.{AllowAllAuthenticator,
129129
# PasswordAuthenticator}.
130-
# Optional parameters can be specified in the form of:
131-
# parameters:
132-
# param_key1: param_value1
133-
# ...
134130
#
135131
# - AllowAllAuthenticator performs no checks - set it to disable authentication.
136132
# - PasswordAuthenticator relies on username/password pairs to authenticate
@@ -142,10 +138,6 @@ authenticator: AllowAllAuthenticator
142138
# Authorization backend, implementing IAuthorizer; used to limit access/provide permissions
143139
# Out of the box, Cassandra provides org.apache.cassandra.auth.{AllowAllAuthorizer,
144140
# CassandraAuthorizer}.
145-
# Optional parameters can be specified in the form of:
146-
# parameters:
147-
# param_key1: param_value1
148-
# ...
149141
#
150142
# - AllowAllAuthorizer allows any action to any user - set it to disable authorization.
151143
# - CassandraAuthorizer stores permissions in system_auth.role_permissions table. Please
@@ -158,10 +150,6 @@ authorizer: AllowAllAuthorizer
158150
# which stores role information in the system_auth keyspace. Most functions of the
159151
# IRoleManager require an authenticated login, so unless the configured IAuthenticator
160152
# actually implements authentication, most of this functionality will be unavailable.
161-
# Optional parameters can be specified in the form of:
162-
# parameters:
163-
# param_key1: param_value1
164-
# ...
165153
#
166154
# - CassandraRoleManager stores role data in the system_auth keyspace. Please
167155
# increase system_auth keyspace replication factor if you use this role manager.
@@ -171,10 +159,6 @@ role_manager: CassandraRoleManager
171159
# access to certain DCs
172160
# Out of the box, Cassandra provides org.apache.cassandra.auth.{AllowAllNetworkAuthorizer,
173161
# CassandraNetworkAuthorizer}.
174-
# Optional parameters can be specified in the form of:
175-
# parameters:
176-
# param_key1: param_value1
177-
# ...
178162
#
179163
# - AllowAllNetworkAuthorizer allows access to any DC to any user - set it to disable authorization.
180164
# - CassandraNetworkAuthorizer stores permissions in system_auth.network_permissions table. Please

src/java/org/apache/cassandra/auth/AuthConfig.java

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@
1818

1919
package org.apache.cassandra.auth;
2020

21-
import java.util.List;
22-
2321
import org.slf4j.Logger;
2422
import org.slf4j.LoggerFactory;
2523

2624
import org.apache.cassandra.config.Config;
2725
import org.apache.cassandra.config.DatabaseDescriptor;
28-
import org.apache.cassandra.config.ParameterizedClass;
2926
import org.apache.cassandra.exceptions.ConfigurationException;
27+
import org.apache.cassandra.utils.FBUtilities;
3028

3129
/**
3230
* Only purpose is to Initialize authentication/authorization via {@link #applyAuth()}.
@@ -48,10 +46,11 @@ public static void applyAuth()
4846

4947
Config conf = DatabaseDescriptor.getRawConfig();
5048

49+
IAuthenticator authenticator = new AllowAllAuthenticator();
5150

52-
/* Authentication, authorization and role management backend, implementing IAuthenticator, I*Authorizer & IRoleManager */
53-
54-
IAuthenticator authenticator = authInstantiate(conf.authenticator, AllowAllAuthenticator.class);
51+
/* Authentication, authorization and role management backend, implementing IAuthenticator, IAuthorizer & IRoleMapper*/
52+
if (conf.authenticator != null)
53+
authenticator = FBUtilities.newAuthenticator(conf.authenticator);
5554

5655
// the configuration options regarding credentials caching are only guaranteed to
5756
// work with PasswordAuthenticator, so log a message if some other authenticator
@@ -70,39 +69,40 @@ public static void applyAuth()
7069

7170
// authorizer
7271

73-
IAuthorizer authorizer = authInstantiate(conf.authorizer, AllowAllAuthorizer.class);
72+
IAuthorizer authorizer = new AllowAllAuthorizer();
73+
74+
if (conf.authorizer != null)
75+
authorizer = FBUtilities.newAuthorizer(conf.authorizer);
7476

7577
if (!authenticator.requireAuthentication() && authorizer.requireAuthorization())
76-
{
77-
throw new ConfigurationException(authorizer.getClass().getName() + " has authorization enabled which requires " +
78-
authenticator.getClass().getName() + " to enable authentication", false);
79-
}
78+
throw new ConfigurationException(conf.authenticator + " can't be used with " + conf.authorizer, false);
8079

8180
DatabaseDescriptor.setAuthorizer(authorizer);
8281

8382
// role manager
8483

85-
IRoleManager roleManager = authInstantiate(conf.role_manager, CassandraRoleManager.class);
84+
IRoleManager roleManager;
85+
if (conf.role_manager != null)
86+
roleManager = FBUtilities.newRoleManager(conf.role_manager);
87+
else
88+
roleManager = new CassandraRoleManager();
8689

8790
if (authenticator instanceof PasswordAuthenticator && !(roleManager instanceof CassandraRoleManager))
88-
throw new ConfigurationException(authenticator.getClass().getName() + " requires CassandraRoleManager", false);
91+
throw new ConfigurationException("CassandraRoleManager must be used with PasswordAuthenticator", false);
8992

9093
DatabaseDescriptor.setRoleManager(roleManager);
9194

9295
// authenticator
9396

94-
IInternodeAuthenticator internodeAuthenticator = authInstantiate(conf.internode_authenticator,
95-
AllowAllInternodeAuthenticator.class);
96-
DatabaseDescriptor.setInternodeAuthenticator(internodeAuthenticator);
97+
if (conf.internode_authenticator != null)
98+
DatabaseDescriptor.setInternodeAuthenticator(FBUtilities.construct(conf.internode_authenticator, "internode_authenticator"));
9799

98100
// network authorizer
99-
100-
INetworkAuthorizer networkAuthorizer = authInstantiate(conf.network_authorizer, AllowAllNetworkAuthorizer.class);
101+
INetworkAuthorizer networkAuthorizer = FBUtilities.newNetworkAuthorizer(conf.network_authorizer);
101102
DatabaseDescriptor.setNetworkAuthorizer(networkAuthorizer);
102-
103103
if (networkAuthorizer.requireAuthorization() && !authenticator.requireAuthentication())
104104
{
105-
throw new ConfigurationException(conf.network_authorizer + " can't be used with " + conf.authenticator.class_name, false);
105+
throw new ConfigurationException(conf.network_authorizer + " can't be used with " + conf.authenticator, false);
106106
}
107107

108108
// Validate at last to have authenticator, authorizer, role-manager and internode-auth setup
@@ -114,21 +114,4 @@ public static void applyAuth()
114114
networkAuthorizer.validateConfiguration();
115115
DatabaseDescriptor.getInternodeAuthenticator().validateConfiguration();
116116
}
117-
118-
private static <T> T authInstantiate(ParameterizedClass authCls, Class<T> defaultCls) {
119-
if (authCls != null && authCls.class_name != null)
120-
{
121-
String authPackage = AuthConfig.class.getPackage().getName();
122-
return ParameterizedClass.newInstance(authCls, List.of("", authPackage));
123-
}
124-
125-
try
126-
{
127-
return defaultCls.newInstance();
128-
}
129-
catch (InstantiationException | IllegalAccessException e)
130-
{
131-
throw new ConfigurationException("Failed to instantiate " + defaultCls.getName(), e);
132-
}
133-
}
134117
}

src/java/org/apache/cassandra/auth/PasswordAuthenticator.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.util.Map;
2424
import java.util.Set;
2525

26-
import com.google.common.annotations.VisibleForTesting;
2726
import com.google.common.collect.ImmutableSet;
2827
import com.google.common.collect.Lists;
2928
import org.slf4j.Logger;
@@ -172,8 +171,7 @@ private static SelectStatement prepare(String query)
172171
return (SelectStatement) QueryProcessor.getStatement(query, ClientState.forInternalCalls());
173172
}
174173

175-
@VisibleForTesting
176-
class PlainTextSaslAuthenticator implements SaslNegotiator
174+
private class PlainTextSaslAuthenticator implements SaslNegotiator
177175
{
178176
private boolean complete = false;
179177
private String username;

src/java/org/apache/cassandra/config/Config.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public class Config
5454
public static final String PROPERTY_PREFIX = "cassandra.";
5555

5656
public String cluster_name = "Test Cluster";
57-
public ParameterizedClass authenticator;
58-
public ParameterizedClass authorizer;
59-
public ParameterizedClass role_manager;
60-
public ParameterizedClass network_authorizer;
57+
public String authenticator;
58+
public String authorizer;
59+
public String role_manager;
60+
public String network_authorizer;
6161
public volatile int permissions_validity_in_ms = 2000;
6262
public volatile int permissions_cache_max_entries = 1000;
6363
public volatile int permissions_update_interval_in_ms = -1;
@@ -158,7 +158,7 @@ public class Config
158158
public boolean listen_interface_prefer_ipv6 = false;
159159
public String broadcast_address;
160160
public boolean listen_on_broadcast_address = false;
161-
public ParameterizedClass internode_authenticator;
161+
public String internode_authenticator;
162162

163163
/*
164164
* RPC address and interface refer to the address/interface used for the native protocol used to communicate with

src/java/org/apache/cassandra/config/ParameterizedClass.java

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,11 @@
1717
*/
1818
package org.apache.cassandra.config;
1919

20-
import java.lang.reflect.Constructor;
21-
import java.lang.reflect.InvocationTargetException;
22-
import java.util.Arrays;
23-
import java.util.Collections;
2420
import java.util.List;
2521
import java.util.Map;
26-
import java.util.stream.Collectors;
2722

2823
import com.google.common.base.Objects;
2924

30-
import org.apache.cassandra.exceptions.ConfigurationException;
31-
import org.apache.cassandra.utils.IntegerInterval;
32-
3325
public class ParameterizedClass
3426
{
3527
public static final String CLASS_NAME = "class_name";
@@ -43,12 +35,6 @@ public ParameterizedClass()
4335
// for snakeyaml
4436
}
4537

46-
public ParameterizedClass(String class_name)
47-
{
48-
this.class_name = class_name;
49-
this.parameters = Collections.emptyMap();
50-
}
51-
5238
public ParameterizedClass(String class_name, Map<String, String> parameters)
5339
{
5440
this.class_name = class_name;
@@ -62,67 +48,6 @@ public ParameterizedClass(Map<String, ?> p)
6248
p.containsKey(PARAMETERS) ? (Map<String, String>)((List<?>)p.get(PARAMETERS)).get(0) : null);
6349
}
6450

65-
static public <K> K newInstance(ParameterizedClass parameterizedClass, List<String> searchPackages)
66-
{
67-
Class<?> providerClass = null;
68-
if (searchPackages == null || searchPackages.isEmpty())
69-
searchPackages = Collections.singletonList("");
70-
for (String searchPackage : searchPackages)
71-
{
72-
try
73-
{
74-
if (!searchPackage.isEmpty() && !searchPackage.endsWith("."))
75-
searchPackage = searchPackage + '.';
76-
String name = searchPackage + parameterizedClass.class_name;
77-
providerClass = Class.forName(name);
78-
}
79-
catch (ClassNotFoundException e)
80-
{
81-
//no-op
82-
}
83-
}
84-
85-
if (providerClass == null)
86-
{
87-
String error = "Unable to find class " + parameterizedClass.class_name + " in packages [" +
88-
searchPackages.stream().map(p -> '"' + p + '"').collect(Collectors.joining(",")) + ']';
89-
throw new ConfigurationException(error);
90-
}
91-
92-
try
93-
{
94-
Constructor<?>[] declaredConstructors = providerClass.getDeclaredConstructors();
95-
96-
Constructor mapConstructor = Arrays.stream(declaredConstructors)
97-
.filter(c -> c.getParameterTypes().length == 1 && c.getParameterTypes()[0].equals(Map.class))
98-
.findFirst().orElse(null);
99-
if (mapConstructor != null)
100-
return (K) mapConstructor.newInstance(parameterizedClass.parameters);
101-
102-
// Falls-back to no-arg constructor if no parameters are present
103-
if (parameterizedClass.parameters == null || parameterizedClass.parameters.isEmpty())
104-
{
105-
Constructor emptyConstructor = Arrays.stream(declaredConstructors)
106-
.filter(c -> c.getParameterTypes().length == 0)
107-
.findFirst().orElse(null);
108-
if (emptyConstructor != null)
109-
return (K) emptyConstructor.newInstance();
110-
}
111-
112-
throw new ConfigurationException("No valid constructor found for class " + parameterizedClass.class_name);
113-
}
114-
catch (IllegalAccessException|InstantiationException|ExceptionInInitializerError e)
115-
{
116-
throw new ConfigurationException("Unable to instantiate parameterized class " + parameterizedClass.class_name, e);
117-
}
118-
catch (InvocationTargetException e)
119-
{
120-
Throwable cause = e.getCause();
121-
String error = "Failed to instantiate class " + parameterizedClass.class_name + ": " + cause.getMessage();
122-
throw new ConfigurationException(error, cause);
123-
}
124-
}
125-
12651
@Override
12752
public boolean equals(Object that)
12853
{

src/java/org/apache/cassandra/utils/FBUtilities.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
import com.fasterxml.jackson.core.JsonFactory;
7373
import com.fasterxml.jackson.databind.ObjectMapper;
7474
import org.apache.cassandra.audit.IAuditLogger;
75+
import org.apache.cassandra.auth.AllowAllNetworkAuthorizer;
76+
import org.apache.cassandra.auth.IAuthenticator;
77+
import org.apache.cassandra.auth.IAuthorizer;
78+
import org.apache.cassandra.auth.INetworkAuthorizer;
79+
import org.apache.cassandra.auth.IRoleManager;
7580
import org.apache.cassandra.config.DatabaseDescriptor;
7681
import org.apache.cassandra.db.DecoratedKey;
7782
import org.apache.cassandra.db.SerializationHeader;
@@ -707,6 +712,40 @@ static IPartitioner newPartitioner(String partitionerClassName, Optional<Abstrac
707712
return FBUtilities.instanceOrConstruct(partitionerClassName, "partitioner");
708713
}
709714

715+
public static IAuthorizer newAuthorizer(String className) throws ConfigurationException
716+
{
717+
if (!className.contains("."))
718+
className = "org.apache.cassandra.auth." + className;
719+
return FBUtilities.construct(className, "authorizer");
720+
}
721+
722+
public static IAuthenticator newAuthenticator(String className) throws ConfigurationException
723+
{
724+
if (!className.contains("."))
725+
className = "org.apache.cassandra.auth." + className;
726+
return FBUtilities.construct(className, "authenticator");
727+
}
728+
729+
public static IRoleManager newRoleManager(String className) throws ConfigurationException
730+
{
731+
if (!className.contains("."))
732+
className = "org.apache.cassandra.auth." + className;
733+
return FBUtilities.construct(className, "role manager");
734+
}
735+
736+
public static INetworkAuthorizer newNetworkAuthorizer(String className)
737+
{
738+
if (className == null)
739+
{
740+
return new AllowAllNetworkAuthorizer();
741+
}
742+
if (!className.contains("."))
743+
{
744+
className = "org.apache.cassandra.auth." + className;
745+
}
746+
return FBUtilities.construct(className, "network authorizer");
747+
}
748+
710749
public static IAuditLogger newAuditLogger(String className, Map<String, String> parameters) throws ConfigurationException
711750
{
712751
if (!className.contains("."))

test/unit/org/apache/cassandra/audit/AuditLoggerAuthTest.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
import com.datastax.driver.core.exceptions.SyntaxError;
3535
import com.datastax.driver.core.exceptions.UnauthorizedException;
3636
import org.apache.cassandra.ServerTestUtils;
37-
import org.apache.cassandra.auth.CassandraAuthorizer;
38-
import org.apache.cassandra.auth.CassandraRoleManager;
39-
import org.apache.cassandra.auth.PasswordAuthenticator;
4037
import org.apache.cassandra.config.DatabaseDescriptor;
4138
import org.apache.cassandra.config.OverrideConfigurationLoader;
4239
import org.apache.cassandra.config.ParameterizedClass;
@@ -70,11 +67,11 @@ public class AuditLoggerAuthTest
7067
public static void setup() throws Exception
7168
{
7269
OverrideConfigurationLoader.override((config) -> {
73-
config.authenticator = new ParameterizedClass(PasswordAuthenticator.class.getName());
74-
config.role_manager = new ParameterizedClass(CassandraRoleManager.class.getName());
75-
config.authorizer = new ParameterizedClass(CassandraAuthorizer.class.getName());
70+
config.authenticator = "PasswordAuthenticator";
71+
config.role_manager = "CassandraRoleManager";
72+
config.authorizer = "CassandraAuthorizer";
7673
config.audit_logging_options.enabled = true;
77-
config.audit_logging_options.logger = new ParameterizedClass(InMemoryAuditLogger.class.getName(), null);
74+
config.audit_logging_options.logger = new ParameterizedClass("InMemoryAuditLogger", null);
7875
});
7976

8077
System.setProperty("cassandra.superuser_setup_delay_ms", "0");

0 commit comments

Comments
 (0)