mirror of https://gitee.com/stylefeng/roses
【7.3.2】【auth】更新登录会话管理
parent
385f5fd783
commit
ac6bab76a2
|
@ -33,10 +33,8 @@ import cn.stylefeng.roses.kernel.auth.api.cookie.SessionCookieCreator;
|
|||
import cn.stylefeng.roses.kernel.auth.api.expander.AuthConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.auth.api.pojo.login.LoginUser;
|
||||
import cn.stylefeng.roses.kernel.cache.api.CacheOperatorApi;
|
||||
import cn.stylefeng.roses.kernel.cache.api.tenant.TenantCacheProxyFactory;
|
||||
import cn.stylefeng.roses.kernel.message.api.expander.WebSocketConfigExpander;
|
||||
import cn.stylefeng.roses.kernel.rule.callback.ConfigUpdateCallback;
|
||||
import cn.stylefeng.roses.kernel.rule.constants.TenantConstants;
|
||||
import cn.stylefeng.roses.kernel.rule.util.HttpServletUtil;
|
||||
|
||||
import javax.servlet.http.Cookie;
|
||||
|
@ -94,19 +92,16 @@ public class DefaultSessionManager implements SessionManagerApi, ConfigUpdateCal
|
|||
@Override
|
||||
public void createSession(String token, LoginUser loginUser, Boolean createCookie) {
|
||||
|
||||
CacheOperatorApi<LoginUser> tenantCacheProxy = TenantCacheProxyFactory.createTenantCacheProxy(loginUser.getTenantCode(), loginUserCache);
|
||||
CacheOperatorApi<Set<String>> allPlaceLoginTokenCacheProxy = TenantCacheProxyFactory.createTenantCacheProxy(loginUser.getTenantCode(), allPlaceLoginTokenCache);
|
||||
|
||||
// 装配用户信息的缓存
|
||||
tenantCacheProxy.put(token, loginUser, sessionExpiredSeconds);
|
||||
loginUserCache.put(token, loginUser, sessionExpiredSeconds);
|
||||
|
||||
// 装配用户token的缓存
|
||||
Set<String> theUserTokens = allPlaceLoginTokenCacheProxy.get(loginUser.getUserId().toString());
|
||||
Set<String> theUserTokens = allPlaceLoginTokenCache.get(loginUser.getUserId().toString());
|
||||
if (theUserTokens == null) {
|
||||
theUserTokens = new HashSet<>();
|
||||
}
|
||||
theUserTokens.add(token);
|
||||
allPlaceLoginTokenCacheProxy.put(loginUser.getUserId().toString(), theUserTokens);
|
||||
allPlaceLoginTokenCache.put(loginUser.getUserId().toString(), theUserTokens);
|
||||
|
||||
// 如果开启了cookie存储会话信息,则需要给HttpServletResponse添加一个cookie
|
||||
if (createCookie) {
|
||||
|
@ -128,8 +123,7 @@ public class DefaultSessionManager implements SessionManagerApi, ConfigUpdateCal
|
|||
|
||||
@Override
|
||||
public LoginUser getSession(String token) {
|
||||
CacheOperatorApi<LoginUser> tenantCacheProxy = TenantCacheProxyFactory.createTenantCacheProxy(TenantConstants.MASTER_DATASOURCE_NAME, loginUserCache);
|
||||
return tenantCacheProxy.get(token);
|
||||
return loginUserCache.get(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -142,6 +142,20 @@ public interface CacheOperatorApi<T> {
|
|||
*/
|
||||
String getCommonKeyPrefix();
|
||||
|
||||
/**
|
||||
* 是否按租户维度去切割缓存(不推荐开启)
|
||||
* <p>
|
||||
* key的组成方式:租户前缀:业务前缀:业务key
|
||||
* <p>
|
||||
* 如果不开启租户切割,则租户前缀一直会为master:
|
||||
*
|
||||
* @author fengshuonan
|
||||
* @date 2022/11/9 19:02
|
||||
*/
|
||||
default Boolean divideByTenant() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取最终的计算前缀
|
||||
* <p>
|
||||
|
@ -201,6 +215,14 @@ public interface CacheOperatorApi<T> {
|
|||
*/
|
||||
default String getTenantPrefix() {
|
||||
|
||||
// 缓存是否按租户维度切分
|
||||
Boolean divideByTenantFlag = divideByTenant();
|
||||
|
||||
// 如果不按租户维度切分,则默认都返回为master
|
||||
if (!divideByTenantFlag) {
|
||||
return TenantConstants.MASTER_DATASOURCE_NAME;
|
||||
}
|
||||
|
||||
// 用户的租户前缀
|
||||
String tenantPrefix = "";
|
||||
try {
|
||||
|
|
Loading…
Reference in New Issue