[
https://issues.apache.org/jira/browse/HIVE-24543?focusedWorklogId=534559&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-534559
]
ASF GitHub Bot logged work on HIVE-24543:
-----------------------------------------
Author: ASF GitHub Bot
Created on: 11/Jan/21 21:48
Start Date: 11/Jan/21 21:48
Worklog Time Spent: 10m
Work Description: vihangk1 commented on a change in pull request #1791:
URL: https://github.com/apache/hive/pull/1791#discussion_r555361475
##########
File path: jdbc/src/java/org/apache/hive/jdbc/saml/HiveJdbcBrowserClient.java
##########
@@ -0,0 +1,322 @@
+/*
+ * 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.hive.jdbc.saml;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.base.Strings;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import java.awt.Desktop;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketTimeoutException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import org.apache.hive.jdbc.Utils.JdbcConnectionParams;
+import org.apache.hive.service.auth.saml.HiveSamlUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * This class is used to execute a browser based SSO workflow with the
authentication mode
+ * is browser.
+ */
+public class HiveJdbcBrowserClient implements IJdbcBrowserClient {
+
+ private static final Logger LOG =
LoggerFactory.getLogger(HiveJdbcBrowserClient.class);
+ // error message when the socket times out.
+ @VisibleForTesting
+ public static final String TIMEOUT_ERROR_MSG = "Timed out while waiting for
server response";
+ private final ServerSocket serverSocket;
+ private HiveJdbcBrowserServerResponse serverResponse;
+ protected JdbcBrowserClientContext clientContext;
+ // By default we wait for 2 min unless overridden by a JDBC connection param
+ // browserResponseTimeout
+ private static final int DEFAULT_SOCKET_TIMEOUT_SECS = 120;
+ private final ExecutorService serverResponseThread =
Executors.newSingleThreadExecutor(
+ new ThreadFactoryBuilder().setNameFormat("Hive-Jdbc-Browser-Client-%d")
+ .setDaemon(true).build());
+
+ HiveJdbcBrowserClient(JdbcConnectionParams connectionParams)
+ throws HiveJdbcBrowserException {
+ serverSocket = getServerSocket(connectionParams.getSessionVars());
+ }
+
+ private ServerSocket getServerSocket(Map<String, String> sessionConf)
+ throws HiveJdbcBrowserException {
+ final ServerSocket serverSocket;
+ int port = Integer.parseInt(sessionConf
+ .getOrDefault(JdbcConnectionParams.AUTH_BROWSER_RESPONSE_PORT, "0"));
+ int timeout = Integer.parseInt(
+
sessionConf.getOrDefault(JdbcConnectionParams.AUTH_BROWSER_RESPONSE_TIMEOUT_SECS,
+ String.valueOf(DEFAULT_SOCKET_TIMEOUT_SECS)));
+ try {
+ serverSocket = new ServerSocket(port, 0,
+ InetAddress.getByName(HiveSamlUtils.LOOP_BACK_INTERFACE));
+ LOG.debug("Browser response timeout is set to {} seconds", timeout);
+ serverSocket.setSoTimeout(timeout * 1000);
+ } catch (IOException e) {
+ throw new HiveJdbcBrowserException("Unable to bind to the localhost");
+ }
+ return serverSocket;
+ }
+
+ public Integer getPort() {
+ return serverSocket.getLocalPort();
Review comment:
serverSocket is a final field and it will always be not-null. If there
is an exception during getServerSocket, the HiveJdbcBrowserClient's constructor
will error out.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 534559)
Time Spent: 4h 10m (was: 4h)
> Support SAML 2.0 as an authentication mechanism
> -----------------------------------------------
>
> Key: HIVE-24543
> URL: https://issues.apache.org/jira/browse/HIVE-24543
> Project: Hive
> Issue Type: New Feature
> Reporter: Vihang Karajgaonkar
> Assignee: Vihang Karajgaonkar
> Priority: Major
> Labels: pull-request-available
> Time Spent: 4h 10m
> Remaining Estimate: 0h
>
> With cloud based deployments, having a SAML 2.0 based authentication support
> in HS2 will be greatly useful in case of federated or external identity
> providers like Okta, PingIdentity or Azure AD.
> This authentication mechanism can initially be only supported on http
> transport mode in HiveServer2 since the SAML 2.0 protocol is primarily
> designed for web clients.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)