123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- package com.gxzc.zen.umps.util
- import com.gxzc.zen.api.sys.model.SysUser
- import com.gxzc.zen.common.util.HttpUtil
- import javax.servlet.http.HttpServletRequest
- /**
- * SSO 工具类
- * @author NorthLan
- * @date 2018/3/15
- * @url https://noahlan.com
- */
- object SSOUtil {
- /**
- * 从token中获取当前用户id
- */
- fun getCurUserIdByToken(): Long? {
- return getCurUserIdByToken(HttpUtil.getRequest())
- }
- /**
- * TODO 改改改
- * 从token中获取当前用户id
- */
- fun getCurUserIdByToken(request: HttpServletRequest): Long? {
- val token = try {
- // SSOHelper.attrToken<SSOToken>(request) ?: SSOHelper.getToken(request)
- 1L
- } catch (e: Throwable) {
- null
- }
- return 1L
- // return token?.uid?.toLong()
- }
- /**
- * 获取当前用户
- */
- fun getCurUser(): SysUser? {
- return TL.get()
- }
- /**
- * 获取当前用户id
- */
- fun getCurUserId(): Long? {
- return getCurUser()?.id
- }
- object TL {
- /**
- * 180324
- * 于MetaObjectHandler执行前 每个Controller方法拦截 暂存当前用户引用
- */
- private val CURRENT_USER_TL = ThreadLocal<SysUser>()
- fun set(entity: SysUser?) {
- CURRENT_USER_TL.set(entity)
- }
- fun clear() {
- CURRENT_USER_TL.remove()
- }
- fun get(): SysUser? {
- return CURRENT_USER_TL.get()
- }
- }
- }
|