현재 우리 프로젝트 구조는
ApiGateway -> Eureka확인 -> 후 해당 service들에게 요청을 보내는 형식이다.
즉, ApiGateway에서 jwtfilter를 통한 인증,인가를 하고 있다.
프로젝트 과정에서 MSA 구조로 프로젝트를 올려야 했고, 이 과정에서 인증 문제가 발생해
계속 401 UNAUHTORIZED가 발생했다.
이를 해결해보자 .
JWTFILTER만 있는것이 아니다.
JWTFILTERCHAIN 뿐만 아니라, CORS, 기본 SecurityFilter등이 존재한다.
@Configuration
@EnableWebSecurity
public class SecurityConfig {
private final JwtProvider jwtProvider;
private final MemberDetailService memberDetailService;
private final OAuth2Service oAuth2Service;
private final OAuth2SuccessHandler oAuth2SuccessHandler;
public SecurityConfig(JwtProvider jwtProvider, MemberDetailService memberDetailService, OAuth2Service oAuth2Service, OAuth2SuccessHandler oAuth2SuccessHandler) {
//
}
@Bean
public static BCryptPasswordEncoder passwordEncoder() {
return new BCryptPasswordEncoder();
}
@Bean
protected AuthenticationProvider authenticationProvider() {
//
}
// cors=다른 도메인의 리소스에 웹 페이지가 접근할 수 있도록 브라우저에게 권한을 부여
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
//
}
@Bean
public CorsConfigurationSource corsConfigurationSource() {
//
}
}
- member의 Security Config 예시
개발 과정에선, spring security를 끄고 실행했습니다.
public class SecurityConfig {
}
@SpringBootApplication(exclude = SecurityAutoConfiguration.class)
@EnableDiscoveryClient
@RefreshScope
public class BucketApplication {
public static void main(String[] args) {
SpringApplication.run(BucketApplication.class, args);
}
}
apigateway의 jwtfilter를 활용하여 외부 접근 자체를 불가능하게 만든 방식에 의존하여,
나머지 spring security의 기능들은 종료한 후 개발하도록 하겠습니다.
'프로젝트 > 장애인 PT 플랫폼, PTFD' 카테고리의 다른 글
NCP로 GCP 활용 부 변경 (0) | 2024.07.04 |
---|---|
1차 완성, 코드 리뷰 (3) | 2024.04.16 |
RESTFUL URL 규칙 + 협업시 지켜야 할 것들 (0) | 2024.04.06 |
@builder/ 모든 생성자 (0) | 2024.04.03 |
DELETE , UPDATE 쿼리 관련 동시성 문제 (0) | 2024.03.30 |