|
|
@@ -1,20 +1,26 @@
|
|
|
package cn.reghao.dfs.store.inerceptor;
|
|
|
|
|
|
import cn.reghao.dfs.store.util.UserContext;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
+import cn.reghao.jutil.web.ServletUtil;
|
|
|
+import cn.reghao.tnb.account.api.constant.TokenType;
|
|
|
+import cn.reghao.tnb.account.api.dto.AccountInfo;
|
|
|
+import cn.reghao.tnb.account.api.iface.AuthService;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.servlet.*;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
import java.io.IOException;
|
|
|
|
|
|
/**
|
|
|
* @author reghao
|
|
|
- * @date 2022-08-25 21:14:23
|
|
|
+ * @date 2023-08-25 16:14:23
|
|
|
*/
|
|
|
-@Slf4j
|
|
|
@Component
|
|
|
public class TokenFilter implements Filter {
|
|
|
+ @DubboReference(check = false)
|
|
|
+ private AuthService authService;
|
|
|
+ private final String cookieKey = "USERDATA";
|
|
|
+
|
|
|
@Override
|
|
|
public void init(FilterConfig filterConfig) throws ServletException {
|
|
|
}
|
|
|
@@ -23,15 +29,24 @@ public class TokenFilter implements Filter {
|
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
|
|
throws IOException, ServletException {
|
|
|
long userId = -1L;
|
|
|
- /*HttpServletRequest httpServletRequest = (HttpServletRequest) request;
|
|
|
- String auth = httpServletRequest.getHeader("Authorization");
|
|
|
- if (auth != null) {
|
|
|
+ String sessId = ServletUtil.getCookie(cookieKey);
|
|
|
+ AccountInfo accountInfo = null;
|
|
|
+ if (sessId != null) {
|
|
|
+ accountInfo = authService.getAccountInfo(TokenType.cookie.getValue(), sessId);
|
|
|
+ } else {
|
|
|
+ sessId = ServletUtil.getBearerToken();
|
|
|
+ if (sessId != null) {
|
|
|
+ accountInfo = authService.getAccountInfo(TokenType.token.getValue(), sessId);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- try (UserContext context = new UserContext(userId)) {
|
|
|
- }*/
|
|
|
+ if (accountInfo != null) {
|
|
|
+ userId = accountInfo.getUserId();
|
|
|
+ }
|
|
|
|
|
|
- chain.doFilter(request, response);
|
|
|
+ try (UserContext context = new UserContext(userId)) {
|
|
|
+ chain.doFilter(request, response);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|