Skip to content

Commit d2be62a

Browse files
vikingUnetsmiklosovic
authored andcommitted
Add option allow_empty_password
see issue 53
1 parent 08f1506 commit d2be62a

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

README.adoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ The content of the configuration file is as follows:
103103

104104
|cassandra_ldap_admin_user
105105
|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.
106+
107+
|allow_empty_password
108+
|allow or disallow empty passwords when trying to connect to ldap server to prevent insecure behavior, defaults to `true`
106109
|===
107110

108111

@@ -228,4 +231,4 @@ Only one role can be specified.
228231

229232
## Further Information
230233
- See blog by Stefan Miklosovic about https://www.instaclustr.com/the-instaclustr-ldap-plugin-for-cassandra/[Apache Cassandra LDAP Authentication]
231-
- Please see https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/[Instaclustr support status] of this project
234+
- Please see https://www.instaclustr.com/support/documentation/announcements/instaclustr-open-source-project-status/[Instaclustr support status] of this project

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public final class LdapAuthenticatorConfiguration
5353

5454
public static final String CASSANDRA_AUTH_CACHE_ENABLED_PROP = "auth_cache_enabled";
5555

56+
// allow as default or disallow empty passwords when trying to connect to ldap server - empty passwords make do some unexpected behavior
57+
public static final String ALLOW_EMPTY_PASSWORD_PROP = "allow_empty_password";
58+
5659
public static final String GENSALT_LOG2_ROUNDS_PROP = "auth_bcrypt_gensalt_log2_rounds";
5760
public static final int GENSALT_LOG2_ROUNDS_DEFAULT = 10;
5861

@@ -134,6 +137,8 @@ public Properties parseProperties() throws ConfigurationException
134137

135138
properties.setProperty(CASSANDRA_AUTH_CACHE_ENABLED_PROP, Boolean.toString(parseBoolean(properties.getProperty(CASSANDRA_AUTH_CACHE_ENABLED_PROP, "true"))));
136139

140+
properties.setProperty(ALLOW_EMPTY_PASSWORD_PROP, Boolean.toString(parseBoolean(properties.getProperty(ALLOW_EMPTY_PASSWORD_PROP, "true"))));
141+
137142
properties.setProperty(CONSISTENCY_FOR_ROLE, properties.getProperty(CONSISTENCY_FOR_ROLE, DEFAULT_CONSISTENCY_FOR_ROLE));
138143

139144
String filterTemplate = properties.getProperty(FILTER_TEMPLATE, "(cn=%s)");

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

Lines changed: 8 additions & 0 deletions
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_AUTH_CACHE_ENABLED_PROP;
21+
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.ALLOW_EMPTY_PASSWORD_PROP;
2122
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER;
2223
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_LDAP_ADMIN_USER_SYSTEM_PROPERTY;
2324
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.DEFAULT_ROLE_MEMBERSHIP;
@@ -65,6 +66,8 @@ public class LDAPAuthenticator extends AbstractLDAPAuthenticator
6566

6667
private static final Logger logger = LoggerFactory.getLogger(AbstractLDAPAuthenticator.class);
6768

69+
private boolean allow_empty_password;
70+
6871
protected CacheDelegate cacheDelegate;
6972

7073
public void setup()
@@ -114,6 +117,8 @@ public void setup()
114117
ldapUserRetriever::retrieve,
115118
parseBoolean(properties.getProperty(CASSANDRA_AUTH_CACHE_ENABLED_PROP)));
116119

120+
allow_empty_password = parseBoolean(properties.getProperty(ALLOW_EMPTY_PASSWORD_PROP));
121+
117122
logger.info("{} was initialised", LDAPAuthenticator.class.getName());
118123
}
119124

@@ -136,6 +141,9 @@ public AuthenticatedUser authenticate(String username, String password) throws A
136141
{
137142
try
138143
{
144+
if (!allow_empty_password && password.isEmpty())
145+
throw new AuthenticationException("empty password is not supported");
146+
139147
final User user = new User(username, password);
140148

141149
final User cachedUser = cacheDelegate.get(user);

conf/ldap.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ filter_template: (cn=%s)
2020
# This option is irrelevant for Cassandra version <= 3.0
2121
#auth_cache_enabled: false
2222

23+
# Allow or disallow empty passwords when trying to connect to ldap server to prevent insecure behavior, defaults to `true`
24+
#allow_empty_password: true
25+
2326
# if you set this property, Cassandra will internally consider 'dba` to be same as 'cassandra'.
2427
# so you might get rid of `cassandra` role (not recommended) or you might make it unable to log in at least.
2528
# You need to create this admin role beforehand, it has to be super user.

0 commit comments

Comments
 (0)