omkreddy commented on code in PR #13114:
URL: https://github.com/apache/kafka/pull/13114#discussion_r1101769724


##########
metadata/src/main/java/org/apache/kafka/controller/ScramControlManager.java:
##########
@@ -0,0 +1,307 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.kafka.controller;
+
+import org.apache.kafka.clients.admin.ScramMechanism;
+import org.apache.kafka.common.message.AlterUserScramCredentialsRequestData;
+import 
org.apache.kafka.common.message.AlterUserScramCredentialsRequestData.ScramCredentialDeletion;
+import 
org.apache.kafka.common.message.AlterUserScramCredentialsRequestData.ScramCredentialUpsertion;
+import org.apache.kafka.common.message.AlterUserScramCredentialsResponseData;
+import 
org.apache.kafka.common.message.AlterUserScramCredentialsResponseData.AlterUserScramCredentialsResult;
+import org.apache.kafka.common.metadata.RemoveUserScramCredentialRecord;
+import org.apache.kafka.common.metadata.UserScramCredentialRecord;
+import org.apache.kafka.common.requests.ApiError;
+import org.apache.kafka.common.utils.LogContext;
+import org.apache.kafka.server.common.ApiMessageAndVersion;
+import org.apache.kafka.timeline.SnapshotRegistry;
+import org.apache.kafka.timeline.TimelineHashMap;
+import org.slf4j.Logger;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Base64;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Objects;
+
+import static org.apache.kafka.common.protocol.Errors.DUPLICATE_RESOURCE;
+import static org.apache.kafka.common.protocol.Errors.NONE;
+import static org.apache.kafka.common.protocol.Errors.RESOURCE_NOT_FOUND;
+import static org.apache.kafka.common.protocol.Errors.UNACCEPTABLE_CREDENTIAL;
+import static 
org.apache.kafka.common.protocol.Errors.UNSUPPORTED_SASL_MECHANISM;
+
+
+/**
+ * Manages SCRAM credentials.
+ */
+public class ScramControlManager {
+    static final int MAX_ITERATIONS = 16384;
+
+    static class Builder {
+        private LogContext logContext = null;
+        private SnapshotRegistry snapshotRegistry = null;
+
+        Builder setLogContext(LogContext logContext) {
+            this.logContext = logContext;
+            return this;
+        }
+
+        Builder setSnapshotRegistry(SnapshotRegistry snapshotRegistry) {
+            this.snapshotRegistry = snapshotRegistry;
+            return this;
+        }
+
+        ScramControlManager build() {
+            if (logContext == null) logContext = new LogContext();
+            if (snapshotRegistry == null) snapshotRegistry = new 
SnapshotRegistry(logContext);
+            return new ScramControlManager(logContext,
+                snapshotRegistry);
+        }
+    }
+
+    static class ScramCredentialKey {
+        private final String username;
+        private final ScramMechanism mechanism;
+
+        ScramCredentialKey(String username, ScramMechanism mechanism) {
+            this.username = username;
+            this.mechanism = mechanism;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(username, mechanism);
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (o == null) return false;
+            if (!(o.getClass() == this.getClass())) return false;
+            ScramCredentialKey other = (ScramCredentialKey) o;
+            return username.equals(other.username) &&
+                mechanism.equals(other.mechanism);
+        }
+
+        @Override
+        public String toString() {
+            return "ScramCredentialKey" +
+                "(username=" + username +
+                ", mechanism=" + mechanism +
+                ")";
+        }
+    }
+
+    static class ScramCredentialValue {
+        private final byte[] salt;
+        private final byte[] saltedPassword;
+        private final int iterations;
+
+        ScramCredentialValue(
+            byte[] salt,
+            byte[] saltedPassword,
+            int iterations
+        ) {
+            this.salt = salt;
+            this.saltedPassword = saltedPassword;
+            this.iterations = iterations;
+        }
+
+        @Override
+        public int hashCode() {
+            return Objects.hash(salt, saltedPassword, iterations);
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (o == null) return false;
+            if (!(o.getClass() == this.getClass())) return false;
+            ScramCredentialValue other = (ScramCredentialValue) o;
+            return Arrays.equals(salt, other.salt) &&
+                Arrays.equals(saltedPassword, other.saltedPassword) &&
+                iterations == other.iterations;
+        }
+
+        @Override
+        public String toString() {
+            return "ScramCredentialValue" +
+                "(salt=" + Base64.getEncoder().encodeToString(salt) +
+                ", saltedPassword=" + 
Base64.getEncoder().encodeToString(saltedPassword) +
+                ", iterations=" + iterations +

Review Comment:
                   "(salt= [hidden], saltedPassword= [hidden]", 
iterations=[hidden]";



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to