anmolnar commented on a change in pull request #4019:
URL: https://github.com/apache/hbase/pull/4019#discussion_r782496823



##########
File path: 
hbase-client/src/main/java/org/apache/hadoop/hbase/security/token/OAuthBearerTokenUtil.java
##########
@@ -0,0 +1,76 @@
+/**
+ *
+ * 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.hbase.security.token;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import javax.security.auth.Subject;
+import org.apache.hadoop.hbase.security.User;
+import org.apache.hadoop.hbase.security.oauthbearer.OAuthBearerToken;
+import 
org.apache.hadoop.hbase.security.oauthbearer.internals.OAuthBearerSaslClientProvider;
+import org.apache.hadoop.io.Text;
+import org.apache.hadoop.security.token.Token;
+import org.apache.yetus.audience.InterfaceAudience;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Utility methods for obtaining OAuthBearer / JWT authentication tokens.
+ */
[email protected]
+public final class OAuthBearerTokenUtil {
+  private static final Logger LOG = 
LoggerFactory.getLogger(OAuthBearerTokenUtil.class);
+  public static final String OAUTHBEARER_MECHANISM = "OAUTHBEARER";
+  public static final String TOKEN_KIND = "JWT_AUTH_TOKEN";
+
+  static {
+    OAuthBearerSaslClientProvider.initialize(); // not part of public API
+    LOG.info("OAuthBearer SASL client provider has been initialized");
+  }
+
+  private OAuthBearerTokenUtil() {  }
+
+  /**
+   * Add token to user's subject private credentials and a hint to provider 
selector
+   * to correctly select OAuthBearer SASL provider.
+   */
+  public static void addTokenForUser(User user, String encodedToken) {
+    user.addToken(new Token<>(null, null, new Text(TOKEN_KIND), null));
+    user.runAs(new PrivilegedAction<Object>() {
+      @Override public Object run() {
+        Subject subject = Subject.getSubject(AccessController.getContext());
+        OAuthBearerToken jwt = new OAuthBearerToken() {
+          @Override public String value() {
+            return encodedToken;
+          }
+
+          @Override public long lifetimeMs() {
+            return 0;

Review comment:
       We would need to decode and parse the base64 token to figure it out, but 
expiry information is usally provided on the token generation APIs. I believe 
Knox also include that in the response.
   
   Specifically in the Util class I think we can just get it as a parameter. 
Also the principal could be the username of Hadoop user context.




-- 
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]


Reply via email to