You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@linkis.apache.org by al...@apache.org on 2022/02/28 09:31:43 UTC

[incubator-linkis] 01/11: Gateway supports adding login user suffix after user login #1537

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

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

commit 7bac74d8923f85e2e9f81dcab40ed25ec769b3ec
Author: peacewong <wp...@gmail.com>
AuthorDate: Mon Feb 21 17:37:14 2022 +0800

    Gateway supports adding login user suffix after user login #1537
---
 .../linkis/server/conf/ModuleConfiguration.scala   | 25 ---------------------
 .../linkis/server/conf/ServerConfiguration.scala   | 26 ++++++++++++++++++----
 2 files changed, 22 insertions(+), 29 deletions(-)

diff --git a/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ModuleConfiguration.scala b/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ModuleConfiguration.scala
deleted file mode 100644
index 35cf98d..0000000
--- a/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ModuleConfiguration.scala
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * 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.linkis.server.conf
-
-import org.apache.linkis.common.conf.CommonVars
-
-
-object ModuleConfiguration {
-  val DATA_OPERATE = CommonVars("wds.linkis.data.operate", "false")
-}
diff --git a/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ServerConfiguration.scala b/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ServerConfiguration.scala
index 921b0d1..718dabf 100644
--- a/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ServerConfiguration.scala
+++ b/linkis-commons/linkis-module/src/main/scala/org/apache/linkis/server/conf/ServerConfiguration.scala
@@ -38,25 +38,38 @@ object ServerConfiguration extends Logging{
     throw new BDPInitServerException(10010, "DataWorkCloud service must set the version, please add property [[wds.linkis.server.version]] to properties file.")
   }
 
-  val cryptKey =  new BASE64Encoder().encode(CommonVars("wds.linkis.crypt.key", "bdp-for-server").getValue.getBytes)
+  val cryptKey = new BASE64Encoder().encode(CommonVars("wds.linkis.crypt.key", "bdp-for-server").getValue.getBytes)
+
   private val ticketHeader = CommonVars("wds.linkis.ticket.header", "bfs_").getValue
-  def getUsernameByTicket(ticketId: String): Option[String] = if(StringUtils.isEmpty(ticketId)) None
+
+  def getUsernameByTicket(ticketId: String): Option[String] = if (StringUtils.isEmpty(ticketId)) None
   else {
     val userName = DESUtil.decrypt(ticketId, ServerConfiguration.cryptKey)
     if(userName.startsWith(ticketHeader)) Some(userName.substring(ticketHeader.length))
     else None
   }
-  def getUsernameByTicket(ticketId: Any): Option[String] = if(ticketId == null) None else getUsernameByTicket(ticketId.toString)
+  def getUsernameByTicket(ticketId: Any): Option[String] = if (ticketId == null) None else getUsernameByTicket(ticketId.toString)
+
   def getTicketByUsername(userName: String): String = {
+    if (LINKIE_USERNAME_SUFFIX_ENABLE) {
+      val username = userName.split(",")(0)
+      val time = userName.split(",")(1)
+      val proxyUser = username + LINKIE_USERNAME_SUFFIX_NAME
+      logger.info(s"$username will be proxied as ${proxyUser}")
+      DESUtil.encrypt(ticketHeader + proxyUser + "," + time, ServerConfiguration.cryptKey)
+    } else {
       DESUtil.encrypt(ticketHeader + userName, ServerConfiguration.cryptKey)
+    }
   }
 
   val BDP_TEST_USER = CommonVars("wds.linkis.test.user", "")
 
   val BDP_SERVER_HOME = CommonVars("wds.linkis.server.home", CommonVars("LINKIS_HOME", "").getValue)
   val BDP_SERVER_DISTINCT_MODE = CommonVars("wds.linkis.server.distinct.mode", new Boolean(true))
-  if(!BDP_SERVER_DISTINCT_MODE.getValue && StringUtils.isEmpty(BDP_SERVER_HOME.getValue))
+
+  if (!BDP_SERVER_DISTINCT_MODE.getValue && StringUtils.isEmpty(BDP_SERVER_HOME.getValue)) {
     throw new BDPInitServerException(11000, "wds.linkis.server.homeĉˆ–BDP_SERVER_HOME haven't set!")
+  }
   val BDP_SERVER_SOCKET_MODE = CommonVars("wds.linkis.server.socket.mode", new Boolean(false))
   val BDP_SERVER_IDENT_STRING = CommonVars("wds.linkis.server.ident.string", "true")
   val BDP_SERVER_SERVER_JETTY_NAME = CommonVars("wds.linkis.server.jetty.name", "")
@@ -102,4 +115,9 @@ object ServerConfiguration extends Logging{
   val IS_GATEWAY = CommonVars("wds.linkis.is.gateway", "false")
   val BDP_SERVER_WEB_ALLOW_ORIGIN = CommonVars("wds.linkis.server.web.alloworigin", "*")
   val BDP_SERVER_WEB_ALLOW_METHOD = CommonVars("wds.linkis.server.web.allowmethod", "POST,GET,OPTIONS,PUT,HEAD,DELETE")
+
+  val LINKIE_USERNAME_SUFFIX_ENABLE = CommonVars("linkis.username.suffix.enable", false).getValue
+
+  val LINKIE_USERNAME_SUFFIX_NAME = CommonVars("linkis.username.suffix.name", "_c").getValue
+
 }

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