16、SpringBoot集成SpringSecurity实战:使用JSON登录

前言

SpringSecurity默认使用表单登录,不支持Json方式登录,接下来设置既可以支持表单登录,也可以支持Json方式登录。

实现

public class SignInFilter extends UsernamePasswordAuthenticationFilter {
   
   
     
    @Override
    public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws
            AuthenticationException {
   
   
     
        if (MediaType.APPLICATION_JSON_VALUE.equals(request.getContentType()) && request.getMethod().equals("POST")) {
   
   
     
            Map<String, String> requestBody = null;
            try {
   
   
     
                requestBody = new ObjectMapper().readValue(request.getInputStream(), 

版权声明:本文不是「本站」原创文章,版权归原作者所有 | 原文地址: