inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

스프링 시큐리티

5) DB 연동 인증 처리(2) : CustomAuthenticationProvider

provider안쪽에

283

대배랙

작성한 질문수 15

0


log.info("username : "+username);
log.info("password : "+password );

  AccountContext accountContext = (AccountContext) userDetailsService.loadUserByUsername(username);

이부분에서

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception

java.lang.NullPointerException: null

이에러가나는데

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    log.info("로그로그로그");

여기 자체로 넘어오지를 않습니다.

어떤거를 손봐야할까요..

@RequiredArgsConstructor
public class CustomUserDetailsService implements UserDetailsService {

    private final UserRepository userRepository;

지금 보통 RequiredArgsConstructor 로 초기화중입니다.

빼고 해봐도 별차이가없네요..

 

@Getter
public class AccountContext extends User {

    private Account account;

    public AccountContext(Account account, ArrayList<GrantedAuthority> roles) {
        super(account.getUsername(), account.getPassword(), roles);
        this.account = account;
    }

}

AccountContext 코드입니다.

제가 혼자 해보려고해도 시간이많이없어서 질문올립니다..

오래된강의인거는 알고있었지만 너무많이 바뀐거같아요..

 

java spring-boot Spring Security

답변 2

0

정수원

현재 AuthenticationProvider 객체를 생성하고 있는데 빈으로 정의하지 않고 있는 것 같습니다.

첫번째로 설정클래스에서 객체를 생성하고 있는데 @Bean 이 없습니다.

public AuthenticationProvider authenticationProvider() {
    return new CustomAuthenticationProvider(passwordEncoder());
}

 

그리고

@Slf4j
public class CustomAuthenticationProvider implements AuthenticationProvider {

 

직접 클래스를 정의할 때도 @Component 가 정의되지 않고 있습니다.

그래서 CustomUserDetailsService 를 주입받지 못하고 있어서 null 이 되고 있습니다.

결론은 AuthenticationProvider 객체를 생성할 때 빈으로 정의하시면 됩니다.

0

정수원

지금 실행하고 있는 소스를 공유 부탁드려요

제가 테스트 해 보겠습니다.

0

대배랙

https://github.com/Baekwangyeol/nullpointexception

깃허브 생성해서 올렸습니다.! 오늘도 이것저것 했는데 안넘어가져서 올려용ㅠㅠ

시큐리티 공부 버전 질문

0

190

1

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

0

197

1

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

0

186

1

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

0

271

1

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

0

248

1

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

0

382

1

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

0

337

1

소스 부분 질문 드립니다.

0

213

2

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

0

352

2

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

0

312

1

HttpSessionSecurityContextRepository를 사용안하는 문제

0

566

2

error , exception 이 잘 안됩니다.

0

289

2

thymeleaf tag 질문합니다.

0

201

2

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

0

483

1

spring security 패치 관련

0

442

1

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

0

869

2

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

0

269

1

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

0

313

1

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

0

238

1

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

1

443

2

403 에러 뜹니다.

0

828

2

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

0

283

1

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

0

295

2

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

0

196

1