You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by pe...@apache.org on 2023/03/08 03:58:51 UTC

[linkis] branch dev-1.3.2 updated: linkis-gateway-core - add interface token-login (#4339)

This is an automated email from the ASF dual-hosted git repository.

peacewong pushed a commit to branch dev-1.3.2
in repository https://gitbox.apache.org/repos/asf/linkis.git


The following commit(s) were added to refs/heads/dev-1.3.2 by this push:
     new 7511de515 linkis-gateway-core - add interface token-login (#4339)
7511de515 is described below

commit 7511de5157daa1cf1e3c0bb42ebea22171abdbff
Author: Alexyang <xu...@qq.com>
AuthorDate: Wed Mar 8 11:58:46 2023 +0800

    linkis-gateway-core - add interface token-login (#4339)
---
 .../org/apache/linkis/gateway/security/UserRestful.scala     |  8 ++++++++
 .../linkis/gateway/security/token/TokenAuthentication.scala  | 12 +++++++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/UserRestful.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/UserRestful.scala
index 5cbdfdca2..6e3aca6c9 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/UserRestful.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/UserRestful.scala
@@ -21,6 +21,7 @@ import org.apache.linkis.common.utils.{Logging, RSAUtils, Utils}
 import org.apache.linkis.gateway.config.GatewayConfiguration
 import org.apache.linkis.gateway.http.GatewayContext
 import org.apache.linkis.gateway.security.sso.SSOInterceptor
+import org.apache.linkis.gateway.security.token.TokenAuthentication
 import org.apache.linkis.protocol.usercontrol.{
   RequestLogin,
   RequestRegister,
@@ -75,6 +76,13 @@ abstract class AbstractUserRestful extends UserRestful with Logging {
             .ok(loginUser + "Already logged in, please log out before signing in(已经登录,请先退出再进行登录)!")
             .data("userName", loginUser)
         }(_ => login(gatewayContext))
+      case "token-login" =>
+        if (!"POST".equalsIgnoreCase(gatewayContext.getRequest.getMethod)) {
+          Message.error("Only support method POST")
+        } else {
+          TokenAuthentication.tokenAuth(gatewayContext, true)
+          return
+        }
       case "logout" => logout(gatewayContext)
       case "userInfo" => userInfo(gatewayContext)
       case "publicKey" => publicKey(gatewayContext)
diff --git a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/token/TokenAuthentication.scala b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/token/TokenAuthentication.scala
index 4b3fde6f1..9a460eb52 100644
--- a/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/token/TokenAuthentication.scala
+++ b/linkis-spring-cloud-services/linkis-service-gateway/linkis-gateway-core/src/main/scala/org/apache/linkis/gateway/security/token/TokenAuthentication.scala
@@ -43,7 +43,7 @@ object TokenAuthentication extends Logging {
       gatewayContext.getRequest.getCookies.containsKey(TOKEN_USER_KEY))
   }
 
-  def tokenAuth(gatewayContext: GatewayContext): Boolean = {
+  def tokenAuth(gatewayContext: GatewayContext, login: Boolean = false): Boolean = {
     if (!ENABLE_TOKEN_AUTHENTICATION.getValue) {
       val message =
         Message.noLogin(s"Gateway未启用token认证,请采用其他认证方式!") << gatewayContext.getRequest.getRequestURI
@@ -95,6 +95,16 @@ object TokenAuthentication extends Logging {
       logger.info(
         s"Token authentication succeed, uri: ${gatewayContext.getRequest.getRequestURI}, token: $token, tokenUser: $tokenUser."
       )
+      if (login) {
+        logger.info(
+          s"Token authentication succeed, uri: ${gatewayContext.getRequest.getRequestURI}, token: $token, tokenUser: $tokenUser."
+        )
+        GatewaySSOUtils.setLoginUser(gatewayContext, tokenUser)
+        val msg =
+          Message.ok("login successful(登录成功)!").data("userName", tokenUser).data("isAdmin", false)
+        SecurityFilter.filterResponse(gatewayContext, msg)
+        return false
+      }
       if (GatewayConfiguration.ENABLE_TOEKN_AUTHENTICATION_ALIVE.getValue || tokenAlive) {
         if (logger.isDebugEnabled()) {
           logger.debug(s"Token auth of user : ${tokenUser} has param : tokenAlive : true.")


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@linkis.apache.org
For additional commands, e-mail: commits-help@linkis.apache.org