Class SessionSecurityAuthenticateUserService
java.lang.Object
com.codeupsoft.component.security.service.impl.SessionSecurityAuthenticateUserService
- All Implemented Interfaces:
SecurityAuthenticateUserService
public class SessionSecurityAuthenticateUserService
extends Object
implements SecurityAuthenticateUserService
基于Session的安全认证用户服务实现类.
提供基于Session的用户认证功能,包括用户信息存储、获取和登出操作. 该实现使用传统的Session机制管理用户会话,适用于不使用Redis的场景.
- Author:
- Liu,Dongdong
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void清除当前请求对象.createToken(LoginUser loginUser) 创建访问令牌.getLoginUser(jakarta.servlet.http.HttpServletRequest request) 从HTTP请求中获取当前登录用户信息.voidlogout(jakarta.servlet.http.HttpServletRequest request) 登出当前用户.static voidsetCurrentRequest(jakarta.servlet.http.HttpServletRequest request) 设置当前请求对象.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface SecurityAuthenticateUserService
verifyUser
-
Constructor Details
-
SessionSecurityAuthenticateUserService
public SessionSecurityAuthenticateUserService()
-
-
Method Details
-
setCurrentRequest
public static void setCurrentRequest(jakarta.servlet.http.HttpServletRequest request) 设置当前请求对象.在过滤器中调用此方法设置当前请求对象,以便在createToken方法中使用.
- Parameters:
request- 当前HTTP请求对象
-
clearCurrentRequest
public static void clearCurrentRequest()清除当前请求对象.在请求处理完成后调用此方法清除ThreadLocal中的请求对象.
-
getLoginUser
Description copied from interface:SecurityAuthenticateUserService从HTTP请求中获取当前登录用户信息.通过解析请求头或请求参数中的令牌,获取已登录用户的详细信息. 如果请求中没有有效的令牌或令牌已失效,可能返回 null.
- Specified by:
getLoginUserin interfaceSecurityAuthenticateUserService- Parameters:
request- HTTP请求对象- Returns:
- 登录用户信息,如果未登录或令牌无效则返回 null
-
logout
public void logout(jakarta.servlet.http.HttpServletRequest request) Description copied from interface:SecurityAuthenticateUserService登出当前用户.从HTTP请求中获取当前登录用户信息,并注销当前用户.
- Specified by:
logoutin interfaceSecurityAuthenticateUserService- Parameters:
request- HTTP请求对象
-
createToken
创建访问令牌.基于Session的认证方式不需要生成令牌,而是将用户信息存储在Session中. 此实现将登录用户信息保存到Session中,并返回固定标识符"SESSION".
- Specified by:
createTokenin interfaceSecurityAuthenticateUserService- Parameters:
loginUser- 登录用户信息- Returns:
- 固定字符串"SESSION",表示使用Session认证
-