|
|
|
@ -4,12 +4,16 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
//import com.icomsys.main_vm.db.jpa.repo.bot.TbBotAuthMenuRepo;
|
|
|
|
|
//import com.icomsys.main_vm.db.jpa.repo.bot.TbBotMenuRepo;
|
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
|
import com.icomsys.main_vm.biz.common.login.TokenProvider;
|
|
|
|
|
import com.icomsys.main_vm.common.code.enumresource.SessionResource;
|
|
|
|
|
import com.icomsys.main_vm.db.mybatis.alias.LoginVO;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
import org.springframework.web.filter.OncePerRequestFilter;
|
|
|
|
|
import org.springframework.web.util.ContentCachingRequestWrapper;
|
|
|
|
|
import org.springframework.web.util.ContentCachingResponseWrapper;
|
|
|
|
@ -27,6 +31,8 @@ import java.time.LocalDateTime;
|
|
|
|
|
public class LoginFilter extends OncePerRequestFilter {
|
|
|
|
|
|
|
|
|
|
private final ObjectMapper objectMapper;
|
|
|
|
|
|
|
|
|
|
private final TokenProvider tokenProvider;
|
|
|
|
|
// private final TbBotAuthMenuRepo tbBotAuthMenuRepo;
|
|
|
|
|
// private final TbBotMenuRepo tbBotMenuRepo;
|
|
|
|
|
// @Value("${Server.servlet.context-path}")
|
|
|
|
@ -43,21 +49,12 @@ public class LoginFilter extends OncePerRequestFilter {
|
|
|
|
|
// log.info("필터 요청유알엘 - {}, {}", reqUrl);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (reqUrl.startsWith("/re1")){
|
|
|
|
|
response.sendError(490);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reqUrl.startsWith("/re2")){
|
|
|
|
|
response.sendError(491);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (reqUrl.startsWith("/lib")
|
|
|
|
|
|| reqUrl.startsWith("/css")
|
|
|
|
|
|| reqUrl.startsWith("/images")
|
|
|
|
|
|| reqUrl.startsWith("/js")
|
|
|
|
|
|| reqUrl.startsWith("/adm")
|
|
|
|
|
|| reqUrl.startsWith("/adm/")
|
|
|
|
|
|| reqUrl.startsWith("/ws")
|
|
|
|
|
|| reqUrl.startsWith("/rest")
|
|
|
|
|
|| reqUrl.startsWith("/create")
|
|
|
|
@ -66,9 +63,28 @@ public class LoginFilter extends OncePerRequestFilter {
|
|
|
|
|
|| reqUrl.startsWith("/error")
|
|
|
|
|
|| reqUrl.startsWith("/files")
|
|
|
|
|
|| reqUrl.equals("/")
|
|
|
|
|
// || reqUrl.equals("/tokenLogin")
|
|
|
|
|
) {
|
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
// 1. Request Header 에서 JWT 토큰 추출
|
|
|
|
|
String token = resolveToken((HttpServletRequest) request);
|
|
|
|
|
|
|
|
|
|
// 2. validateToken 으로 토큰 유효성 검사
|
|
|
|
|
if (token != null && tokenProvider.validateToken(token)) {
|
|
|
|
|
|
|
|
|
|
// Todo: 토큰 유효성 검사 후 에러 처리
|
|
|
|
|
// 토큰이 유효할 경우 토큰에서 Authentication 객체를 가지고 와서 SecurityContext 에 저장
|
|
|
|
|
Authentication authentication = tokenProvider.getAuthentication(token);
|
|
|
|
|
SecurityContextHolder.getContext().setAuthentication(authentication);
|
|
|
|
|
|
|
|
|
|
response.sendError(403);
|
|
|
|
|
}
|
|
|
|
|
filterChain.doFilter(request, response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
if (request.getSession().getAttribute(SessionResource.UserVO.getName()) == null || request.getSession().getAttribute(SessionResource.UserVO.getName()).equals("")) {
|
|
|
|
|
log.info("session Check");
|
|
|
|
|
response.sendError(490);
|
|
|
|
@ -104,6 +120,17 @@ public class LoginFilter extends OncePerRequestFilter {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// response.copyBodyToResponse();
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Request Header 에서 토큰 정보 추출
|
|
|
|
|
private String resolveToken(HttpServletRequest request) {
|
|
|
|
|
String bearerToken = request.getHeader("Authorization");
|
|
|
|
|
if (StringUtils.hasText(bearerToken) && bearerToken.startsWith("Bearer")) {
|
|
|
|
|
return bearerToken.substring(7);
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|