|
|
@@ -25,7 +25,9 @@ import org.springframework.security.access.ConfigAttribute;
|
|
|
import org.springframework.security.access.SecurityConfig;
|
|
|
import org.springframework.security.core.GrantedAuthority;
|
|
|
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
|
|
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
|
|
|
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
|
|
+import org.springframework.util.StringUtils;
|
|
|
|
|
|
import com.uas.platform.b2b.dao.ResourceItemDao;
|
|
|
import com.uas.platform.b2b.manage.service.AccessTokenService;
|
|
|
@@ -43,6 +45,7 @@ import com.uas.platform.b2b.support.SystemSession;
|
|
|
import com.uas.platform.b2b.support.UserCreater;
|
|
|
import com.uas.platform.core.model.Constant;
|
|
|
import com.uas.platform.core.util.AgentUtils;
|
|
|
+import com.uas.platform.core.util.encry.Md5Utils;
|
|
|
import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
import com.uas.sso.SSOHelper;
|
|
|
import com.uas.sso.SSOToken;
|
|
|
@@ -110,6 +113,8 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
user.setIp(AgentUtils.getIp(request));
|
|
|
request.getSession().setAttribute("user", user);
|
|
|
setGrantedAuthorities(user);
|
|
|
+ } else {
|
|
|
+ user = autoLogin(request);
|
|
|
}
|
|
|
}
|
|
|
if (user != null) {
|
|
|
@@ -298,4 +303,53 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
|
|
|
return SitePreference.NORMAL;
|
|
|
}
|
|
|
|
|
|
+ static final String TEL_REGEXP = "^((\\(\\d{3}\\))|(\\d{3}\\-))?(13|15|18)\\d{9}$";
|
|
|
+
|
|
|
+ static final String UU_REGEXP = "^\\d{4,}$";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 自动登录
|
|
|
+ *
|
|
|
+ * <pre>
|
|
|
+ * 旧方式
|
|
|
+ * </pre>
|
|
|
+ */
|
|
|
+ @Deprecated
|
|
|
+ private User autoLogin(HttpServletRequest request) {
|
|
|
+ String enUU = request.getParameter("b_enuu");
|
|
|
+ String username = request.getParameter("b_username");
|
|
|
+ String password = request.getParameter("b_password");
|
|
|
+ User user = null;
|
|
|
+ if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
|
|
|
+ if (username.contains("@")) { // 邮箱登录
|
|
|
+ user = userService.findUserByUserEmail(username);
|
|
|
+ } else if (username.matches(TEL_REGEXP)) {// 手机号登录
|
|
|
+ user = userService.findUserByUserTel(username);
|
|
|
+ } else if (username.matches(UU_REGEXP)) {
|
|
|
+ user = userService.findUserByUserUU(Long.parseLong(username));
|
|
|
+ }
|
|
|
+ if (user != null && user.getUserPwd().equals(Md5Utils.encode(password, user.getUserUU()))) {
|
|
|
+ checkEnterprise(user, enUU);
|
|
|
+ user.setIp(AgentUtils.getIp(request));
|
|
|
+ request.getSession().setAttribute("user", user);
|
|
|
+ setGrantedAuthorities(user);
|
|
|
+ } else
|
|
|
+ throw new UsernameNotFoundException(username + " 账号或密码错误");
|
|
|
+ }
|
|
|
+ return user;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void checkEnterprise(User user, String enUU) {
|
|
|
+ boolean choosed = false;
|
|
|
+ for (Enterprise enterprise : user.getEnterprises()) {
|
|
|
+ if (enterprise.getUu().toString().equals(enUU)) {
|
|
|
+ user.setEnterprise(enterprise);
|
|
|
+ choosed = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!choosed)
|
|
|
+ throw new UsernameNotFoundException("企业与用户不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
}
|