Skip to content

Commit

Permalink
Fix creating/dropping roles in CASSANDRA_4
Browse files Browse the repository at this point in the history
  • Loading branch information
driftx committed Dec 13, 2024
1 parent 576f887 commit d80c66b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.StorageCompatibilityMode;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

Expand All @@ -37,6 +39,11 @@ public class CreateRoleStatement extends AuthenticationStatement
final CIDRPermissions cidrPermissions;
private final boolean ifNotExists;

public CreateRoleStatement(RoleName name, RoleOptions options, DCPermissions dcPermissions, boolean ifNotExists)
{
this(name, options, dcPermissions, null, ifNotExists);
}

public CreateRoleStatement(RoleName name, RoleOptions options, DCPermissions dcPermissions,
CIDRPermissions cidrPermissions, boolean ifNotExists)
{
Expand Down Expand Up @@ -93,7 +100,7 @@ public ResultMessage execute(ClientState state) throws RequestExecutionException
DatabaseDescriptor.getNetworkAuthorizer().setRoleDatacenters(role, dcPermissions);
}

if (cidrPermissions != null)
if (cidrPermissions != null && DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
DatabaseDescriptor.getCIDRAuthorizer().setCidrGroupsForRole(role, cidrPermissions);

grantPermissionsToCreator(state);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.apache.cassandra.exceptions.*;
import org.apache.cassandra.service.ClientState;
import org.apache.cassandra.transport.messages.ResultMessage;
import org.apache.cassandra.utils.StorageCompatibilityMode;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

Expand Down Expand Up @@ -75,7 +77,8 @@ public ResultMessage execute(ClientState state) throws RequestValidationExceptio
DatabaseDescriptor.getAuthorizer().revokeAllFrom(role);
DatabaseDescriptor.getAuthorizer().revokeAllOn(role);
DatabaseDescriptor.getNetworkAuthorizer().drop(role);
DatabaseDescriptor.getCIDRAuthorizer().dropCidrPermissionsForRole(role);
if (DatabaseDescriptor.getStorageCompatibilityMode() != StorageCompatibilityMode.CASSANDRA_4)
DatabaseDescriptor.getCIDRAuthorizer().dropCidrPermissionsForRole(role);
return null;
}

Expand Down

0 comments on commit d80c66b

Please sign in to comment.