parent
9aec66d1a7
commit
acf448e980
@ -1,4 +1,4 @@
|
|||||||
package cn.teammodel.manager;
|
package cn.teammodel.manager.notification;
|
||||||
|
|
||||||
import com.dingtalk.api.DefaultDingTalkClient;
|
import com.dingtalk.api.DefaultDingTalkClient;
|
||||||
import com.dingtalk.api.DingTalkClient;
|
import com.dingtalk.api.DingTalkClient;
|
@ -1,4 +1,4 @@
|
|||||||
package cn.teammodel.manager;
|
package cn.teammodel.manager.notification;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 消息通知接口
|
* 消息通知接口
|
@ -0,0 +1,12 @@
|
|||||||
|
package cn.teammodel.manager.wx;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author winter
|
||||||
|
* @create 2024-03-26 11:08
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class MiniProgramSevice {
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
package cn.teammodel.security.filter;
|
||||||
|
|
||||||
|
import cn.teammodel.security.utils.JwtTokenUtil;
|
||||||
|
import io.jsonwebtoken.Claims;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
||||||
|
import org.springframework.security.core.context.SecurityContext;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.filter.OncePerRequestFilter;
|
||||||
|
|
||||||
|
import javax.annotation.Resource;
|
||||||
|
import javax.servlet.FilterChain;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 对外的 AI chat 接口的认证过滤器
|
||||||
|
* @author winter
|
||||||
|
* @create 2023-11-09 10:43
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ApiAuthTokenFilter extends OncePerRequestFilter {
|
||||||
|
|
||||||
|
@Resource
|
||||||
|
private JwtTokenUtil jwtTokenUtil;
|
||||||
|
|
||||||
|
// todo: 修改 context 的值 + 写一下多过滤器链的复盘
|
||||||
|
@Override
|
||||||
|
protected void doFilterInternal(HttpServletRequest request, @NotNull HttpServletResponse response, @NotNull FilterChain filterChain) throws ServletException, IOException {
|
||||||
|
SecurityContext context = SecurityContextHolder.getContext();
|
||||||
|
// 验证 authToken 合法
|
||||||
|
String token = request.getHeader("token");
|
||||||
|
if (StringUtils.isBlank(token)) {
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Claims claims = jwtTokenUtil.validAndGetClaims(token, "fXO6ko/qyXeYrkecPeKdgXnuLXf9vMEtnBC9OB3s+aA=", 315360000);
|
||||||
|
if (claims == null) {
|
||||||
|
SecurityContextHolder.clearContext(); // 验证失败不应该在此处抛出异常,应该维护好 context 的值,以便整个过滤器链正常运行
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 组装 authToken 的 jwt 进 authentication
|
||||||
|
UsernamePasswordAuthenticationToken finalAuthentication = new UsernamePasswordAuthenticationToken(claims, null, null);
|
||||||
|
context.setAuthentication(finalAuthentication);
|
||||||
|
filterChain.doFilter(request, response);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue