inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티 완전 정복 [6.x 개정판]

인증 제공자 - AuthenticationProvider - 2

빈 1개 등록 시 다른 해결 방법

65

매콤한각설탕

작성한 질문수 17

0

 

@Configuration
public class SecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) {
        return http
                .authorizeHttpRequests(auth -> auth.anyRequest().authenticated())
                .formLogin(Customizer.withDefaults())
                .authenticationProvider(customAuthenticationProvider())
                .authenticationProvider(new DaoAuthenticationProvider(inMemoryUserDetailsManager()))
                .build();
    }

    @Bean
    public AuthenticationProvider customAuthenticationProvider() {
        return new CustomAuthenticationProvider();
    }

    @Bean
    public UserDetailsService inMemoryUserDetailsManager() {
        UserDetails user = User.withUsername("user")
                .password("{noop}1111")
                .roles("USER")
                .build();

        return new InMemoryUserDetailsManager(user);
    }
}

 

메소드 인자로 AuthenticationManagerBuilderAuthenticationconfiguration을 주입 받아서 수동으로 parent Manager가 가진 Provider를 삭제하고 추가하는 작업을 하지 말고,

그냥 안전하게, 대체되었던 DaoAuthenticationProviderauthenticationProvider()로 다시 추가하면 안 되나요?

spring spring-boot spring-security security web-security

답변 1

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.
매콤한각설탕님께서 질문 주셨네요.

SecurityFilterChain 구성 시, 별도로 AuthenticationManagerBuilderAuthenticationConfiguration을 사용하여 parent Manager의 Provider를 삭제하고 추가하는 방식을 피하고자 하신다면, DaoAuthenticationProvider를 직접 추가하는 방법 역시 가능합니다.

사실상 코드 상에서도 DaoAuthenticationProviderauthenticationProvider()에 다시 추가해 놓으셨습니다. 이렇게 구현하시면 CustomAuthenticationProviderDaoAuthenticationProvider가 모두 사용됩니다.

이처럼 SecurityFilterChain 내에서 authenticationProvider()를 통해 필요한 AuthenticationProvider들을 지정하고 사용하시면 Spring Security에서 여러 가지 인증 경로를 관리하는 데 문제가 없습니다.

계속해서 학습하시면서 문제가 생기시면 언제든지 질문해 주세요!

도움이 되셨기를 바랍니다. 관련된 문서를 참고하시려면 아래의 링크를 사용하세요:
Spring Boot Reference Documentation - Security

감사합니다.

로그아웃-logout()-2 강에서 겟방식 로그아웃 호출 후 화면이동 질문입니다.

0

27

2

단원별 소스코드

0

59

2

CustomAuthenticationProvider 추가 관련 문의

0

69

2

AOP 의존성 명칭 변경

0

63

1

@Bean으로 AuthenticationProvider를 등록 시 http.authenticationProvider 함수를 이용해서 추가해줘야되나요?

0

85

2

OIDC의 id token에 담긴 데이터에 대해

0

74

1

loginPage("/loginPage") 질문드립니다.

0

68

1

@EnableWebSecurity

0

147

1

트랜잭션과 롤백

0

99

1

68. 인증 이벤트 - AuthenticationEventPublisher 활용 강좌 음성 문제

0

87

2

AuthenticationManager 사용 방법

0

148

2

HttpSecurity.authorizeHttpRequests() - 2 강의 부분에 대한 질문

0

102

2

spring security 6.3에서는 HttpSecurity가 만들어지기 전 WebSecurity가 먼저 만들어지는게 맞나요??

0

190

1

init(B Builder), configure(B builder) 에 대하여 질문 드립니다.

0

105

2

메타 주석 질문

0

68

1

동시세션제어 기능에서 로그아웃하기

0

144

3

로그인 후, redirect 에서 error

0

138

3

Session 생성 타이밍에 대한 질문

0

84

2

강의 참고 내용을 개발 로그로 작성해도 될지 문의드립니다.

0

132

2

customAuthentication 관련

0

126

2

authenticationManagerBuilder 주입받은거 vs 만든 거

0

110

1

UserDetailsService()에서 UserDetail이 아닌 타입을 반환할 수 있나요?

0

101

1

9:28 패턴 3의 경우 마지막으로 설정한 것만 적용되는 것 같습니다.

0

158

2

Bean UserDetailsService

0

90

2