This is an automated email from the ASF dual-hosted git repository. smiklosovic pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/cassandra.git
commit fe30e227bdedf13f890e242d2646598398ba8bed Merge: 26ff589f3d 63b4e1c41c Author: Stefan Miklosovic <smikloso...@apache.org> AuthorDate: Tue Jul 9 17:21:53 2024 +0200 Merge branch 'cassandra-5.0' into trunk CHANGES.txt | 1 + pylib/cqlshlib/test/test_cqlsh_completion.py | 5 +++ .../cql3/statements/AlterRoleStatement.java | 3 ++ .../cassandra/auth/CreateAndAlterRoleTest.java | 39 ++++++++++++++++++++++ 4 files changed, 48 insertions(+) diff --cc pylib/cqlshlib/test/test_cqlsh_completion.py index e8c0473675,a53df5905d..a787f3fcb2 --- a/pylib/cqlshlib/test/test_cqlsh_completion.py +++ b/pylib/cqlshlib/test/test_cqlsh_completion.py @@@ -1044,8 -1042,9 +1044,9 @@@ class TestCqlshCompletion(CqlshCompleti def test_complete_in_alter_role(self): self.trycompletions('ALTER ROLE ', choices=['<identifier>', 'IF', '<quotedName>']) + self.trycompletions('ALTER ROLE IF ', immediate='EXISTS ') self.trycompletions('ALTER ROLE foo ', immediate='WITH ') - self.trycompletions('ALTER ROLE foo WITH ', choices=['ACCESS', 'HASHED', 'LOGIN', 'OPTIONS', 'PASSWORD', 'SUPERUSER']) + self.trycompletions('ALTER ROLE foo WITH ', choices=['ACCESS', 'HASHED', 'LOGIN', 'OPTIONS', 'PASSWORD', 'SUPERUSER', 'GENERATED']) self.trycompletions('ALTER ROLE foo WITH ACCESS TO ', choices=['ALL', 'DATACENTERS']) self.trycompletions('ALTER ROLE foo WITH ACCESS FROM ', choices=['ALL', 'CIDRS']) diff --cc src/java/org/apache/cassandra/cql3/statements/AlterRoleStatement.java index d12b020c88,74ec25f2df..bb83127c84 --- a/src/java/org/apache/cassandra/cql3/statements/AlterRoleStatement.java +++ b/src/java/org/apache/cassandra/cql3/statements/AlterRoleStatement.java @@@ -124,19 -114,9 +124,22 @@@ public class AlterRoleStatement extend public ResultMessage execute(ClientState state) throws RequestValidationException, RequestExecutionException { + if (ifExists && !DatabaseDescriptor.getRoleManager().isExistingRole(role)) + return null; + + if (opts.isGeneratedPassword()) + { + String generatedPassword = Guardrails.password.generate(); + if (generatedPassword != null) + opts.setOption(IRoleManager.Option.PASSWORD, generatedPassword); + else + throw new InvalidRequestException("You have to enable password_validator and it's generator_class_name property " + + "in cassandra.yaml to be able to generate passwords."); + } + + if (opts.getPassword().isPresent()) + Guardrails.password.guard(opts.getPassword().get(), state); + if (!opts.isEmpty()) DatabaseDescriptor.getRoleManager().alterRole(state.getUser(), role, opts); diff --cc test/unit/org/apache/cassandra/auth/CreateAndAlterRoleTest.java index 1d71025cbb,a6adafcd01..39e0098489 --- a/test/unit/org/apache/cassandra/auth/CreateAndAlterRoleTest.java +++ b/test/unit/org/apache/cassandra/auth/CreateAndAlterRoleTest.java @@@ -21,6 -24,9 +24,8 @@@ import java.util.Set import org.junit.BeforeClass; import org.junit.Test; + import com.datastax.driver.core.ResultSet; + import com.datastax.driver.core.exceptions.InvalidQueryException; -import org.apache.cassandra.ServerTestUtils; import org.apache.cassandra.config.DatabaseDescriptor; import org.apache.cassandra.cql3.CQLTester; --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org