|
@@ -6,6 +6,8 @@ import com.koobietech.eas.common.utils.JwtManager;
|
|
|
import com.koobietech.eas.dao.adminLoginPojo.Permission;
|
|
|
import com.koobietech.eas.dao.adminLoginPojo.UserDetail;
|
|
|
import com.koobietech.eas.service.LoginRedisService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
import org.springframework.security.core.context.SecurityContext;
|
|
@@ -27,6 +29,8 @@ import javax.servlet.http.HttpServletResponse;
|
|
|
@Component
|
|
|
public class EasSecurityFilter extends OncePerRequestFilter {
|
|
|
|
|
|
+ private static final Logger logger = LoggerFactory.getLogger(EasSecurityFilter.class);
|
|
|
+
|
|
|
@Resource
|
|
|
private LoginRedisService loginRedisService;
|
|
|
|
|
@@ -45,16 +49,22 @@ public class EasSecurityFilter extends OncePerRequestFilter {
|
|
|
try {
|
|
|
//过滤器 允许 Token 不正确, 后面Security 会拦截处理
|
|
|
jwtUserDto = jwtManager.decodeJwt(token);
|
|
|
- } catch ( EasException e) {}
|
|
|
+ } catch ( EasException e) {
|
|
|
+ logger.debug(e.getMessage());
|
|
|
+ }
|
|
|
if ( Objects.nonNull(jwtUserDto) ) {
|
|
|
//判断token是否有效
|
|
|
- UserDetail userDetail = loginRedisService.checkToken(jwtUserDto);
|
|
|
-
|
|
|
- // 获取当前的 SecurityContext 对象,用于保存当前用户的安全上下文信息
|
|
|
- SecurityContext context = SecurityContextHolder.getContext();
|
|
|
+ UserDetail userDetail = null;
|
|
|
+ try {
|
|
|
+ userDetail = loginRedisService.checkToken(jwtUserDto);
|
|
|
+ } catch ( EasException e) {
|
|
|
+ logger.debug(e.getMessage());
|
|
|
+ }
|
|
|
|
|
|
+ // 如果获取到了有效的用户对象
|
|
|
if (Objects.nonNull(userDetail)) {
|
|
|
- // 如果获取到了有效的用户对象
|
|
|
+ // 获取当前的 SecurityContext 对象,用于保存当前用户的安全上下文信息
|
|
|
+ SecurityContext context = SecurityContextHolder.getContext();
|
|
|
|
|
|
// 获取用户的权限列表
|
|
|
List<Permission> permission = userDetail.getPermissions();
|