[Spring Cloud] - 15. Users Microservice AuthenticationFilter
목차 [Spring Cloud] - 20. Users Microservice AuthorizationHeaderFilter 추가 [Spring Cloud] - 19. Users Microservice JWT 생성 [Spring Cloud] - 18. Users Microservice 로그인 성공 처리 [Spring Cloud] - 17. Users Microservice Routes 정보 변경 [Spring Cloud] - 16. Users Microservice loadUserByUsername() 구현 [Spring Cloud] - 15. Users Microservice AuthenticationFilter [Spring Cloud] - 14. Users Microservice Order Service [Spring Cloud] - 13. Users Microservice Catalog [Spring Cloud] - 12. Users Microservice 사용자 조회 [Spring Cloud] - 11. Users Microservice Gateway 연동 [Spring Cloud] - 10. Users Microservice 사용자 추가 [Spring Cloud] - 개발하는 마이크로서비스 애플리케이션 9 [Spring Cloud] - Users Microservice 15. Users Microservice AuthenticationFilter@Datapublic class RequestLogin { @NotNull(message = "Email cannot be null") @Size(min = 2, message = "Email not be less than two characters") private String email; @NotNull(message = "Password cannot be null") @Size(min = 8, message = "Password must be equals or grater than 8 characters") private String password;} public class AuthenticationFilter extends UsernamePasswordAuthenticationFilter { @Override public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException { try { RequestLogin creds = new ObjectMapper().readValue(request.getInputStream(), RequestLogin.class); Authentication token = new UsernamePasswordAuthenticationToken(creds.getEmail(), creds.getPassword(), new ArrayList<>()); return getAuthenticationManager().authenticate(token); } catch (IOException e){ throw new RuntimeException(e); } } @Override protected void successfulAuthentication(HttpServletRequest request, HttpServletResponse response, FilterChain chain, Authentication authResult) throws IOException, ServletException { super.successfulAuthentication(request, response, chain, authResult); }}