You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2020/09/02 17:57:37 UTC

[GitHub] [arrow] jduo commented on a change in pull request #7994: ARROW-9804: [FlightRPC] Flight auth redesign

jduo commented on a change in pull request #7994:
URL: https://github.com/apache/arrow/pull/7994#discussion_r482260625



##########
File path: java/flight/flight-core/src/main/java/org/apache/arrow/flight/auth/ServerAuthMiddleware.java
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.arrow.flight.auth;
+
+import org.apache.arrow.flight.CallContext;
+import org.apache.arrow.flight.CallHeaders;
+import org.apache.arrow.flight.CallInfo;
+import org.apache.arrow.flight.CallStatus;
+import org.apache.arrow.flight.FlightServerMiddleware;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Middleware that's used to validate credentials during the handshake and verify
+ * the bearer token in subsequent requests.
+ */
+public class ServerAuthMiddleware implements FlightServerMiddleware {
+  private static final Logger logger = LoggerFactory.getLogger(ServerAuthMiddleware.class);
+
+  /**
+   * Factory for accessing ServerAuthMiddleware.
+   */
+  public static class Factory implements FlightServerMiddleware.Factory<ServerAuthMiddleware> {
+    private final ServerAuthHandler authHandler;
+    private final GeneratedBearerTokenAuthHandler bearerTokenAuthHandler;
+
+    /**
+     * Construct a factory with the given auth handler.
+     * @param authHandler The auth handler what will be used for authenticating requests.
+     */
+    public Factory(ServerAuthHandler authHandler) {
+      this.authHandler = authHandler;
+      bearerTokenAuthHandler = authHandler.enableCachedCredentials() ?
+          new GeneratedBearerTokenAuthHandler() : null;
+    }
+
+    @Override
+    public ServerAuthMiddleware onCallStarted(CallInfo callInfo, CallHeaders incomingHeaders, CallContext context) {
+      logger.debug("Call name: {}", callInfo.method().name());
+      // Check if bearer token auth is being used, and if we've enabled use of server-generated
+      // bearer tokens.
+      if (authHandler.enableCachedCredentials()) {
+        final String bearerTokenFromHeaders =
+            AuthUtilities.getValueFromAuthHeader(incomingHeaders, AuthConstants.BEARER_PREFIX);
+        if (bearerTokenFromHeaders != null) {
+          final ServerAuthHandler.AuthResult result = bearerTokenAuthHandler.authenticate(incomingHeaders);

Review comment:
       No, the idea is you don't know which header you need to authenticate from. We're going to change this such that bearer token generation is moved out of this middleware and into an implementation of ServerAuthHandler which will make this more claer.




----------------------------------------------------------------
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:
users@infra.apache.org