|
|
@@ -36,6 +36,7 @@ import org.springframework.security.web.context.HttpSessionSecurityContextReposi
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
+import com.uas.platform.b2b.model.Enterprise;
|
|
|
import com.uas.platform.b2b.model.ResourceItem;
|
|
|
import com.uas.platform.b2b.model.Role;
|
|
|
import com.uas.platform.b2b.model.SigninLog;
|
|
|
@@ -221,6 +222,7 @@ public class SecurityInterceptor extends AbstractSecurityInterceptor implements
|
|
|
* 自动登录
|
|
|
*/
|
|
|
private void autoLogin(HttpServletRequest request) {
|
|
|
+ String enUU = request.getParameter("b_enuu");
|
|
|
String username = request.getParameter("b_username");
|
|
|
String password = request.getParameter("b_password");
|
|
|
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
|
|
|
@@ -239,7 +241,10 @@ public class SecurityInterceptor extends AbstractSecurityInterceptor implements
|
|
|
SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
|
|
|
request.getSession().setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
|
|
|
SecurityContextHolder.getContext());
|
|
|
- user.setCurrentEnterprise();
|
|
|
+ if (enUU != null)
|
|
|
+ checkEnterprise(user, enUU);
|
|
|
+ else
|
|
|
+ user.setCurrentEnterprise();
|
|
|
user.setIp(AgentUtils.getIp(request));
|
|
|
request.getSession().setAttribute("user", user);
|
|
|
} else
|
|
|
@@ -247,6 +252,19 @@ public class SecurityInterceptor extends AbstractSecurityInterceptor implements
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ 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("企业与用户不匹配");
|
|
|
+ }
|
|
|
+
|
|
|
private Set<GrantedAuthority> getGrantedAuthorities(User user) {
|
|
|
Set<GrantedAuthority> authSet = new HashSet<GrantedAuthority>();
|
|
|
Set<Role> roles = user.getRoles();
|