smengcl commented on code in PR #3576: URL: https://github.com/apache/ozone/pull/3576#discussion_r919561906
########## hadoop-ozone/integration-test/src/test/java/org/apache/hadoop/ozone/om/multitenant/RangerUserRequest.java: ########## @@ -0,0 +1,275 @@ +/** + * 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 com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParseException; +import com.google.gson.JsonParser; +import org.apache.kerby.util.Base64; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.nio.charset.StandardCharsets; + +import static java.net.HttpURLConnection.HTTP_OK; +// TODO: MOVE THIS HERE. +import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OM_RANGER_ADMIN_CREATE_USER_HTTP_ENDPOINT; +import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OM_RANGER_ADMIN_DELETE_USER_HTTP_ENDPOINT; +import static org.apache.hadoop.ozone.OzoneConsts.OZONE_OM_RANGER_ADMIN_GET_USER_HTTP_ENDPOINT; + +/** + * Helper class to create and delete users in Ranger because RangerClient + * doesn't support it yet. + */ +public class RangerUserRequest { + + private static final Logger LOG = + LoggerFactory.getLogger(RangerUserRequest.class); + + private String rangerEndpoint; + + // Value of HTTP auth header + private String authHeaderValue; + + RangerUserRequest(String rangerHttpsAddress, String userName, String passwd) { + + // Trim trailing slash + if (rangerHttpsAddress.endsWith("/")) { + rangerHttpsAddress = + rangerHttpsAddress.substring(0, rangerHttpsAddress.length() - 1); + } + this.rangerEndpoint = rangerHttpsAddress; + + String auth = userName + ":" + passwd; + byte[] encodedAuth = + Base64.encodeBase64(auth.getBytes(StandardCharsets.UTF_8)); + authHeaderValue = "Basic " + + new String(encodedAuth, StandardCharsets.UTF_8); + + setupRangerIgnoreServerCertificate(); + } + + private void setupRangerIgnoreServerCertificate() { + // Create a trust manager that does not validate certificate chains Review Comment: Oh. This part is only in the test code and not used in production, and was copied from our earlier homemade Ranger client. This could be useful during dev, though the proper way would be to set a correct truststore. -- 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]
