|
@@ -13,11 +13,17 @@ import javax.servlet.http.HttpServletRequest
|
|
|
* @url https://noahlan.com
|
|
|
*/
|
|
|
object SSOUtil {
|
|
|
- fun getCurUserId(): Long? {
|
|
|
- return getCurUserId(HttpUtil.getRequest())
|
|
|
+ /**
|
|
|
+ * 从token中获取当前用户id
|
|
|
+ */
|
|
|
+ fun getCurUserIdByToken(): Long? {
|
|
|
+ return getCurUserIdByToken(HttpUtil.getRequest())
|
|
|
}
|
|
|
|
|
|
- fun getCurUserId(request: HttpServletRequest): Long? {
|
|
|
+ /**
|
|
|
+ * 从token中获取当前用户id
|
|
|
+ */
|
|
|
+ fun getCurUserIdByToken(request: HttpServletRequest): Long? {
|
|
|
val token = try {
|
|
|
SSOHelper.attrToken<SSOToken>(request) ?: SSOHelper.getToken(request)
|
|
|
} catch (e: Throwable) {
|
|
@@ -26,10 +32,20 @@ object SSOUtil {
|
|
|
return token?.uid?.toLong()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前用户
|
|
|
+ */
|
|
|
fun getCurUser(): SysUser? {
|
|
|
return TL.get()
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 获取当前用户id
|
|
|
+ */
|
|
|
+ fun getCurUserId(): Long? {
|
|
|
+ return getCurUser()?.id
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
object TL {
|
|
|
/**
|
|
@@ -46,7 +62,7 @@ object SSOUtil {
|
|
|
CURRENT_USER_TL.remove()
|
|
|
}
|
|
|
|
|
|
- fun get(): SysUser {
|
|
|
+ fun get(): SysUser? {
|
|
|
return CURRENT_USER_TL.get()
|
|
|
}
|
|
|
}
|