-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refact, feat: JwtTokenProvider 인터페이스로 변환 * feat: JwtTokenProvider 구현체 accessTokenProvider, refreshTokenprovider 구현 * refact: 토근검증함수 validateToken 필터로 이동 * refact: 비즈니스로직 수정 시작 * refact: TokenProvider 사용하는 로직들 수정 * refact: Primary 어노테이션으로 우선순위 설정, AuthService 로직 수정 * refact: AuthService tokenProvider 선언 수정 * refact: Qualifier 어노테이션 적용 * feat: 의존성 분리를 위한 JwtHelper 구현 * refact: RedisUtitl ttl설정 수정, JwtHelper 사용하는 서비스로직 수정 * refact: jwtConfig 삭제, 리뷰컨트롤러 import 수정 * feat: jwt 예외필터 및 엔트리 포인트 구현 * refact: 시큐리티config 수정 * refact: 불필요 import 제거 * refact: 검증로직 수정
- Loading branch information
1 parent
da2342d
commit 5842ed4
Showing
17 changed files
with
371 additions
and
155 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,26 @@ | ||
package gible.config; | ||
|
||
import gible.domain.security.jwt.JwtAuthenticationFilter; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import gible.domain.security.jwt.JwtAuthenticationEntryPoint; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
|
||
@Configuration | ||
@EnableWebSecurity(debug = true) | ||
@RequiredArgsConstructor | ||
@Configuration | ||
public class SecurityConfig { | ||
private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||
|
||
private final ObjectMapper objectMapper; | ||
@Bean | ||
protected SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { | ||
httpSecurity.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests(authorizeHttpRequests -> | ||
authorizeHttpRequests.requestMatchers( | ||
"/auth/kakaologin", | ||
"/auth/token",//라우팅 아직 설정x | ||
"/swagger-resources/**", | ||
"/swagger-ui/**", | ||
"/v3/api-docs/**", | ||
"/user/*", | ||
"/user", | ||
"/webjars/**", | ||
"/error", | ||
"/auth/logout", | ||
"/review/ssibal" | ||
).permitAll() | ||
.anyRequest().authenticated()) | ||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class); | ||
public JwtAuthenticationEntryPoint authenticationEntryPoint() { | ||
return new JwtAuthenticationEntryPoint(objectMapper); | ||
} | ||
|
||
return httpSecurity.build(); | ||
@Bean | ||
public PasswordEncoder passwordEncoder(){ | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package gible.config; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import gible.domain.security.jwt.JwtAuthenticationFilter; | ||
import gible.domain.security.jwt.JwtExceptionFilter; | ||
import gible.global.util.jwt.JwtHelper; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class SecurityFilterConfig { | ||
private final JwtHelper jwtHelper; | ||
private final UserDetailsService userDetailsService; | ||
private final ObjectMapper objectMapper; | ||
|
||
@Bean | ||
public JwtExceptionFilter jwtExceptionFilter(){ | ||
return new JwtExceptionFilter(objectMapper); | ||
} | ||
|
||
@Bean | ||
public JwtAuthenticationFilter jwtAuthenticationFilter(){ | ||
return new JwtAuthenticationFilter(jwtHelper, userDetailsService); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package gible.config; | ||
|
||
import gible.domain.security.jwt.JwtAuthenticationFilter; | ||
import gible.domain.security.jwt.JwtExceptionFilter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter; | ||
|
||
@Configuration | ||
@EnableWebSecurity(debug = true) | ||
@RequiredArgsConstructor | ||
public class WebSecurityConfig { | ||
private final AuthenticationEntryPoint authenticationEntryPoint; | ||
private final JwtAuthenticationFilter jwtAuthenticationFilter; | ||
private final JwtExceptionFilter jwtExceptionFilter; | ||
@Bean | ||
protected SecurityFilterChain filterChain(HttpSecurity httpSecurity) throws Exception { | ||
httpSecurity.csrf(AbstractHttpConfigurer::disable) | ||
.authorizeHttpRequests(authorizeHttpRequests -> | ||
authorizeHttpRequests.requestMatchers( | ||
"/auth/kakaologin", | ||
"/auth/token",//라우팅 아직 설정x | ||
"/swagger-resources/**", | ||
"/swagger-ui/**", | ||
"/v3/api-docs/**", | ||
"/user/*", | ||
"/user", | ||
"/webjars/**", | ||
"/error", | ||
"/auth/logout" | ||
).permitAll() | ||
.anyRequest().authenticated()) | ||
.exceptionHandling(exception-> exception.authenticationEntryPoint(authenticationEntryPoint)) | ||
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class) | ||
.addFilterBefore(jwtExceptionFilter, JwtAuthenticationFilter.class); | ||
|
||
return httpSecurity.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
src/main/java/gible/domain/security/jwt/JwtAuthenticationEntryPoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package gible.domain.security.jwt; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.servlet.ServletException; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpServletResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.security.core.AuthenticationException; | ||
import org.springframework.security.web.AuthenticationEntryPoint; | ||
|
||
import java.io.IOException; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint { | ||
private final ObjectMapper objectMapper; | ||
@Override | ||
public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException { | ||
log.warn("Unauthorized : {}", authException.getMessage()); | ||
response.setContentType("application/json;charset=UTF-8"); | ||
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED); | ||
objectMapper.writeValue(response.getWriter(), null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.