UsernamePasswordAuthenticationFilter

ObjectMapper

@RequiredArgsConstructor

在我们写controller或者Service层的时候,需要注入很多的mapper接口或者另外的service接口,这时候就会写很多的@AutoWired注解,代码看起来很乱lombok提供了一个注解:

@RequiredArgsConstructor(onConstructor =@_(@Autowired))
写在类上可以代替@AutoWired注解,需要注意的是在注入时需要用final定义,或者使用@notnull注解

.addFilterAt

  1. .addFilterAt(restAuthenticationFilter(), UsernamePasswordAuthenticationFilter.class)

设置

  1. private RestAuthenticationFilter restAuthenticationFilter() throws Exception {
  2. RestAuthenticationFilter filter = new RestAuthenticationFilter(objectMapper);
  3. filter.setAuthenticationSuccessHandler(jsonLoginSuccessHandler());
  4. filter.setAuthenticationFailureHandler(jsonLoginFailureHandler());
  5. filter.setAuthenticationManager(authenticationManager());
  6. filter.setFilterProcessesUrl("/authorize/login");
  7. return filter;
  8. }