|
@@ -7,19 +7,15 @@ import javax.servlet.ServletException;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
-import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
-import org.springframework.security.authentication.LockedException;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.Authentication;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.core.AuthenticationException;
|
|
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
|
import org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter;
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
|
|
|
|
-import com.keao.edu.auth.api.dto.SysUserInfo;
|
|
|
|
import com.keao.edu.auth.api.entity.LoginEntity;
|
|
import com.keao.edu.auth.api.entity.LoginEntity;
|
|
import com.keao.edu.auth.config.token.PhoneAuthenticationToken;
|
|
import com.keao.edu.auth.config.token.PhoneAuthenticationToken;
|
|
-import com.keao.edu.auth.service.SysUserService;
|
|
|
|
import com.keao.edu.common.security.SecurityConstants;
|
|
import com.keao.edu.common.security.SecurityConstants;
|
|
|
|
|
|
public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
|
public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
|
@@ -27,14 +23,10 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
private static final String SPRING_SECURITY_RESTFUL_PHONE_KEY = "phone";
|
|
private static final String SPRING_SECURITY_RESTFUL_PHONE_KEY = "phone";
|
|
private static final String SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY = "smsCode";
|
|
private static final String SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY = "smsCode";
|
|
private static final String clientIdParameter = "clientId";
|
|
private static final String clientIdParameter = "clientId";
|
|
- private static final String IS_REGISTER_PARAMETER = "register";
|
|
|
|
- private static final String IS_LESSEE = "isLessee";
|
|
|
|
|
|
|
|
private static final String SPRING_SECURITY_RESTFUL_LOGIN_URL = "/smsLogin";
|
|
private static final String SPRING_SECURITY_RESTFUL_LOGIN_URL = "/smsLogin";
|
|
private boolean postOnly = true;
|
|
private boolean postOnly = true;
|
|
|
|
|
|
- private SysUserService sysUserService;
|
|
|
|
-
|
|
|
|
public PhoneLoginAuthenticationFilter() {
|
|
public PhoneLoginAuthenticationFilter() {
|
|
super(new AntPathRequestMatcher(SPRING_SECURITY_RESTFUL_LOGIN_URL, "POST"));
|
|
super(new AntPathRequestMatcher(SPRING_SECURITY_RESTFUL_LOGIN_URL, "POST"));
|
|
}
|
|
}
|
|
@@ -49,32 +41,15 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
// 手机验证码登陆
|
|
// 手机验证码登陆
|
|
String principal = obtainParameter(request, SPRING_SECURITY_RESTFUL_PHONE_KEY);
|
|
String principal = obtainParameter(request, SPRING_SECURITY_RESTFUL_PHONE_KEY);
|
|
String credentials = obtainParameter(request, SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY);
|
|
String credentials = obtainParameter(request, SPRING_SECURITY_RESTFUL_VERIFY_CODE_KEY);
|
|
- String isRegister = obtainParameter(request, IS_REGISTER_PARAMETER);
|
|
|
|
- // 是否是租户
|
|
|
|
- String isLessee = obtainParameter(request, IS_LESSEE);
|
|
|
|
|
|
|
|
String clientId = request.getParameter(clientIdParameter).toUpperCase();
|
|
String clientId = request.getParameter(clientIdParameter).toUpperCase();
|
|
-
|
|
|
|
-// SysUserInfo userInfo = sysUserService.queryUserInfoByPhone(principal);
|
|
|
|
- SysUserInfo userInfo = sysUserService.queryUserInfoByPhoneAndClient(principal,clientId);
|
|
|
|
- if (userInfo != null && StringUtils.isNotEmpty(isLessee)) {
|
|
|
|
- throw new LockedException("用户已存在");
|
|
|
|
- }
|
|
|
|
- if ("EDUCATION".equals(clientId)) {
|
|
|
|
- clientId = "SYSTEM";
|
|
|
|
- }
|
|
|
|
- if (userInfo != null && !userInfo.getSysUser().getUserType().contains(clientId)) {
|
|
|
|
- throw new LockedException("用户不存在,请联系教务老师");
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+
|
|
principal = principal.trim();
|
|
principal = principal.trim();
|
|
|
|
|
|
LoginEntity loginEntity = new LoginEntity();
|
|
LoginEntity loginEntity = new LoginEntity();
|
|
loginEntity.setClientId(clientId);
|
|
loginEntity.setClientId(clientId);
|
|
- loginEntity.setIsLessee(isLessee);
|
|
|
|
loginEntity.setPhone(principal);
|
|
loginEntity.setPhone(principal);
|
|
loginEntity.setSmsCode(credentials);
|
|
loginEntity.setSmsCode(credentials);
|
|
- loginEntity.setIsRegister(isRegister);
|
|
|
|
|
|
|
|
authRequest = new PhoneAuthenticationToken(SecurityConstants.PHONE_PRINCIPAL_PREFIX + principal, loginEntity);
|
|
authRequest = new PhoneAuthenticationToken(SecurityConstants.PHONE_PRINCIPAL_PREFIX + principal, loginEntity);
|
|
|
|
|
|
@@ -99,8 +74,4 @@ public class PhoneLoginAuthenticationFilter extends AbstractAuthenticationProces
|
|
return result == null ? "" : result;
|
|
return result == null ? "" : result;
|
|
}
|
|
}
|
|
|
|
|
|
- public void setSysUserService(SysUserService sysUserService) {
|
|
|
|
- this.sysUserService = sysUserService;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
}
|
|
}
|