Skip to content

Commit

Permalink
clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
wangjunbo committed Feb 22, 2024
1 parent 4e05065 commit dee5341
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ class KyuubiRestFrontendService(override val serverable: Serverable)

private def startInternal(): Unit = {
val contextHandler = ApiRootResource.getServletHandler(this)
val holder = new FilterHolder(
new AuthenticationFilter(
conf,
conf.get(FRONTEND_REST_AUTHENTICATION_METHOD).map(AuthTypes.withName),
REST))
val holder = new FilterHolder(new AuthenticationFilter(conf, REST))
contextHandler.addFilter(holder, "/v1/*", EnumSet.allOf(classOf[DispatcherType]))
val authenticationFactory = new KyuubiHttpAuthenticationFactory(conf)
server.addHandler(authenticationFactory.httpHandlerWrapperFactory.wrapHandler(contextHandler))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,7 @@ class ThriftHttpServlet(
private var isCookieSecure = false
private var isHttpOnlyCookie = false
private val X_FORWARDED_FOR_HEADER = "X-Forwarded-For"
private val authenticationFilter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
THRIFT_HTTP)
private val authenticationFilter = new AuthenticationFilter(conf, THRIFT_HTTP)

override def init(): Unit = {
isCookieAuthEnabled = conf.get(KyuubiConf.FRONTEND_THRIFT_HTTP_COOKIE_AUTH_ENABLED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@ import scala.collection.mutable

import org.apache.kyuubi.Logging
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.FrontendProtocol
import org.apache.kyuubi.config.KyuubiConf.{AUTHENTICATION_METHOD, FRONTEND_PROXY_HTTP_CLIENT_IP_HEADER, FRONTEND_REST_AUTHENTICATION_METHOD}
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.{FrontendProtocol, REST}
import org.apache.kyuubi.server.http.util.HttpAuthUtils.AUTHORIZATION_HEADER
import org.apache.kyuubi.service.authentication.{AuthTypes, InternalSecurityAccessor}
import org.apache.kyuubi.service.authentication.AuthTypes.{KERBEROS, NOSASL}

class AuthenticationFilter(
conf: KyuubiConf,
authTypes: Seq[AuthTypes.Value],
protocol: FrontendProtocol) extends Filter
class AuthenticationFilter(conf: KyuubiConf, protocol: FrontendProtocol) extends Filter
with Logging {
import AuthenticationFilter._
import AuthSchemes._
Expand All @@ -60,6 +57,10 @@ class AuthenticationFilter(
}

private[kyuubi] def initAuthHandlers(): Unit = {
val authTypes = protocol match {
case REST => conf.get(FRONTEND_REST_AUTHENTICATION_METHOD).map(AuthTypes.withName)
case _ => conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName)
}
val spnegoKerberosEnabled = authTypes.contains(KERBEROS)
val basicAuthTypeOpt = {
if (authTypes == Set(NOSASL)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ package org.apache.kyuubi.server.http.authentication

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.AUTHENTICATION_METHOD
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.REST
import org.apache.kyuubi.service.authentication.AuthTypes

class RestAuthenticationFilterSuite extends KyuubiFunSuite {
test("add auth handler and destroy") {
val conf = KyuubiConf()
val filter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
REST)
val filter = new AuthenticationFilter(conf, REST)
filter.addAuthHandler(new BasicAuthenticationHandler(null, REST))
assert(filter.authSchemeHandlers.isEmpty)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, REST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,13 @@ package org.apache.kyuubi.server.http.authentication

import org.apache.kyuubi.KyuubiFunSuite
import org.apache.kyuubi.config.KyuubiConf
import org.apache.kyuubi.config.KyuubiConf.AUTHENTICATION_METHOD
import org.apache.kyuubi.config.KyuubiConf.FrontendProtocols.THRIFT_HTTP
import org.apache.kyuubi.service.authentication.AuthTypes

class ThriftHttpAuthenticationFilterSuite extends KyuubiFunSuite {
test("add auth handler and destroy") {
val conf = KyuubiConf()
val filter =
new AuthenticationFilter(
conf,
conf.get(AUTHENTICATION_METHOD).map(AuthTypes.withName),
THRIFT_HTTP)
val filter = new AuthenticationFilter(conf, THRIFT_HTTP)
filter.addAuthHandler(new BasicAuthenticationHandler(null, THRIFT_HTTP))
assert(filter.authSchemeHandlers.isEmpty)
filter.addAuthHandler(new BasicAuthenticationHandler(AuthTypes.LDAP, THRIFT_HTTP))
Expand Down

0 comments on commit dee5341

Please sign in to comment.