

250324 김혜민 jwt관련 리팩토링
@bbc6a5b974c7accd97c083712c0af477577220ac
--- src/main/java/com/takensoft/cms/mber/service/Impl/RefreshTokenServiceImpl.java
+++ src/main/java/com/takensoft/cms/mber/service/Impl/RefreshTokenServiceImpl.java
... | ... | @@ -80,12 +80,12 @@ |
80 | 80 |
return result; |
81 | 81 |
} |
82 | 82 |
try { |
83 |
- jwtUtil.isExpired(refreshToken); |
|
83 |
+ jwtUtil.getClaim(refreshToken, "isExpired"); |
|
84 | 84 |
} catch (ExpiredJwtException e) { |
85 | 85 |
result.put("result", 0); |
86 | 86 |
return result; |
87 | 87 |
} |
88 |
- String category = jwtUtil.getCategory(refreshToken); |
|
88 |
+ String category = (String) jwtUtil.getClaim(refreshToken, "category"); |
|
89 | 89 |
if(!category.equals("refresh")) { |
90 | 90 |
result.put("result", 0); |
91 | 91 |
return result; |
... | ... | @@ -145,7 +145,7 @@ |
145 | 145 |
//res.addCookie(jwtUtil.createCookie("refresh",null, 0)); |
146 | 146 |
|
147 | 147 |
RefreshVO refreshVO = new RefreshVO(); |
148 |
- refreshVO.setMbrId(jwtUtil.getMbrId(refreshTokenCheck(req).get("refreshToken").toString())); |
|
148 |
+ refreshVO.setMbrId((String) jwtUtil.getClaim(refreshTokenCheck(req).get("refreshToken").toString(), "mbrId")); |
|
149 | 149 |
|
150 | 150 |
//중복로그인 비허용시 삭제 |
151 | 151 |
if (!redisConfig.isAllowMultipleLogin()) { |
... | ... | @@ -177,7 +177,7 @@ |
177 | 177 |
|
178 | 178 |
String refreshToken = refreshTokenCheck(req).get("refreshToken").toString(); |
179 | 179 |
|
180 |
- String userId = jwtUtil.getMbrId(refreshToken); |
|
180 |
+ String userId = (String) jwtUtil.getClaim(refreshToken, "mbrId"); |
|
181 | 181 |
|
182 | 182 |
// 중복 로그인 비허용 체크 (DB에 저장된 리프레시 토큰과 비교) |
183 | 183 |
if (!redisConfig.isAllowMultipleLogin()) { |
... | ... | @@ -189,16 +189,16 @@ |
189 | 189 |
} |
190 | 190 |
} |
191 | 191 |
|
192 |
- Date expired = jwtUtil.getExpired(refreshToken); |
|
192 |
+ Date expired = (Date) jwtUtil.getClaim(refreshToken, "Expired"); |
|
193 | 193 |
|
194 | 194 |
// 만료시간과 현재 시간의 차이 계산 |
195 | 195 |
long timeDffrnc = (expired.getTime() - new Date().getTime()) / (1000 * 60 * 60); |
196 | 196 |
|
197 | 197 |
MberVO mber = new MberVO(); |
198 |
- List<MberAuthorVO> roles = jwtUtil.getRoles(refreshToken); |
|
199 |
- mber.setLgnId(jwtUtil.getLgnId(refreshToken)); |
|
200 |
- mber.setMbrId(jwtUtil.getMbrId(refreshToken)); |
|
201 |
- mber.setMbrNm(jwtUtil.getMbrNm(refreshToken)); |
|
198 |
+ List<MberAuthorVO> roles = (List<MberAuthorVO>) jwtUtil.getClaim(refreshToken, "roles"); |
|
199 |
+ mber.setLgnId((String) jwtUtil.getClaim(refreshToken, "lgnId")); |
|
200 |
+ mber.setMbrId((String) jwtUtil.getClaim(refreshToken, "mbrId")); |
|
201 |
+ mber.setMbrNm((String) jwtUtil.getClaim(refreshToken, "mbrNm")); |
|
202 | 202 |
mber.setAuthorList(roles); |
203 | 203 |
// 신규 AccessToken 발행 |
204 | 204 |
String newAccessToken = jwtUtil.createJwt("Authorization", mber.getMbrId(), mber.getLgnId(), mber.getMbrNm(), (List) mber.getAuthorities(), JWT_ACCESSTIME); |
--- src/main/java/com/takensoft/common/HierachyVO.java
+++ src/main/java/com/takensoft/common/HierachyVO.java
... | ... | @@ -7,37 +7,26 @@ |
7 | 7 |
|
8 | 8 |
import java.util.ArrayList; |
9 | 9 |
import java.util.List; |
10 |
- |
|
10 |
+/** |
|
11 |
+ * @author takensoft |
|
12 |
+ * @since 2025.01.22 |
|
13 |
+ * @modification |
|
14 |
+ * since | author | description |
|
15 |
+ * 2025.01.22 | takensoft | 최초 등록 |
|
16 |
+ * |
|
17 |
+ * 최상위 코드 VO |
|
18 |
+ */ |
|
11 | 19 |
@Setter |
12 | 20 |
@Getter |
13 | 21 |
@NoArgsConstructor |
14 | 22 |
@AllArgsConstructor |
15 | 23 |
public class HierachyVO { |
16 | 24 |
|
17 |
- /** |
|
18 |
- * 공통으로 사용될 아이디 |
|
19 |
- */ |
|
20 |
- private String id; |
|
21 |
- /** |
|
22 |
- * 공통으로 사용될 상위 아이디 |
|
23 |
- */ |
|
24 |
- private String upId; |
|
25 |
- /** |
|
26 |
- * 공통으로 사용될 이름 |
|
27 |
- */ |
|
28 |
- private String nm; |
|
29 |
- /** |
|
30 |
- * 공통으로 사용될 깊이(레벨) |
|
31 |
- */ |
|
32 |
- private int grd; |
|
33 |
- /** |
|
34 |
- * 공통으로 사용될 순서 |
|
35 |
- */ |
|
36 |
- private int sn; |
|
37 |
- |
|
38 |
- /** |
|
39 |
- * 공통으로 사용될 자식 객체 |
|
40 |
- */ |
|
41 |
- List<HierachyVO> childList = new ArrayList<HierachyVO>(); |
|
25 |
+ private String id; // 공통으로 사용될 아이디 |
|
26 |
+ private String upId; // 공통으로 사용될 상위 아이디 |
|
27 |
+ private String nm; // 공통으로 사용될 이름 |
|
28 |
+ private int grd; // 공통으로 사용될 깊이(레벨) |
|
29 |
+ private int sn; // 공통으로 사용될 순서 |
|
30 |
+ List<HierachyVO> childList = new ArrayList<HierachyVO>(); // 공통으로 사용될 자식 객체 |
|
42 | 31 |
|
43 | 32 |
} |
--- src/main/java/com/takensoft/common/Pagination.java
+++ src/main/java/com/takensoft/common/Pagination.java
... | ... | @@ -5,7 +5,15 @@ |
5 | 5 |
|
6 | 6 |
import java.util.HashMap; |
7 | 7 |
import java.util.Map; |
8 |
- |
|
8 |
+/** |
|
9 |
+ * @author takensoft |
|
10 |
+ * @since 2025.01.22 |
|
11 |
+ * @modification |
|
12 |
+ * since | author | description |
|
13 |
+ * 2025.01.22 | takensoft | 최초 등록 |
|
14 |
+ * |
|
15 |
+ * 페이징 |
|
16 |
+ */ |
|
9 | 17 |
@Getter |
10 | 18 |
@Setter |
11 | 19 |
public class Pagination { |
--- src/main/java/com/takensoft/common/config/CommonConfig.java
+++ src/main/java/com/takensoft/common/config/AppConfig.java
... | ... | @@ -22,7 +22,7 @@ |
22 | 22 |
* 기본 설정을 위한 Config |
23 | 23 |
*/ |
24 | 24 |
@Configuration |
25 |
-public class CommonConfig { |
|
25 |
+public class AppConfig { |
|
26 | 26 |
|
27 | 27 |
/** |
28 | 28 |
* @return MappingJackson2JsonView - JSON 응답을 위한 뷰 객체 |
--- src/main/java/com/takensoft/common/config/SecurityConfig.java
+++ src/main/java/com/takensoft/common/config/SecurityConfig.java
... | ... | @@ -50,7 +50,7 @@ |
50 | 50 |
private final CustomAuthenticationEntryPoint authenticationEntryPoint; |
51 | 51 |
private final CustomAccessDenieHandler accessDenieHandler; |
52 | 52 |
private final HttpRequestUtil httpRequestUtil; |
53 |
- private final CommonConfig commonConfig; |
|
53 |
+ private final AppConfig appConfig; |
|
54 | 54 |
private final RedisConfig redisConfig; |
55 | 55 |
|
56 | 56 |
private static String FRONT_URL; // 프론트 접근 허용 URL |
... | ... | @@ -73,7 +73,7 @@ |
73 | 73 |
* |
74 | 74 |
* SecurityConfig 생성자 |
75 | 75 |
*/ |
76 |
- public SecurityConfig(AuthenticationConfiguration authenticationConfiguration, JWTUtil jwtUtil, RefreshTokenService refreshTokenService, AccesCtrlService accesCtrlService, CommonConfig commonConfig, RedisConfig redisConfig, |
|
76 |
+ public SecurityConfig(AuthenticationConfiguration authenticationConfiguration, JWTUtil jwtUtil, RefreshTokenService refreshTokenService, AccesCtrlService accesCtrlService, AppConfig appConfig, RedisConfig redisConfig, |
|
77 | 77 |
LgnHstryService lgnHstryService, CustomAuthenticationEntryPoint authenticationEntryPoint, CustomAccessDenieHandler accessDenieHandler, HttpRequestUtil httpRequestUtil, |
78 | 78 |
@Value("${front.url}")String fUrl, @Value("${jwt.accessTime}")long aTime, @Value("${jwt.refreshTime}")long rTime, @Value("${cookie.time}")int ctime, RedisTemplate<String, String> redisTemplate) { |
79 | 79 |
|
... | ... | @@ -85,7 +85,7 @@ |
85 | 85 |
this.accessDenieHandler = accessDenieHandler; |
86 | 86 |
this.jwtUtil = jwtUtil; |
87 | 87 |
this.httpRequestUtil = httpRequestUtil; |
88 |
- this.commonConfig = commonConfig; |
|
88 |
+ this.appConfig = appConfig; |
|
89 | 89 |
this.redisConfig = redisConfig; |
90 | 90 |
|
91 | 91 |
this.FRONT_URL = fUrl; |
... | ... | @@ -170,10 +170,10 @@ |
170 | 170 |
http.addFilterBefore(new JWTFilter(jwtUtil, commonConfig, redisConfig, redisTemplate), LoginFilter.class); // JWT 인증 필터 추가 |
171 | 171 |
}*/ |
172 | 172 |
|
173 |
- http.addFilterBefore(new JWTFilter(jwtUtil, commonConfig, redisConfig, redisTemplate), LoginFilter.class); // 토큰 검증 필터 |
|
174 |
- http.addFilterBefore(new AccesFilter(accesCtrlService, httpRequestUtil, commonConfig), JWTFilter.class); // 아이피 검증 |
|
173 |
+ http.addFilterBefore(new JWTFilter(jwtUtil, appConfig, redisConfig, redisTemplate), LoginFilter.class); // 토큰 검증 필터 |
|
174 |
+ http.addFilterBefore(new AccesFilter(accesCtrlService, httpRequestUtil, appConfig), JWTFilter.class); // 아이피 검증 |
|
175 | 175 |
http.addFilterAt(new LoginFilter(authenticationManager(authenticationConfiguration), jwtUtil, refreshTokenService, lgnHstryService, httpRequestUtil, |
176 |
- commonConfig,redisConfig, JWT_ACCESSTIME, JWT_REFRESHTIME, COOKIE_TIME, redisTemplate), UsernamePasswordAuthenticationFilter.class); // 로그인 필터 |
|
176 |
+ appConfig,redisConfig, JWT_ACCESSTIME, JWT_REFRESHTIME, COOKIE_TIME, redisTemplate), UsernamePasswordAuthenticationFilter.class); // 로그인 필터 |
|
177 | 177 |
|
178 | 178 |
return http.build(); |
179 | 179 |
} |
--- src/main/java/com/takensoft/common/config/WebConfig.java
+++ src/main/java/com/takensoft/common/config/WebConfig.java
... | ... | @@ -17,6 +17,7 @@ |
17 | 17 |
*/ |
18 | 18 |
@Configuration |
19 | 19 |
public class WebConfig { |
20 |
+ |
|
20 | 21 |
/** |
21 | 22 |
* @return ForwardedHeaderFilter |
22 | 23 |
* |
--- src/main/java/com/takensoft/common/filter/AccesFilter.java
+++ src/main/java/com/takensoft/common/filter/AccesFilter.java
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 |
|
3 | 3 |
import com.takensoft.cms.accesCtrl.service.AccesCtrlService; |
4 | 4 |
import com.takensoft.cms.accesCtrl.vo.AccesCtrlVO; |
5 |
-import com.takensoft.common.config.CommonConfig; |
|
5 |
+import com.takensoft.common.config.AppConfig; |
|
6 | 6 |
import com.takensoft.common.util.HttpRequestUtil; |
7 | 7 |
import com.takensoft.common.util.ErrorResponse; |
8 | 8 |
import org.springframework.http.HttpStatus; |
... | ... | @@ -17,10 +17,14 @@ |
17 | 17 |
import java.io.IOException; |
18 | 18 |
import java.time.LocalDateTime; |
19 | 19 |
import java.util.List; |
20 |
- |
|
21 | 20 |
/** |
22 | 21 |
* @author takensoft |
23 | 22 |
* @since 2024.04.15 |
23 |
+ * @modification |
|
24 |
+ * since | author | description |
|
25 |
+ * 2024.04.15 | takensoft | 최초 등록 |
|
26 |
+ * |
|
27 |
+ * OncePerRequestFilter - 한 번의 요청마다 단 한 번만 필터링 작업을 수행하는 필터를 제공하는 클래스 |
|
24 | 28 |
* |
25 | 29 |
* Access(아이피) 검증 필터 |
26 | 30 |
*/ |
... | ... | @@ -28,14 +32,29 @@ |
28 | 32 |
|
29 | 33 |
private final AccesCtrlService accesCtrlService; |
30 | 34 |
private final HttpRequestUtil httpRequestUtil; |
31 |
- private final CommonConfig commonConfig; |
|
35 |
+ private final AppConfig appConfig; |
|
32 | 36 |
|
33 |
- public AccesFilter(AccesCtrlService accesCtrlService, HttpRequestUtil httpRequestUtil, CommonConfig commonConfig) { |
|
37 |
+ /** |
|
38 |
+ * @param accesCtrlService 접근 제어 관련 인터페이스의 인스턴스 |
|
39 |
+ * @param httpRequestUtil HTTP 요청 관련 유틸리티 클래스의 인스턴스 |
|
40 |
+ * @param appConfig 기본 설정을 위한 Config |
|
41 |
+ * |
|
42 |
+ * AccesFilter 생성자 |
|
43 |
+ */ |
|
44 |
+ public AccesFilter(AccesCtrlService accesCtrlService, HttpRequestUtil httpRequestUtil, AppConfig appConfig) { |
|
34 | 45 |
this.accesCtrlService = accesCtrlService; |
35 | 46 |
this.httpRequestUtil = httpRequestUtil; |
36 |
- this.commonConfig = commonConfig; |
|
47 |
+ this.appConfig = appConfig; |
|
37 | 48 |
} |
38 |
- |
|
49 |
+ /** |
|
50 |
+ * @param request HttpServletRequest 객체 |
|
51 |
+ * @param response HttpServletResponse 객체 |
|
52 |
+ * @param filterChain 필터 체인을 통해 다음 필터로 요청을 전달 |
|
53 |
+ * @throws ServletException 필터 처리 중 발생한 서블릿 예외 |
|
54 |
+ * @throws IOException 필터 처리 중 발생한 IO 예외 |
|
55 |
+ * |
|
56 |
+ * Access(아이피) 검증 |
|
57 |
+ */ |
|
39 | 58 |
@Override |
40 | 59 |
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { |
41 | 60 |
try { |
... | ... | @@ -60,7 +79,7 @@ |
60 | 79 |
// 응답 헤더 설정 및 json 응답 전송 |
61 | 80 |
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
62 | 81 |
response.setStatus(HttpStatus.FORBIDDEN.value()); |
63 |
- response.getOutputStream().write(commonConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
82 |
+ response.getOutputStream().write(appConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
64 | 83 |
} catch (Exception e) { |
65 | 84 |
// 시스템 에러 발생 |
66 | 85 |
e.printStackTrace(); |
... | ... | @@ -74,11 +93,16 @@ |
74 | 93 |
// 응답 헤더 설정 및 json 응답 전송 |
75 | 94 |
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
76 | 95 |
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value()); |
77 |
- response.getOutputStream().write(commonConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
96 |
+ response.getOutputStream().write(appConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
78 | 97 |
} |
79 | 98 |
} |
80 | 99 |
|
81 |
- // 요청 URI에 따른 접근 제어 확인 |
|
100 |
+ /** |
|
101 |
+ * @param accesCtrlList 접근 제어 정보 리스트 |
|
102 |
+ * @param req HttpServletRequest 객체 |
|
103 |
+ * @return boolean 요청 URI에 따른 접근 제어 여부 |
|
104 |
+ * 요청 URI에 따른 접근 제어 확인 |
|
105 |
+ */ |
|
82 | 106 |
private boolean isAccesCntrl(List<AccesCtrlVO> accesCtrlList, HttpServletRequest req) { |
83 | 107 |
for(AccesCtrlVO vo : accesCtrlList) { |
84 | 108 |
AntPathRequestMatcher matcher = new AntPathRequestMatcher(vo.getCntrlCrs()); |
--- src/main/java/com/takensoft/common/filter/JWTFilter.java
+++ src/main/java/com/takensoft/common/filter/JWTFilter.java
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 |
|
3 | 3 |
import com.takensoft.cms.mber.vo.MberAuthorVO; |
4 | 4 |
import com.takensoft.cms.mber.vo.MberVO; |
5 |
-import com.takensoft.common.config.CommonConfig; |
|
5 |
+import com.takensoft.common.config.AppConfig; |
|
6 | 6 |
import com.takensoft.common.config.RedisConfig; |
7 | 7 |
import com.takensoft.common.util.ErrorResponse; |
8 | 8 |
import com.takensoft.common.util.JWTUtil; |
... | ... | @@ -38,7 +38,7 @@ |
38 | 38 |
public class JWTFilter extends OncePerRequestFilter { |
39 | 39 |
|
40 | 40 |
private final JWTUtil jwtUtil; |
41 |
- private final CommonConfig commonConfig; |
|
41 |
+ private final AppConfig appConfig; |
|
42 | 42 |
private final RedisConfig redisConfig; |
43 | 43 |
private final RedisTemplate<String, String> redisTemplate; |
44 | 44 |
/** |
... | ... | @@ -46,9 +46,9 @@ |
46 | 46 |
* |
47 | 47 |
* JWTFilter 생성자 |
48 | 48 |
*/ |
49 |
- public JWTFilter(JWTUtil jwtUtil, CommonConfig commonConfig, RedisConfig redisConfig, RedisTemplate<String, String> redisTemplate) { |
|
49 |
+ public JWTFilter(JWTUtil jwtUtil, AppConfig appConfig, RedisConfig redisConfig, RedisTemplate<String, String> redisTemplate) { |
|
50 | 50 |
this.jwtUtil = jwtUtil; |
51 |
- this.commonConfig = commonConfig; |
|
51 |
+ this.appConfig = appConfig; |
|
52 | 52 |
this.redisConfig = redisConfig; |
53 | 53 |
this.redisTemplate = redisTemplate; |
54 | 54 |
} |
... | ... | @@ -73,7 +73,7 @@ |
73 | 73 |
} |
74 | 74 |
|
75 | 75 |
// 토큰 만료 여부 검증 |
76 |
- if(jwtUtil.isExpired(accessToken)) { |
|
76 |
+ if( (Boolean) jwtUtil.getClaim(accessToken, "isExpired")) { |
|
77 | 77 |
throw new JwtException("Token expired"); |
78 | 78 |
} |
79 | 79 |
// 토큰에서 페이로드 확인[ 발급시 명시 ] |
... | ... | @@ -87,7 +87,7 @@ |
87 | 87 |
); |
88 | 88 |
|
89 | 89 |
// 중복 로그인 비허용 설정이면 Redis에서 최신 JWT 가져와 비교 |
90 |
- String userId = jwtUtil.getMbrId(accessToken); |
|
90 |
+ String userId = (String) jwtUtil.getClaim(accessToken, "mbrId"); |
|
91 | 91 |
if (!redisConfig.isAllowMultipleLogin()) { |
92 | 92 |
String storedToken = redisTemplate.opsForValue().get("jwt:" + userId); |
93 | 93 |
if (storedToken == null) { |
... | ... | @@ -107,7 +107,7 @@ |
107 | 107 |
// 응답 헤더 설정 및 json 응답 전송 |
108 | 108 |
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
109 | 109 |
response.setStatus(HttpStatus.UNAUTHORIZED.value()); |
110 |
- response.getOutputStream().write(commonConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
110 |
+ response.getOutputStream().write(appConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
111 | 111 |
return; |
112 | 112 |
} |
113 | 113 |
} |
... | ... | @@ -133,7 +133,7 @@ |
133 | 133 |
// 응답 헤더 설정 및 json 응답 전송 |
134 | 134 |
response.setContentType(MediaType.APPLICATION_JSON_VALUE); |
135 | 135 |
response.setStatus(HttpStatus.UNAUTHORIZED.value()); |
136 |
- response.getOutputStream().write(commonConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
136 |
+ response.getOutputStream().write(appConfig.getObjectMapper().writeValueAsBytes(errorResponse)); |
|
137 | 137 |
} |
138 | 138 |
} |
139 | 139 |
}(파일 끝에 줄바꿈 문자 없음) |
--- src/main/java/com/takensoft/common/filter/LoginFilter.java
+++ src/main/java/com/takensoft/common/filter/LoginFilter.java
... | ... | @@ -7,7 +7,7 @@ |
7 | 7 |
import com.takensoft.cms.mber.vo.LgnHstryVO; |
8 | 8 |
import com.takensoft.cms.mber.vo.MberVO; |
9 | 9 |
import com.takensoft.cms.mber.vo.RefreshVO; |
10 |
-import com.takensoft.common.config.CommonConfig; |
|
10 |
+import com.takensoft.common.config.AppConfig; |
|
11 | 11 |
import com.takensoft.common.config.RedisConfig; |
12 | 12 |
import com.takensoft.common.exception.FilterExceptionHandler; |
13 | 13 |
import com.takensoft.common.util.HttpRequestUtil; |
... | ... | @@ -49,7 +49,7 @@ |
49 | 49 |
private final RefreshTokenService refreshTokenService; |
50 | 50 |
private final LgnHstryService lgnHstryService; |
51 | 51 |
private final HttpRequestUtil httpRequestUtil; |
52 |
- private final CommonConfig commonConfig; |
|
52 |
+ private final AppConfig appConfig; |
|
53 | 53 |
private final RedisConfig redisConfig; |
54 | 54 |
|
55 | 55 |
private static long JWT_ACCESSTIME; // access 토큰 유지 시간 |
... | ... | @@ -67,13 +67,13 @@ |
67 | 67 |
* LoginFilter 생성자 |
68 | 68 |
*/ |
69 | 69 |
public LoginFilter(AuthenticationManager authenticationManager, JWTUtil jwtUtil, RefreshTokenService refreshTokenService, LgnHstryService lgnHstryService, HttpRequestUtil httpRequestUtil, |
70 |
- CommonConfig commonConfig, RedisConfig redisConfig, @Value("${jwt.accessTime}")long aTime, @Value("${jwt.refreshTime}")long rTime, @Value("${cookie.time}")int ctime, RedisTemplate<String, String> redisTemplate) { |
|
70 |
+ AppConfig appConfig, RedisConfig redisConfig, @Value("${jwt.accessTime}")long aTime, @Value("${jwt.refreshTime}")long rTime, @Value("${cookie.time}")int ctime, RedisTemplate<String, String> redisTemplate) { |
|
71 | 71 |
this.authenticationManager = authenticationManager; |
72 | 72 |
this.jwtUtil = jwtUtil; |
73 | 73 |
this.refreshTokenService = refreshTokenService; |
74 | 74 |
this.lgnHstryService = lgnHstryService; |
75 | 75 |
this.httpRequestUtil = httpRequestUtil; |
76 |
- this.commonConfig = commonConfig; |
|
76 |
+ this.appConfig = appConfig; |
|
77 | 77 |
this.redisConfig = redisConfig; |
78 | 78 |
|
79 | 79 |
this.JWT_ACCESSTIME = aTime; |
--- src/main/java/com/takensoft/common/filter/SessionAuthFilter.java
+++ src/main/java/com/takensoft/common/filter/SessionAuthFilter.java
... | ... | @@ -24,13 +24,26 @@ |
24 | 24 |
|
25 | 25 |
private final JWTUtil jwtUtil; |
26 | 26 |
|
27 |
+ /** |
|
28 |
+ * @param jwtUtil JWT 유틸리티 클래스의 인스턴스 |
|
29 |
+ * |
|
30 |
+ * 세션 Filter 생성자 |
|
31 |
+ */ |
|
27 | 32 |
public SessionAuthFilter(JWTUtil jwtUtil) { |
28 | 33 |
this.jwtUtil = jwtUtil; |
29 | 34 |
} |
30 | 35 |
|
36 |
+ /** |
|
37 |
+ * @param request HttpServletRequest 객체 |
|
38 |
+ * @param response HttpServletResponse 객체 |
|
39 |
+ * @param filterChain 필터 체인을 통해 다음 필터로 요청을 전달 |
|
40 |
+ * @throws ServletException 필터 처리 중 발생한 서블릿 예외 |
|
41 |
+ * @throws IOException 필터 처리 중 발생한 IO 예외 |
|
42 |
+ * |
|
43 |
+ * 세션 Filter 검증 |
|
44 |
+ */ |
|
31 | 45 |
@Override |
32 |
- protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) |
|
33 |
- throws ServletException, IOException { |
|
46 |
+ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { |
|
34 | 47 |
/* |
35 | 48 |
// 현재 로그인 방식 확인 |
36 | 49 |
if (!"SESSION".equals(authConfig.getLoginType())) { |
--- src/main/java/com/takensoft/common/util/HttpRequestUtil.java
+++ src/main/java/com/takensoft/common/util/HttpRequestUtil.java
... | ... | @@ -19,6 +19,13 @@ |
19 | 19 |
public class HttpRequestUtil { |
20 | 20 |
|
21 | 21 |
/** |
22 |
+ * 기본 생성자 |
|
23 |
+ */ |
|
24 |
+ private HttpRequestUtil() { |
|
25 |
+ |
|
26 |
+ } |
|
27 |
+ |
|
28 |
+ /** |
|
22 | 29 |
* @param req - HTTP 요청 객체 |
23 | 30 |
* @return 클라이언트 IP 주소 (String) |
24 | 31 |
* @throws UnknownHostException - 로컬 IP 주소를 확인할 수 없는 경우 |
--- src/main/java/com/takensoft/common/util/JWTUtil.java
+++ src/main/java/com/takensoft/common/util/JWTUtil.java
... | ... | @@ -80,52 +80,6 @@ |
80 | 80 |
cookie.setHttpOnly(true); // front에서 script로 접근 방지 |
81 | 81 |
return cookie; |
82 | 82 |
} |
83 |
- |
|
84 |
- public String getCategory(String token) { |
|
85 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().get("category", String.class); |
|
86 |
- } |
|
87 |
- |
|
88 |
- // 접속자 토큰 기반 회원 아이디 추출 |
|
89 |
- public String getMbrId(String token) { |
|
90 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().get("mbrId", String.class); |
|
91 |
- } |
|
92 |
- |
|
93 |
- // 접속자 토큰 기반 로그인 아이디 추출 |
|
94 |
- public String getLgnId(String token) { |
|
95 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().get("lgnId", String.class); |
|
96 |
- } |
|
97 |
- |
|
98 |
- // 접속자 토큰 기반 회원명 추출 |
|
99 |
- public String getMbrNm(String token) { |
|
100 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().get("mbrNm", String.class); |
|
101 |
- } |
|
102 |
- |
|
103 |
- // 접속자 토큰 기반 권한정보 추출 |
|
104 |
- public List<MberAuthorVO> getRoles(String token) { |
|
105 |
- // 토큰에서 권한 정보를 가져옴 |
|
106 |
- Claims claims = Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload(); |
|
107 |
- List<HashMap> roles = claims.get("roles", List.class); |
|
108 |
- List<MberAuthorVO> authorList = new ArrayList<MberAuthorVO>(); |
|
109 |
- if (roles != null && !roles.isEmpty()) { |
|
110 |
- for(Map role : roles) { |
|
111 |
- MberAuthorVO mberAuthor = new MberAuthorVO(); |
|
112 |
- mberAuthor.setAuthrtCd(role.get("authority").toString()); |
|
113 |
- authorList.add(mberAuthor); |
|
114 |
- } |
|
115 |
- } |
|
116 |
- return authorList; |
|
117 |
- } |
|
118 |
- |
|
119 |
- // 토큰 소멸 여부 |
|
120 |
- public Boolean isExpired(String token) { |
|
121 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().getExpiration().before(new Date()); |
|
122 |
- } |
|
123 |
- |
|
124 |
- // 토큰 만료 시간 |
|
125 |
- public Date getExpired(String token) { |
|
126 |
- return Jwts.parser().verifyWith(JWT_SECRET_KEY).build().parseSignedClaims(token).getPayload().getExpiration(); |
|
127 |
- } |
|
128 |
- |
|
129 | 83 |
// 로그인 사용자 아이디 조회 |
130 | 84 |
public String getWriter() { |
131 | 85 |
String mbrId = null; |
... | ... | @@ -136,9 +90,6 @@ |
136 | 90 |
} |
137 | 91 |
return mbrId; |
138 | 92 |
} |
139 |
- |
|
140 |
- |
|
141 |
- |
|
142 | 93 |
|
143 | 94 |
/** |
144 | 95 |
* @param tkn JWT 토큰 문자열 |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?