前言
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(),