|
@@ -7,6 +7,7 @@ import javax.servlet.ServletException;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.security.authentication.AuthenticationServiceException;
|
|
|
import org.springframework.security.authentication.LockedException;
|
|
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
@@ -20,6 +21,7 @@ import org.springframework.util.Assert;
|
|
|
import com.keao.edu.auth.api.dto.SysUserInfo;
|
|
|
import com.keao.edu.auth.api.util.SecurityConstants;
|
|
|
import com.keao.edu.auth.service.SysUserService;
|
|
|
+import com.keao.edu.datasource.DataSourceContextHolder;
|
|
|
|
|
|
public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessingFilter {
|
|
|
|
|
@@ -31,6 +33,7 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
|
|
|
private String usernameParameter = "username";
|
|
|
private String passwordParameter = "password";
|
|
|
private String clientIdParameter = "clientId";
|
|
|
+ private String tenantIdParameter = "tenantId";
|
|
|
private boolean postOnly = true;
|
|
|
|
|
|
// ~ Constructors
|
|
@@ -47,6 +50,16 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
|
|
|
if (postOnly && !request.getMethod().equals("POST")) {
|
|
|
throw new AuthenticationServiceException("Authentication method not supported: " + request.getMethod());
|
|
|
}
|
|
|
+
|
|
|
+ String tenantId = request.getHeader(tenantIdParameter);
|
|
|
+ if (StringUtils.isBlank(tenantId)) {
|
|
|
+ tenantId = request.getParameter(tenantIdParameter);
|
|
|
+ }
|
|
|
+ if(StringUtils.isBlank(tenantId)){
|
|
|
+ throw new LockedException("缺少商户编号参数");
|
|
|
+ }
|
|
|
+
|
|
|
+ DataSourceContextHolder.setDataSourceKey(tenantId);
|
|
|
|
|
|
String username = obtainUsername(request);
|
|
|
String password = obtainPassword(request);
|
|
@@ -69,14 +82,8 @@ public class UsernameAuthenticationFilter extends AbstractAuthenticationProcessi
|
|
|
throw new UsernameNotFoundException("404.9");
|
|
|
}
|
|
|
|
|
|
-// if (userInfo.getSysUser().getUserType() != SysUserType.SYSTEM && !StringUtils.equalsIgnoreCase(clientId, userInfo.getSysUser().getUserType().getCode())) {
|
|
|
-// throw new LockedException("登录失败");
|
|
|
-// }
|
|
|
- if("EDUCATION".equals(clientId)){
|
|
|
- clientId = "SYSTEM";
|
|
|
- }
|
|
|
- if (!userInfo.getSysUser().getUserType().contains(clientId)) {
|
|
|
- throw new LockedException("用户不存在,请联系教务老师");
|
|
|
+ if (!StringUtils.upperCase(userInfo.getSysUser().getUserType()).contains(StringUtils.upperCase(clientId))) {
|
|
|
+ throw new UsernameNotFoundException("用户不存在");
|
|
|
}
|
|
|
|
|
|
UsernamePasswordAuthenticationToken authRequest = new UsernamePasswordAuthenticationToken(SecurityConstants.USERNAME_PRINCIPAL_PREFIX + username,
|