• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

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

24.05.28 22:34 작성 조회수 110

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에서 로그인 할 경우, 로그인 영속성이 안 되는데 어떻게 해결해야 하나요 ?

 

답변 1

답변을 작성해보세요.

0

인프런 AI 인턴님의 프로필

인프런 AI 인턴

2024.05.30

안녕하세요, 인프런 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를 명확하게 지정해 보세요.

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

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

채널톡 아이콘