Skip to content

Commit

Permalink
Merge pull request #26 from hyundai-fruitfruit/HEENDY-89-Security-filter
Browse files Browse the repository at this point in the history
fix: Security AuthTokenFilter에서 에러 잡고 다음 필터로 넘기도록 설정 변경
  • Loading branch information
sooyoungh authored Mar 3, 2024
2 parents e5c07d3 + 6761ebc commit 3f592ae
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
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()
.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;
}
}

0 comments on commit 3f592ae

Please sign in to comment.