inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

CustomAuthenticationProvider 질문드립니다!

564

cjswoudddn

작성한 질문수 6

0

안녕하세요 선생님

우선 좋은 강의 감사드립니다!

spring context에서 빈 생성 방법에 대해 질문드립니다

이전에 CustomAuthenticaionService는 @Service 어노테이션으로 빈으로 등록하고

SecurityConfig에서 @Autowird를 통해 주입 받은 빈을 

auth.userDetailsService에 전달해주셨습니다.

반면, CustomAuthenticationProvider는 

바로 밑에 빈 생성 매서드를 이용해 주입하셨고,

@Bean

CustomAuthenticationProvider customAuthenticationProvider(){

    return ...

}

저는 아무 생각 없이 CustomAuthenticationService처럼 @Service 어노테이션을 붙인 뒤

@Autowired를 이용해 Prover를 주입했습니다.

이때 무수히 많은 에러로그를 발생시키면서 프로그램이 종료되는데 혹시 원인을 알 수 있을까요??

감사합니다!

java Spring Security spring-boot

답변 2

0

cjswoudddn

우선 답변 감사드립니다!

선생님이 적어주신 내용으로 문제가 해결되었습니다.

다만, 저는 CustomAuthenticaionProvider에 의존성주입을 생성자를 통해 해주었습니다.

그리고 @Service로 빈등록을 마친 후 다시 생성자를 통해 CustomAuthenticationProvider를 주입해주었습니다.

의존성 주입에서 문제가 생긴듯 합니다 ㅠㅠ 감사드립니다!

0

정수원

말씀하신 대로 해도 상관없습니다.

몇가지만 수정하시면 됩니다.

FormAuthenticationProvider 에 보시면 PasswordEncoder 에 @Autowired 를 설정해 주시고

@Service
public class FormAuthenticationProvider implements AuthenticationProvider {

@Autowired
private UserDetailsService userDetailsService;

@Autowired
private PasswordEncoder passwordEncoder;

SecurityConfig 에서

@Configuration
@EnableWebSecurity
@Slf4j
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
private FormWebAuthenticationDetailsSource formWebAuthenticationDetailsSource;
@Autowired
private AuthenticationSuccessHandler formAuthenticationSuccessHandler;
@Autowired
private AuthenticationFailureHandler formAuthenticationFailureHandler;
@Autowired
private SecurityResourceService securityResourceService;
@Autowired
private AuthenticationProvider formAuthenticationProvider;

@Autowired
private AuthenticationProvider formAuthenticationProvider;

와 같이 추가해 주시면 됩니다.

그리고

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.authenticationProvider(formAuthenticationProvider);
}

와 같이 설정해 주시면 정상적으로 동작하고 있습니다.

혹시 잘 안되시면 github 에 소스를 공유해 주시면 제가 확인해 보겠습니다.

시큐리티 공부 버전 질문

0

175

1

[해결 방법] MethodSecurityConfig.customMethodSecurityMetadataSource() 호출하지 않는 이슈

0

185

1

AbstractSecurityInterceptor.class.beforeInvocation()를 2번 실행하는 경우

0

174

1

강의 코드가 왜이렇게 뒤죽박죽인가요...

0

249

1

메인 페이지로 접속해도 login url로 리다이렉트가 되지 않습니다..

0

235

1

파라미터값이 넘어가지 않습니다 ....

0

374

1

security filterChain 설정 질문이 있습니다.

0

330

1

소스 부분 질문 드립니다.

0

208

2

섹션4 7번 강의 문제가 있는거 같네요.

0

344

2

파일이 수시로 이름이 바껴있네요 ㄷㄷ

0

304

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

555

2

error , exception 이 잘 안됩니다.

0

278

2

thymeleaf tag 질문합니다.

0

196

2

버전업하면서 deprecated된 것들이 너무많아요

0

478

1

spring security 패치 관련

0

437

1

모바일을 사용할때 토큰말고 세션

0

845

2

DB 연동한 인가 부분에 대한 질문입니다!

0

264

1

Ajax방식도 똑같이 Session방식을 사용하는건가요?

0

307

1

Config 파일 생성 시 질문이 있습니다.

0

225

1

강사님 몇일동안 구글 검색만 100개 했는데도 이유를 모르겠습니다..

1

429

2

403 에러 뜹니다.

0

813

2

login_proc의 존재에 대한 간략한 설명입니다

0

275

1

top.html에 로그인 링크를 만들어서 로그인을 해봤습니다

0

278

2

안녕하세요. DB에 저장될 때 이해 안 가는 값이 있어서 질문드립니다!

0

189

1