Skip to content

Commit 359fdc5

Browse files
committed
enable reading cassandra_ldap_admin_user property from a property file
1 parent 6066a9f commit 359fdc5

File tree

5 files changed

+23
-7
lines changed

5 files changed

+23
-7
lines changed

README.adoc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ The content of the configuration file is as follows:
9393

9494
|default_role_membership
9595
|A role to add new LDAP users to by default. Defaults to empty (users will not be added to any role).
96+
97+
|cassandra_ldap_admin_user
98+
|name of a user/role which will be considered a default superuser, instead of `cassandra`. Please consult "How it Works" section to know more about the usage.
9699
|===
97100

98101

@@ -165,14 +168,14 @@ authentication using a specified service account. This service account should be
165168
file using the `service_dn` and `service_password` properties. If `service_dn` is set, such a role will be created in database,
166169
when not already present, upon node's start.
167170

168-
`service_dn` account, which will be automatically created, will be super user in Cassandra.
171+
`service_dn` account, which will be automatically created, will be superuser in Cassandra.
169172

170-
All "normal" roles are not affectedthey behave exactly as you are used to.
173+
All "normal" roles are not affected - they behave exactly as you are used to.
171174

172175
If the LDAP server connection is lost or there is another communication error while talking to LDAP server,
173176
the operator still has a possibility of logging in via `cassandra` user as usual, and until the LDAP server is not back again;
174177
Users meant to be authenticated against the LDAP server will not be able to log in but all "normal" users will be able to
175-
login and the disruption of LDAP communication will not affect their ability to do so as they live in Cassandra natively.
178+
log in and the disruption of LDAP communication will not affect their ability to do so as they live in Cassandra natively.
176179

177180
In case a user specifies just `test` as login name (or any other name, for that matter), it will try to
178181
authenticate against database first and if not successful against LDAP using filter `filter_template` which defaults to `(cn=%s)`

base/src/main/java/com/instaclustr/cassandra/ldap/conf/LdapAuthenticatorConfiguration.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ public final class LdapAuthenticatorConfiguration
5858

5959
public static final String DEFAULT_CONTEXT_FACTORY = "com.sun.jndi.ldap.LdapCtxFactory";
6060

61-
public static final String CASSANDRA_LDAP_ADMIN_USER = "cassandra.ldap.admin.user";
61+
// the one read from system properties by -Dcassandra.ldap.admin.user=xyz
62+
public static final String CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY = "cassandra.ldap.admin.user";
63+
// the one read from the configuration file,
64+
// if the above system property is specified, it will overwrite the property in the file
65+
public static final String CASSANDRA_LDAP_ADMIN_USER = "cassandra_ldap_admin_user";
6266

6367
public static final String CONSISTENCY_FOR_ROLE = "consistency_for_role";
6468
public static final String DEFAULT_CONSISTENCY_FOR_ROLE = "LOCAL_ONE";
@@ -144,6 +148,12 @@ public Properties parseProperties() throws ConfigurationException
144148
properties.put(LdapAuthenticatorConfiguration.CONTEXT_FACTORY_PROP, properties.getProperty(CONTEXT_FACTORY_PROP, DEFAULT_CONTEXT_FACTORY));
145149
properties.put(LdapAuthenticatorConfiguration.LDAP_URI_PROP, properties.getProperty(LDAP_URI_PROP));
146150

151+
String adminUserFromProperty = System.getProperty(CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY);
152+
if (adminUserFromProperty != null)
153+
properties.put(LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER, adminUserFromProperty);
154+
155+
properties.putIfAbsent(LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER, "cassandra");
156+
147157
return properties;
148158
}
149159

base/src/main/java/org/apache/cassandra/auth/LDAPAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_AUTH_CACHE_ENABLED_PROP;
2121
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER;
22+
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY;
2223
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.DEFAULT_ROLE_MEMBERSHIP;
2324
import static com.instaclustr.cassandra.ldap.utils.ServiceUtils.getService;
2425
import static java.lang.Boolean.parseBoolean;
@@ -86,7 +87,7 @@ public void setup()
8687

8788
cacheDelegate = getService(CacheDelegate.class, null);
8889

89-
final String adminRole = System.getProperty(CASSANDRA_LDAP_ADMIN_USER, "cassandra");
90+
final String adminRole = properties.getProperty(CASSANDRA_LDAP_ADMIN_USER);
9091

9192
while (true)
9293
{

base/src/main/java/org/apache/cassandra/auth/LDAPCassandraRoleManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cassandra.auth;
1919

2020
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER;
21+
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY;
2122
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CONSISTENCY_FOR_ROLE;
2223
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.DEFAULT_CONSISTENCY_FOR_ROLE;
2324
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.LDAP_DN;
@@ -76,7 +77,7 @@ public void setup()
7677

7778
systemAuthRoles = ServiceUtils.getService(SystemAuthRoles.class, null);
7879

79-
final String dbaRole = System.getProperty(CASSANDRA_LDAP_ADMIN_USER, "cassandra");
80+
final String dbaRole = properties.getProperty(CASSANDRA_LDAP_ADMIN_USER);
8081
logger.info("DB admin role is {}", dbaRole);
8182

8283
final String ldapAdminRole = properties.getProperty(LDAP_DN);

base/src/main/java/org/apache/cassandra/auth/LegacyCassandraLDAPAuthenticator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cassandra.auth;
1919

2020
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER;
21+
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY;
2122
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.DEFAULT_ROLE_MEMBERSHIP;
2223
import static com.instaclustr.cassandra.ldap.utils.ServiceUtils.getService;
2324
import static java.lang.String.format;
@@ -66,7 +67,7 @@ public void setup()
6667
final CassandraUserRetriever cassandraUserRetriever = new LegacyCassandraUserRetriever();
6768
cassandraUserRetriever.init(clientState);
6869

69-
final String adminRole = System.getProperty(CASSANDRA_LDAP_ADMIN_USER, "cassandra");
70+
final String adminRole = properties.getProperty(CASSANDRA_LDAP_ADMIN_USER);
7071

7172
while (true)
7273
{

0 commit comments

Comments
 (0)