smengcl commented on code in PR #3408:
URL: https://github.com/apache/ozone/pull/3408#discussion_r877169862


##########
hadoop-ozone/ozone-manager/src/main/java/org/apache/hadoop/ozone/om/multitenant/RangerClientMultiTenantAccessController.java:
##########
@@ -0,0 +1,314 @@
+/*
+ * 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.hadoop.ozone.om.multitenant;
+
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_KERBEROS_KEYTAB_FILE_KEY;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_OM_KERBEROS_PRINCIPAL_KEY;
+import static 
org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_RANGER_HTTPS_ADDRESS_KEY;
+import static org.apache.hadoop.ozone.om.OMConfigKeys.OZONE_RANGER_SERVICE;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import org.apache.hadoop.hdds.conf.OzoneConfiguration;
+import org.apache.hadoop.ozone.OmUtils;
+import org.apache.hadoop.ozone.security.acl.IAccessAuthorizer;
+import org.apache.hadoop.security.SecurityUtil;
+import org.apache.http.auth.BasicUserPrincipal;
+import org.apache.ranger.RangerServiceException;
+import org.apache.ranger.plugin.model.RangerPolicy;
+import org.apache.ranger.plugin.model.RangerRole;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.ranger.RangerClient;
+
+/**
+ * Implementation of {@link MultiTenantAccessController} using the
+ * {@link RangerClient} to communicate with Ranger.
+ */
+public class RangerClientMultiTenantAccessController implements
+    MultiTenantAccessController {
+
+  private static final Logger LOG = LoggerFactory
+      .getLogger(RangerClientMultiTenantAccessController.class);
+
+  private final RangerClient client;
+  private final String rangerServiceName;
+  private final Map<IAccessAuthorizer.ACLType, String> aclToString;
+  private final Map<String, IAccessAuthorizer.ACLType> stringToAcl;
+  private final String omPrincipal;
+
+  public RangerClientMultiTenantAccessController(OzoneConfiguration conf)
+      throws IOException {
+    aclToString = MultiTenantAccessController.getRangerAclStrings();
+    stringToAcl = new HashMap<>();
+    aclToString.forEach((type, string) -> stringToAcl.put(string, type));
+
+    // TODO: Double check configuration set up after HDDS-6612 is merged.
+    String rangerHttpsAddress = conf.get(OZONE_RANGER_HTTPS_ADDRESS_KEY);
+    rangerServiceName = conf.get(OZONE_RANGER_SERVICE);
+    String configuredOmPrincipal = conf.get(OZONE_OM_KERBEROS_PRINCIPAL_KEY);
+    // Replace _HOST pattern with host name in the Kerberos principal. Ranger
+    // client currently does not do this automatically.
+    omPrincipal = SecurityUtil.getServerPrincipal(
+        configuredOmPrincipal, OmUtils.getOmAddress(conf).getHostName());
+    String keytabPath = conf.get(OZONE_OM_KERBEROS_KEYTAB_FILE_KEY);
+
+    client = new RangerClient(rangerHttpsAddress,
+        "kerberos", omPrincipal, keytabPath, rangerServiceName, "ozone");

Review Comment:
   nit
   
   ```suggestion
       client = new RangerClient(rangerHttpsAddress, 
KERBEROS.name().toLowerCase(),
           omPrincipal, keytabPath, rangerServiceName, OzoneConsts.OZONE);
   ```
   
   (don't forget the imports)
   
   



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to