|
@@ -1,15 +1,10 @@
|
|
|
package com.ym.mec.auth.core.filter;
|
|
|
|
|
|
-import com.ym.mec.auth.api.dto.SysUserInfo;
|
|
|
+import com.ym.mec.auth.api.entity.LoginEntity;
|
|
|
import com.ym.mec.auth.config.token.PhoneAuthenticationToken;
|
|
|
-import com.ym.mec.auth.service.SysUserService;
|
|
|
import com.ym.mec.common.security.SecurityConstants;
|
|
|
-import com.ym.mec.common.service.IdGeneratorService;
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
|
-import org.springframework.security.authentication.BadCredentialsException;
|
|
|
-import org.springframework.security.authentication.LockedException;
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
import org.springframework.security.core.AuthenticationException;
|
|
|
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
|
@@ -31,9 +26,6 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
|
|
|
|
private static final String SPRING_SECURITY_RESTFUL_LOGIN_URL = "/smsLogin";
|
|
|
private boolean postOnly = true;
|
|
|
-
|
|
|
- private SysUserService sysUserService;
|
|
|
- private IdGeneratorService smsCodeService;
|
|
|
|
|
|
public PhoneLoginAuthenticationFilter() {
|
|
|
super(new AntPathRequestMatcher(SPRING_SECURITY_RESTFUL_LOGIN_URL, "POST"));
|
|
@@ -44,35 +36,17 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
|
if (postOnly && !request.getMethod().equals("POST")) {
|
|
|
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
|
|
|
}
|
|
|
-
|
|
|
AbstractAuthenticationToken authRequest;
|
|
|
// 手机验证码登陆
|
|
|
String principal = obtainParameter(request, SPRING_SECURITY_RESTFUL_PHONE_KEY);
|
|
|
- String credentials = obtainParameter(request, SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY);
|
|
|
- String isRegister = obtainParameter(request, IS_REGISTER_PARAMETER);
|
|
|
- //是否是租户
|
|
|
- String isLessee = obtainParameter(request, IS_LESSEE);
|
|
|
- // 验证码验证
|
|
|
- boolean b = smsCodeService.verifyValidCode(StringUtils.substringAfter(principal, SecurityConstants.PHONE_PRINCIPAL_PREFIX), credentials);
|
|
|
- if(!b) throw new BadCredentialsException("验证码校验失败");
|
|
|
-
|
|
|
- SysUserInfo userInfo = sysUserService.queryUserInfoByPhone(principal);
|
|
|
-
|
|
|
- String clientId = request.getParameter(clientIdParameter).toUpperCase();
|
|
|
- if (userInfo == null) {
|
|
|
- userInfo = sysUserService.initUser(principal,clientId,isRegister,isLessee);
|
|
|
- }else if(StringUtils.isNotEmpty(isLessee)){
|
|
|
- throw new LockedException("用户已存在");
|
|
|
- }
|
|
|
- if("EDUCATION".equals(clientId)){
|
|
|
- clientId = "SYSTEM";
|
|
|
- }
|
|
|
- if (!userInfo.getSysUser().getUserType().contains(clientId)) {
|
|
|
- throw new LockedException("用户不存在,请联系教务老师");
|
|
|
- }
|
|
|
-
|
|
|
principal = principal.trim();
|
|
|
- authRequest = new PhoneAuthenticationToken(SecurityConstants.PHONE_PRINCIPAL_PREFIX + principal, credentials);
|
|
|
+ LoginEntity loginEntity = new LoginEntity();
|
|
|
+ loginEntity.setClientId(request.getParameter(clientIdParameter).toUpperCase());
|
|
|
+ loginEntity.setIsLessee(obtainParameter(request, IS_LESSEE));
|
|
|
+ loginEntity.setPhone(principal);
|
|
|
+ loginEntity.setSmsCode(obtainParameter(request, SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY));
|
|
|
+ loginEntity.setIsRegister(obtainParameter(request, IS_REGISTER_PARAMETER));
|
|
|
+ authRequest = new PhoneAuthenticationToken(principal, loginEntity);
|
|
|
|
|
|
// Allow subclasses to set the "details" property
|
|
|
setDetails(request, authRequest);
|
|
@@ -94,12 +68,4 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
|
String result = request.getParameter(parameter);
|
|
|
return result == null ? "" : result;
|
|
|
}
|
|
|
-
|
|
|
- public void setSysUserService(SysUserService sysUserService) {
|
|
|
- this.sysUserService = sysUserService;
|
|
|
- }
|
|
|
-
|
|
|
- public void setSmsCodeService(IdGeneratorService smsCodeService) {
|
|
|
- this.smsCodeService = smsCodeService;
|
|
|
- }
|
|
|
}
|