laminelam commented on code in PR #857:
URL: https://github.com/apache/solr/pull/857#discussion_r930273716


##########
solr/solrj/src/java/org/apache/solr/common/cloud/DigestZkACLProvider.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * 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.solr.common.cloud;
+
+import static 
org.apache.zookeeper.server.auth.DigestAuthenticationProvider.generateDigest;
+
+import java.lang.invoke.MethodHandles;
+import java.security.NoSuchAlgorithmException;
+import java.util.ArrayList;
+import java.util.List;
+import org.apache.solr.common.SolrException;
+import org.apache.solr.common.StringUtils;
+import org.apache.solr.common.cloud.ZkCredentialsInjector.ZkCredential;
+import org.apache.zookeeper.ZooDefs;
+import org.apache.zookeeper.data.ACL;
+import org.apache.zookeeper.data.Id;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A class that expects a {@link ZkCredentialsInjector} to create Zookeeper 
ACLs using digest scheme
+ */
+public class DigestZkACLProvider extends SecurityAwareZkACLProvider {
+
+  private static final Logger log = 
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+  /** Called by reflective instantiation */
+  public DigestZkACLProvider() {}
+
+  public DigestZkACLProvider(ZkCredentialsInjector zkCredentialsInjector) {
+    super(zkCredentialsInjector);
+  }
+
+  /**
+   * @return Set of ACLs to return for non-security related znodes
+   */
+  @Override
+  protected List<ACL> createNonSecurityACLsToAdd() {
+    return createACLsToAdd(true);
+  }
+
+  /**
+   * Provider ACL Credential
+   *
+   * @return Set of ACLs to return security-related znodes
+   */
+  @Override
+  protected List<ACL> createSecurityACLsToAdd() {
+    return createACLsToAdd(false);
+  }
+
+  protected List<ACL> createACLsToAdd(boolean includeReadOnly) {
+    List<ACL> result = new ArrayList<>();
+    List<ZkCredential> zkCredentials = 
zkCredentialsInjector.getZkCredentials();
+    log.debug("createACLsToAdd using ZkCredentials: {}", zkCredentials);
+    for (ZkCredential zkCredential : zkCredentials) {
+      if (StringUtils.isEmpty(zkCredential.getUsername())
+          || StringUtils.isEmpty(zkCredential.getPassword())) {
+        continue;
+      }
+      Id id = createACLId(zkCredential.getUsername(), 
zkCredential.getPassword());
+      int perms;
+      if (zkCredential.isAll()) {
+        // Not to have to provide too much credentials and ACL information to 
the process it is
+        // assumed that you want "ALL"-acls
+        // added to the user you are using to connect to ZK
+        perms = ZooDefs.Perms.ALL;
+      } else if (includeReadOnly && zkCredential.isReadonly()) {
+        // Besides, that support for adding additional "READONLY"-acls for 
another user
+        perms = ZooDefs.Perms.READ;
+      } else continue;

Review Comment:
   This is to ignore invalid perms (neither All, nor ReadyOnly). 



-- 
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: issues-unsubscr...@solr.apache.org

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


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to