-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0242cfb
commit 7f5aaf2
Showing
12 changed files
with
341 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...src/main/java/com/instaclustr/cassandra/ldap/auth/BaseCassandraLoginEligibilityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
package com.instaclustr.cassandra.ldap.auth; | ||
|
||
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_ELIGIBILITY_CHECK_ACCESS_COLUMN; | ||
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_ELIGIBILITY_CHECK_KEYSPACE; | ||
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_ELIGIBILITY_CHECK_TABLE; | ||
import static com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration.CASSANDRA_ELIGIBILITY_CHECK_USER_COLUMN; | ||
|
||
import java.util.Properties; | ||
|
||
import com.instaclustr.cassandra.ldap.User; | ||
import com.instaclustr.cassandra.ldap.conf.LdapAuthenticatorConfiguration; | ||
import org.apache.cassandra.serializers.BooleanSerializer; | ||
import org.apache.cassandra.service.ClientState; | ||
import org.apache.cassandra.transport.messages.ResultMessage; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public abstract class BaseCassandraLoginEligibilityCheck implements LoginEligibilityCheck | ||
{ | ||
private static final Logger logger = LoggerFactory.getLogger(BaseCassandraLoginEligibilityCheck.class); | ||
|
||
private static final String BASE_SELECT_USER_STATEMENT_TEMPLATE = "select %s from %s.%s where %s = ?"; | ||
|
||
protected ClientState clientState; | ||
protected Properties configProperties; | ||
protected String selectStatement; | ||
|
||
@Override | ||
public void init(final ClientState clientState, final Properties configProperties) | ||
{ | ||
this.clientState = clientState; | ||
this.configProperties = configProperties; | ||
|
||
this.selectStatement = String.format(BASE_SELECT_USER_STATEMENT_TEMPLATE, | ||
configProperties.getProperty(CASSANDRA_ELIGIBILITY_CHECK_ACCESS_COLUMN), | ||
configProperties.getProperty(CASSANDRA_ELIGIBILITY_CHECK_KEYSPACE), | ||
configProperties.getProperty(CASSANDRA_ELIGIBILITY_CHECK_TABLE), | ||
configProperties.getProperty(CASSANDRA_ELIGIBILITY_CHECK_USER_COLUMN)); | ||
|
||
} | ||
|
||
protected abstract ResultMessage.Rows getRows(final String loginName); | ||
|
||
@Override | ||
public boolean isEligibleToLogin(final User user, final String loginName) | ||
{ | ||
|
||
// all non-ldap users are free to log in just fine | ||
if (user.getLdapDN() == null) | ||
{ | ||
return true; | ||
} | ||
|
||
assert clientState != null; | ||
|
||
final ResultMessage.Rows rows = getRows(loginName); | ||
|
||
final boolean noResults = rows.result.isEmpty(); | ||
|
||
if (noResults) | ||
{ | ||
logger.debug(String.format("User with login name '%s' is not eligible to be logged in!", loginName)); | ||
return false; | ||
} | ||
|
||
if (rows.result.size() != 1) | ||
{ | ||
throw new IllegalStateException("There was more than one record returned from eligibility check select query!"); | ||
} | ||
|
||
if (rows.result.rows.get(0).size() != 1) | ||
{ | ||
throw new IllegalStateException("There was more than one column returned from eligibility check select query!"); | ||
} | ||
|
||
if (BooleanSerializer.instance.deserialize(rows.result.rows.get(0).get(0))) | ||
{ | ||
logger.debug(String.format("User with login name '%s' is eligible to be logged in!", loginName)); | ||
return true; | ||
} | ||
|
||
logger.debug(String.format("User with login name '%s' is not eligible to be logged in!", loginName)); | ||
return false; | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
base/src/main/java/com/instaclustr/cassandra/ldap/auth/CassandraLoginEligibilityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.instaclustr.cassandra.ldap.auth; | ||
|
||
import static java.util.Collections.singletonList; | ||
|
||
import org.apache.cassandra.cql3.QueryOptions; | ||
import org.apache.cassandra.cql3.QueryProcessor; | ||
import org.apache.cassandra.cql3.statements.SelectStatement; | ||
import org.apache.cassandra.service.QueryState; | ||
import org.apache.cassandra.transport.messages.ResultMessage.Rows; | ||
import org.apache.cassandra.utils.ByteBufferUtil; | ||
|
||
public class CassandraLoginEligibilityCheck extends BaseCassandraLoginEligibilityCheck | ||
{ | ||
@Override | ||
protected Rows getRows(final String loginName) | ||
{ | ||
final SelectStatement selStmt = (SelectStatement) QueryProcessor.getStatement(selectStatement, clientState).statement; | ||
return selStmt.execute(new QueryState(clientState), QueryOptions.forInternalCalls(singletonList(ByteBufferUtil.bytes(loginName)))); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
base/src/main/java/com/instaclustr/cassandra/ldap/auth/LoginEligibilityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.instaclustr.cassandra.ldap.auth; | ||
|
||
import java.util.Properties; | ||
|
||
import com.instaclustr.cassandra.ldap.User; | ||
import org.apache.cassandra.service.ClientState; | ||
|
||
public interface LoginEligibilityCheck | ||
{ | ||
|
||
void init(final ClientState clientState, final Properties configProperties); | ||
|
||
boolean isEligibleToLogin(final User user, final String loginName); | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
base/src/main/java/com/instaclustr/cassandra/ldap/auth/NoOpLoginEligibilityCheck.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.instaclustr.cassandra.ldap.auth; | ||
|
||
import java.util.Properties; | ||
|
||
import com.instaclustr.cassandra.ldap.User; | ||
import org.apache.cassandra.service.ClientState; | ||
|
||
public final class NoOpLoginEligibilityCheck implements LoginEligibilityCheck | ||
{ | ||
|
||
@Override | ||
public void init(final ClientState clientState, final Properties properties) | ||
{ | ||
|
||
} | ||
|
||
@Override | ||
public boolean isEligibleToLogin(final User user, final String loginName) | ||
{ | ||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.