Browse Source

修复request获取不到的问题

NorthLan 7 years ago
parent
commit
a28090cf09

+ 1 - 1
zen-api/src/main/kotlin/com/gxzc/zen/sso/aop/CurrentUserHandler.kt

@@ -16,7 +16,7 @@ import javax.servlet.http.HttpServletResponse
 class CurrentUserHandler : HandlerInterceptorAdapter() {
 
     override fun preHandle(request: HttpServletRequest?, response: HttpServletResponse?, handler: Any?): Boolean {
-        SSOUtil.TL.set(SysUserUtil.getById(SSOUtil.getCurUserId()!!)!!)
+        SSOUtil.TL.set(SysUserUtil.getById(SSOUtil.getCurUserId(request!!)!!)!!)
         return super.preHandle(request, response, handler)
     }
 

+ 6 - 1
zen-api/src/main/kotlin/com/gxzc/zen/umps/util/SSOUtil.kt

@@ -4,6 +4,7 @@ import com.baomidou.kisso.SSOHelper
 import com.baomidou.kisso.SSOToken
 import com.gxzc.zen.api.sys.model.SysUser
 import com.gxzc.zen.common.util.HttpUtil
+import javax.servlet.http.HttpServletRequest
 
 /**
  * SSO 工具类
@@ -13,7 +14,11 @@ import com.gxzc.zen.common.util.HttpUtil
  */
 object SSOUtil {
     fun getCurUserId(): Long? {
-        val token = SSOHelper.attrToken<SSOToken>(HttpUtil.getRequest()) ?: SSOHelper.getToken(HttpUtil.getRequest())
+        return getCurUserId(HttpUtil.getRequest())
+    }
+
+    fun getCurUserId(request: HttpServletRequest): Long? {
+        val token = SSOHelper.attrToken<SSOToken>(request) ?: SSOHelper.getToken(request)
         return token?.uid?.toLong()
     }