inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

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

Build and run using과 Run tests using을 Gradle이 아닌 InteliJ IDEA로 실행하면 해당 에러가 발생합니다.

237

JJEONG

작성한 질문수 8

0

스크린샷 2024-05-28 오후 10.30.57.png

Description:

Parameter 0 of constructor in com.example.membercertification.security.config.SecurityConfig required a single bean, but 2 were found:
	- authenticationProvider: defined in file [/Users/jjeong/Desktop/study/memberCertification/out/production/classes/com/example/membercertification/security/provider/FormAuthenticationProvider.class]
	- restAuthenticationProvider: defined in file [/Users/jjeong/Desktop/study/memberCertification/out/production/classes/com/example/membercertification/security/provider/RestAuthenticationProvider.class]

This may be due to missing parameter name information

Action:

Consider marking one of the beans as @Primary, updating the consumer to accept multiple beans, or using @Qualifier to identify the bean that should be consumed

Ensure that your compiler is configured to use the '-parameters' flag.
You may need to update both your build tool settings as well as your IDE.
(See https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention)

 

해당 에러에서 적힌 provider 2개를 @Qualifier와 @Primary로 설정하면 /api에서 로그인 할 경우, 로그인 영속성이 안 되는데 어떻게 해결해야 하나요 ?

 

spring spring-boot spring-security security web-security

답변 1

0

인프런 AI 인턴

안녕하세요, 인프런 AI 인턴입니다.

JJEONG님, 스프링 시큐리티 설정에서 언급된 두 개의 인증 제공자(AuthenticationProvider) 문제를 해결하기 위한 방법 중 하나는, 특정 API 경로(/api)에 대해서만 특정 AuthenticationProvider를 사용하도록 AuthenticationManagerBuilder를 구성하는 것입니다.

WebSecurityConfigurerAdapter를 상속받은 설정 클래스에서 configure(AuthenticationManagerBuilder auth) 메서드를 오버라이드하고, @Qualifier 어노테이션을 사용하여 특정 AuthenticationProvider를 명시적으로 지정할 수 있습니다. 그러나, 여러분의 경우 로그인 영속성 문제가 발생합니다. 이는 로그인 성공 후 세션이 제대로 관리되지 않거나, 특정 인증 메커니즘에 올바르게 연결되지 않았을 때 발생할 수 있습니다.

로그인 영속성 문제를 해결하기 위해 다음 접근 방법을 고려해 볼 수 있습니다:
1. SecurityConfig 설정에서 로그인 성공 후 사용자 세션을 어떻게 처리하는지 확인하세요. 이는 HttpSecurity 설정에서 sessionManagement() 메서드를 통해 구성할 수 있습니다.
2. 특정 AuthenticationProvider/api 로그인에만 사용되도록 명시적 경로 기반 구성을 적용해 보세요. 이는 종종 커스텀 필터를 추가하거나, HttpSecurity 설정에서 특정 경로에 대한 보안 구성을 따로 지정함으로써 구현할 수 있습니다.
3. @Primary를 사용하는 방법 외에도, @Qualifier를 사용하여 스프링 시큐리티가 적절한 AuthenticationProvider를 선택하도록 명확하게 지시할 수 있습니다. 각 경로 또는 인증 방식에 따라 다른 AuthenticationProvider를 명확하게 지정해 보세요.

각각의 해결책을 적용할 때는 애플리케이션의 특정 요구 사항과 로그인 흐름을 정확히 이해하는 것이 중요합니다. 또한, 로그인 영속성과 관련된 문제는 디버깅 시 로그인 과정에서 생성된 세션과 해당 세션이 이후 요청에서 어떻게 활용되는지를 자세히 관찰해야 합니다.

추가적인 정보가 필요하시면, 스프링 시큐리티 공식 문서 및 관련 가이드를 참조하시는 것이 좋습니다.

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

0

36

2

단원별 소스코드

0

66

2

CustomAuthenticationProvider 추가 관련 문의

0

78

2

AOP 의존성 명칭 변경

0

77

1

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

0

70

1

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

0

87

2

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

0

78

1

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

0

69

1

@EnableWebSecurity

0

148

1

트랜잭션과 롤백

0

100

1

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

0

91

2

AuthenticationManager 사용 방법

0

153

2

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

0

108

2

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

0

192

1

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

0

109

2

메타 주석 질문

0

69

1

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

0

153

3

로그인 후, redirect 에서 error

0

141

3

Session 생성 타이밍에 대한 질문

0

86

2

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

0

135

2

customAuthentication 관련

0

132

2

authenticationManagerBuilder 주입받은거 vs 만든 거

0

114

1

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

0

101

1

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

0

162

2