|
|
@@ -9,7 +9,6 @@ import org.springframework.security.authentication.BadCredentialsException; |
|
|
|
import org.springframework.security.authentication.InternalAuthenticationServiceException; |
|
|
|
import org.springframework.security.core.Authentication; |
|
|
|
import org.springframework.security.core.AuthenticationException; |
|
|
|
import org.springframework.security.core.userdetails.UsernameNotFoundException; |
|
|
|
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter; |
|
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; |
|
|
|
|
|
|
@@ -21,7 +20,7 @@ import javax.servlet.http.HttpServletResponse; |
|
|
|
* @Date 2020/8/3 8:46 下午 |
|
|
|
* @Version 1.0 |
|
|
|
**/ |
|
|
|
public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessingFilter { |
|
|
|
public class CredentialAuthFilter extends AbstractAuthenticationProcessingFilter { |
|
|
|
|
|
|
|
private boolean postOnly = true; |
|
|
|
|
|
|
@@ -33,7 +32,7 @@ public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessing |
|
|
|
// ~ Constructors |
|
|
|
// =================================================================================================== |
|
|
|
|
|
|
|
public UsernamePasswordAuthFilter(String processingUrl) { |
|
|
|
public CredentialAuthFilter(String processingUrl) { |
|
|
|
super(new AntPathRequestMatcher(processingUrl, HttpMethod.POST.name())); |
|
|
|
} |
|
|
|
|
|
|
@@ -52,14 +51,12 @@ public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessing |
|
|
|
if (StringUtils.isBlank(loginType)) { |
|
|
|
throw new BadCredentialsException("登陆类型不能为空"); |
|
|
|
} |
|
|
|
paramValid(identifier, credential, loginType); |
|
|
|
|
|
|
|
if (StringUtils.isBlank(identifier) || StringUtils.isBlank(credential)) { |
|
|
|
throw new UsernameNotFoundException("用户名或密码不能为空"); |
|
|
|
} |
|
|
|
|
|
|
|
identifier = identifier.trim(); |
|
|
|
credential = credential.trim(); |
|
|
|
loginType = loginType.trim(); |
|
|
|
identifier = trim(identifier); |
|
|
|
credential = trim(credential); |
|
|
|
loginType = trim(loginType); |
|
|
|
try { |
|
|
|
CredentialAuthToken authRequest = new CredentialAuthToken(identifier, credential, loginType); |
|
|
|
// Allow subclasses to set the "details" property |
|
|
@@ -78,7 +75,7 @@ public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessing |
|
|
|
authRequest.setDetails(authenticationDetailsSource.buildDetails(request)); |
|
|
|
} |
|
|
|
|
|
|
|
private void valid(String identifier, String credential, String loginType) { |
|
|
|
private void paramValid(String identifier, String credential, String loginType) { |
|
|
|
LoginTypeEnum loginTypeEnum = LoginTypeEnum.valueOf(loginType); |
|
|
|
switch (loginTypeEnum) { |
|
|
|
case DING_QR_LOGIN: { |
|
|
@@ -101,4 +98,11 @@ public class UsernamePasswordAuthFilter extends AbstractAuthenticationProcessing |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private String trim(String trimStr) { |
|
|
|
if (StringUtils.isNotBlank(trimStr)) { |
|
|
|
return trimStr.trim(); |
|
|
|
} |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |