Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Security AuthTokenFilter에서 에러 잡고 다음 필터로 넘기도록 설정 변경 #26

Merged
merged 2 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions src/main/java/com/hyundai/app/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) {
web.ignoring().antMatchers(
"/", "/resources/**",
"/v2/api-docs", "/swagger-resources/**", "/swagger-ui/index.html", "/swagger-ui.html","/webjars/**", "/swagger/**", // swagger
"/api/v1/auth/**", "/api/v1/admin/**", "/api/v1/fcm-push/random-spot/**", "/api/v1/heendy-guide/**", "/websocket/**");
"/", "/resources/**"
, "/v2/api-docs", "/swagger-resources/**", "/swagger-ui/index.html"
, "/swagger-ui.html","/webjars/**", "/swagger/**" // swagger
);
}

@Override
Expand All @@ -60,10 +61,14 @@ public void configure(HttpSecurity httpSecurity) throws Exception {
.accessDeniedHandler(authTokenAccessDeniedHandler)
.and()
.authorizeRequests()
.antMatchers("/api/v1/auth/**").permitAll()
.antMatchers("/api/v1/admin/**").permitAll()
.antMatchers("/api/v1/fcm-push/**").permitAll()
.antMatchers("/api/v1/fcm-push/**").permitAll()
.antMatchers("/api/v1/auth/**"
,"/api/v1/admin/**"
, "/api/v1/fcm-push/**"
, "/api/v1/auth/**"
, "/api/v1/admin/**"
, "/api/v1/fcm-push/random-spot/**"
, "/api/v1/heendy-guide/**"
, "/websocket/**").permitAll()
Comment on lines +64 to +71
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

인증 필요없는 경로들 추가

.antMatchers("/api/v1/stores/**").authenticated()
.antMatchers("/api/v1/members/**").authenticated()
.anyRequest().permitAll()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
log.debug("AuthTokenFilter : request " + request);
String accessToken = resolveToken(request);
log.debug("AuthTokenFilter : accessToken " + accessToken);
jwtTokenGenerator.isTokenValidate(accessToken);
if (!jwtTokenGenerator.isTokenValidate(accessToken)) {
log.error("AuthTokenFilter ERROR : accessToken 토큰이 유효하지 않습니다.");
throw new AdventureOfHeendyException(ErrorCode.ACCESS_TOKEN_INVALID);
}

Authentication authentication = createAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
} catch (Exception e) {
log.debug("AuthTokenFilter : accessToken 토큰이 유효하지 않습니다.");
throw new AdventureOfHeendyException(ErrorCode.ACCESS_TOKEN_INVALID);
log.error("AuthTokenFilter ERROR catch! accessToken 토큰이 유효하지 않습니다.");
}
filterChain.doFilter(request, response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ public Claims getClaims(String accessToken) {
* @since 2024/02/14
* 토큰 유효성 검증
*/
public void isTokenValidate(String token) {
public boolean isTokenValidate(String token) {
try {
Jwts.parser()
.setSigningKey(jwtSecret)
.parseClaimsJws(token);
return true;
} catch (JwtException | IllegalArgumentException e) {
throw new AdventureOfHeendyException(ErrorCode.ACCESS_TOKEN_INVALID);
log.error("isTokenValidate() 토큰 파싱 시, 에러 발생 ");
}
return false;
}
}
Loading