Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ class AuthenticationFilter(conf: CelebornConf, serviceName: String) extends Filt

override def init(filterConfig: FilterConfig): Unit = {
initAuthHandlers()
if (authSchemes.nonEmpty && authSchemeHandlers.isEmpty) {
throw new ServletException(
s"No authentication handler registered for the configured schemes" +
s" ${authSchemes.mkString(", ")}, refusing to serve requests without authentication")
}
}

private[celeborn] def getMatchedHandler(authorization: String): Option[AuthenticationHandler] = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ class BasicAuthenticationHandler(providerClass: String) extends AuthenticationHa
override def authenticationSupported: Boolean = {
Option(providerClass).exists { _ =>
try {
Class.forName(providerClass).isAssignableFrom(classOf[PasswdAuthenticationProvider])
true
classOf[PasswdAuthenticationProvider].isAssignableFrom(Class.forName(providerClass))
} catch {
case _: Throwable => false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ class BearerAuthenticationHandler(providerClass: String)
override def authenticationSupported: Boolean = {
Option(providerClass).exists { _ =>
try {
Class.forName(providerClass).isAssignableFrom(classOf[TokenAuthenticationProvider])
true
classOf[TokenAuthenticationProvider].isAssignableFrom(Class.forName(providerClass))
} catch {
case _: Throwable => false
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.celeborn.server.common.http.authentication

import javax.servlet.ServletException

import org.apache.celeborn.CelebornFunSuite
import org.apache.celeborn.common.CelebornConf
import org.apache.celeborn.server.common.Service

class AuthenticationHandlerSuite extends CelebornFunSuite {

test("basic handler supports providers implementing PasswdAuthenticationProvider") {
assert(new BasicAuthenticationHandler(
classOf[UserDefinedPasswordAuthenticationProviderImpl].getName).authenticationSupported)
assert(!new BasicAuthenticationHandler(
classOf[UserDefineTokenAuthenticationProviderImpl].getName).authenticationSupported)
assert(!new BasicAuthenticationHandler("non.existent.Provider").authenticationSupported)
}

test("bearer handler supports providers implementing TokenAuthenticationProvider") {
assert(new BearerAuthenticationHandler(
classOf[UserDefineTokenAuthenticationProviderImpl].getName).authenticationSupported)
assert(!new BearerAuthenticationHandler(
classOf[UserDefinedPasswordAuthenticationProviderImpl].getName).authenticationSupported)
assert(!new BearerAuthenticationHandler("non.existent.Provider").authenticationSupported)
}

test("fail fast when no handler registered for the configured schemes") {
val conf = new CelebornConf()
conf.set(CelebornConf.MASTER_HTTP_AUTH_SUPPORTED_SCHEMES, Seq("BASIC"))
conf.set(CelebornConf.MASTER_HTTP_AUTH_BASIC_PROVIDER, "non.existent.Provider")
intercept[ServletException] {
new AuthenticationFilter(conf, Service.MASTER).init(null)
}
}
}
Loading