비동기 인증 - RestAuthenticationProvider 구현

RestAuthenticationProvider

@Component("restAuthenticationProvider")
@RequiredArgsConstructor
public class RestAuthenticationProvider implements AuthenticationProvider {

    private final UserDetailsService userDetailsService;
    private final PasswordEncoder passwordEncoder;

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        String loginId = authentication.getName();
        String password = (String) authentication.getCredentials();

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

        if (!passwordEncoder.matches(password, accountContext.getPassword())) {
            throw new BadCredentialsException("Invalid password");
        }

        return RestAuthenticationToken.authenticated(
            accountContext.getAccountDto(), null, accountContext.getAuthorities()
        );
    }

    @Override
    public boolean supports(Class<?> authentication) {
        return authentication.isAssignableFrom(RestAuthenticationToken.class);
    }
}

SecurityConfig


이전 ↩️ - 비동기 인증 - Rest 인증 필터 구현arrow-up-right

메인 ⏫arrow-up-right

다음 ↪️ - 비동기 인증 - Rest 인증 성공 및 실패 핸들러arrow-up-right

마지막 업데이트