mirror of https://gitee.com/topiam/eiam
修复会话管理强转失败问题
commit
252042f490
|
@ -25,6 +25,7 @@ import java.util.*;
|
|||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.RedisCallback;
|
||||
import org.springframework.data.redis.core.RedisOperations;
|
||||
|
@ -108,10 +109,23 @@ public class ClusterSessionRegistryImpl<T extends org.springframework.session.Se
|
|||
SecurityContext securityContext = session.getAttribute(SPRING_SECURITY_CONTEXT);
|
||||
//转为实体
|
||||
Authentication authentication = securityContext.getAuthentication();
|
||||
UserDetails principal = (UserDetails) authentication.getPrincipal();
|
||||
Object principal = authentication.getPrincipal();
|
||||
if (principal instanceof UserDetails userDetails) {
|
||||
Session sessionDetails = getSession(session, userDetails, authentication);
|
||||
list.add(sessionDetails);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
//处理
|
||||
return list;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Session getSession(MapSession session, UserDetails userDetails, Authentication authentication) {
|
||||
WebAuthenticationDetails details = (WebAuthenticationDetails) authentication
|
||||
.getDetails();
|
||||
Session sessionDetails = new Session(principal.getId(), principal.getUsername());
|
||||
Session sessionDetails = new Session(userDetails.getId(), userDetails.getUsername());
|
||||
//last request
|
||||
Instant instant = session.getLastAccessedTime();
|
||||
ZoneId zoneId = ZoneId.systemDefault();
|
||||
|
@ -124,19 +138,14 @@ public class ClusterSessionRegistryImpl<T extends org.springframework.session.Se
|
|||
sessionDetails
|
||||
.setAuthenticationProvider(details.getAuthenticationProvider().getType());
|
||||
//用户类型
|
||||
sessionDetails.setUserType(principal.getUserType());
|
||||
sessionDetails.setUserType(userDetails.getUserType());
|
||||
//地理位置
|
||||
sessionDetails.setGeoLocation(details.getGeoLocation());
|
||||
//用户代理
|
||||
sessionDetails.setUserAgent(details.getUserAgent());
|
||||
//会话ID
|
||||
sessionDetails.setSessionId(session.getId());
|
||||
list.add(sessionDetails);
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
}
|
||||
//处理
|
||||
return list;
|
||||
return sessionDetails;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue