|
@@ -1,10 +1,8 @@
|
|
|
package com.simuwang.shiro.core.jwt;
|
|
|
|
|
|
-import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
import com.simuwang.base.common.util.ServletUtils;
|
|
|
-import com.simuwang.base.config.DaqProperties;
|
|
|
import com.smppw.common.pojo.ResultVo;
|
|
|
import io.jsonwebtoken.Claims;
|
|
|
import io.jsonwebtoken.ExpiredJwtException;
|
|
@@ -17,10 +15,8 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
-import org.springframework.util.AntPathMatcher;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
-import java.util.List;
|
|
|
|
|
|
/**
|
|
|
* @author wangzaijun
|
|
@@ -29,14 +25,11 @@ import java.util.List;
|
|
|
*/
|
|
|
@Component
|
|
|
public class JwtFilter extends AccessControlFilter {
|
|
|
- private static final AntPathMatcher PATH_MATCHER = new AntPathMatcher();
|
|
|
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
- private final DaqProperties properties;
|
|
|
private final JwtContext jwtContext;
|
|
|
|
|
|
- public JwtFilter(DaqProperties properties, JwtContext jwtContext) {
|
|
|
- this.properties = properties;
|
|
|
+ public JwtFilter(JwtContext jwtContext) {
|
|
|
this.jwtContext = jwtContext;
|
|
|
}
|
|
|
|
|
@@ -59,17 +52,6 @@ public class JwtFilter extends AccessControlFilter {
|
|
|
// 跟前端约定将jwtToken放在请求的Header的Authorization中,Authorization: token
|
|
|
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
|
|
String requestURI = request.getRequestURI();
|
|
|
- List<String> whitelist = this.properties.getWhitelist();
|
|
|
- if (CollUtil.isNotEmpty(whitelist)) {
|
|
|
- for (String path : whitelist) {
|
|
|
- if (PATH_MATCHER.match(path, requestURI)) {
|
|
|
- if (logger.isDebugEnabled()) {
|
|
|
- logger.debug("接口{} 配置了白名单,不需要签名验证!", requestURI);
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
String token = request.getHeader(JwtContext.HEADER);
|
|
|
if (StrUtil.isBlank(token)) {
|
|
|
this.onLoginFail(servletResponse, requestURI, "请先登录后操作");
|