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

[Feature/#38] Spring Security내 permitAll 동작할 수 있도록 JwtFilter를 수정한다 #54

Merged
merged 35 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
fd6fdcf
feat: 상위 목표 d-day 기능 구현, 테스트 작성 (#6)
Aug 12, 2023
7bcb5b5
최신 버전 merge
Aug 12, 2023
45bd990
최신 버전 merge
Aug 13, 2023
e47a639
최신 버전 머지
Aug 15, 2023
e041812
최신 버전 머지
Aug 17, 2023
a5d0f31
간격 수정
Aug 18, 2023
09e019c
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 19, 2023
8b5a93d
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 20, 2023
84608b8
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 20, 2023
c7f75d4
최신 사항 머지
Aug 20, 2023
d652017
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 20, 2023
162586a
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 20, 2023
c3a5fc5
git cache 초기화
Aug 20, 2023
c5bae84
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 22, 2023
0cad7d8
feat: FCM 알림 설정 및 연동 (#38)
Aug 22, 2023
09c8285
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 23, 2023
9db799c
최신 버전 머지
Aug 23, 2023
d805257
refactor: GoalController LocalTime 형식 변경
Aug 23, 2023
84d1636
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 23, 2023
4bb5071
feat: FCM 알림 스케쥴링 기능 복구
Aug 24, 2023
87a3962
refactor: 테스트 수정 및 도메인 디렉토리 구조 변경
Aug 24, 2023
7d62e93
최신 버전 머지
Aug 24, 2023
7d9f35e
refactor: DetailGoal 수정 시 locale 정보 변경
Aug 24, 2023
80ec248
최신 버전 머지
Aug 25, 2023
4e0ad17
fix: submodule에 fcm_key.json 경로 수정
Aug 25, 2023
9b2a6d9
refactor: 하위 목표 응답 시간 locale ko로 수정
Aug 25, 2023
fd88077
refactor: 상위 목표별 개수 카운드 쿼리 변경
Aug 25, 2023
d87799e
Merge branch 'dev' into feature/#38
jemlog Aug 25, 2023
30149d6
refactor: 상위 목표 수정 컨트롤러에서 Path Variable 사용하도록 변경
Aug 25, 2023
3214be6
Merge remote-tracking branch 'origin/feature/#38' into feature/#38
Aug 25, 2023
5bf3a5d
Merge branch 'dev' of https://github.com/dnd-side-project/dnd-9th-1-b…
Aug 25, 2023
bb999af
refactor: SecurityConfig 설정 변경
Aug 25, 2023
6f85902
refactor: TokenProvider에서 토큰값이 null인 경우 처리 조건 추가
Aug 25, 2023
fb7ce43
refactor: permitAll한 url은 token 예외가 발생하지 않도록 처리
Aug 25, 2023
6c78aba
Merge branch 'dev' into feature/#38
jemlog Aug 25, 2023
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
3 changes: 2 additions & 1 deletion src/main/java/com/backend/auth/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.Objects;

@Slf4j
@Component
Expand Down Expand Up @@ -100,7 +101,7 @@ public void validateToken(String token) {
}

public String getToken(String bearerToken) {
if(bearerToken.isEmpty()){
if(Objects.isNull(bearerToken) || bearerToken.isEmpty()){
throw new NullJwtException(ErrorCode.NO_TOKEN_PROVIDED);
} else if (!bearerToken.startsWith(TOKEN_HEADER_PREFIX)){
throw new InvalidJwtException(ErrorCode.INVALID_TOKEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,23 @@ public class AuthenticationFilter extends OncePerRequestFilter {

@Override
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
String accessToken = tokenProvider.getToken(request.getHeader(AUTHORIZATION_HEADER));

// 토큰의 유효성을 검증
tokenProvider.validateToken(accessToken);
blackListService.checkBlackList(accessToken);
try {
String accessToken = tokenProvider.getToken(request.getHeader(AUTHORIZATION_HEADER));

// 토큰의 유효성을 검증
tokenProvider.validateToken(accessToken);
blackListService.checkBlackList(accessToken);

// 인증 정보를 Security Context에 설정 후 다음 단계를 진행
Authentication authentication = tokenProvider.getAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
}
catch (Exception e)
{
System.out.println("에러 처리");
}

// 인증 정보를 Security Context에 설정 후 다음 단계를 진행
Authentication authentication = tokenProvider.getAuthentication(accessToken);
SecurityContextHolder.getContext().setAuthentication(authentication);
filterChain.doFilter(request, response);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/backend/global/api/AuthTestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.backend.global.api;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class AuthTestController {

@GetMapping("/token")
public String tokenTest()
{
return "token valid!";
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/backend/global/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Excepti
.and()

.authorizeHttpRequests()
.requestMatchers("/auth/**").permitAll()

.requestMatchers( "/detail-goals/**","/goals/**","/auth/**").permitAll()

.and()

.sessionManagement()
Expand Down