package com.iplatform.security;
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
import org.springframework.security.core.Authentication;
|
import org.springframework.security.core.AuthenticationException;
|
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
|
|
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletResponse;
|
|
/**
|
* DefaultAuthenticationToken 重写后,登录总是报错: 用户名或密码错误,尝试重写该过滤器。
|
* @author 时克英
|
* @date 2023-01-27
|
*/
|
@Deprecated
|
public class DefaultAuthenticationFilter extends UsernamePasswordAuthenticationFilter {
|
|
@Override
|
public Authentication attemptAuthentication(HttpServletRequest request, HttpServletResponse response) throws AuthenticationException {
|
// if (this.postOnly && !request.getMethod().equals("POST")) {
|
if (!request.getMethod().equals("POST")) {
|
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
|
} else {
|
String username = this.obtainUsername(request);
|
username = username != null ? username.trim() : "";
|
String password = this.obtainPassword(request);
|
password = password != null ? password : "";
|
// UsernamePasswordAuthenticationToken authRequest = UsernamePasswordAuthenticationToken.unauthenticated(username, password);
|
DefaultAuthenticationToken authRequest = (DefaultAuthenticationToken)DefaultAuthenticationToken.unauthenticated(username, password);
|
this.setDetails(request, authRequest);
|
return this.getAuthenticationManager().authenticate(authRequest);
|
}
|
}
|
}
|