Browse Source

Merge branch 'hotfix-personalUser-suntg' into dev

suntg 6 years ago
parent
commit
6baf556a64

+ 64 - 0
src/main/java/com/uas/platform/b2b/filter/B2bAbstractSSOInterceptor.java

@@ -0,0 +1,64 @@
+package com.uas.platform.b2b.filter;
+
+import com.uas.sso.SSOHelper;
+import com.uas.sso.SSOToken;
+import java.io.IOException;
+import java.util.logging.Logger;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import com.uas.sso.web.spring.AbstractSSOInterceptor;
+import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
+
+/**
+ * B2B 自定义的SSO拦截器
+ */
+public abstract class B2bAbstractSSOInterceptor extends HandlerInterceptorAdapter {
+    private static final Logger logger = Logger.getLogger(AbstractSSOInterceptor.class.getName());
+
+    public B2bAbstractSSOInterceptor() {
+    }
+
+    protected abstract boolean onAuthenticateFailed(HttpServletRequest var1, HttpServletResponse var2);
+
+    protected abstract boolean onAuthenticateSuccess(HttpServletRequest var1, HttpServletResponse var2);
+
+    protected void sendRedirect(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        boolean cross = SSOHelper.isCrossDomain(request);
+        if (cross) {
+            request.getSession().setAttribute("SSOReferer", request.getRequestURL());
+            response.sendRedirect(SSOHelper.getSSOService().getConfig().getCrossProxyUri());
+        } else {
+            SSOHelper.clearRedirectLogin(request, response);
+        }
+
+    }
+
+    private final boolean authenticate(HttpServletRequest request, HttpServletResponse response) throws IOException {
+        SSOToken token = (SSOToken)SSOHelper.getToken(request);
+        if (token == null) {
+            if (!this.onAuthenticateFailed(request, response)) {
+                if (this.isRedirectAble(request)) {
+                    logger.fine("logout. request url:" + request.getRequestURL());
+                    this.sendRedirect(request, response);
+                }
+
+                return false;
+            } else {
+                return true;
+            }
+        } else {
+            request.setAttribute("SSOTokenAttr", token);
+            return this.onAuthenticateSuccess(request, response);
+        }
+    }
+
+    @Override
+    public final boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
+        return super.preHandle(request, response, handler) ? this.authenticate(request, response) : false;
+    }
+
+    protected boolean isRedirectAble(HttpServletRequest request) {
+        return null == request.getHeader("x-requested-with") && (null == request.getHeader("Accept") || !request.getHeader("Accept").contains("application/json"));
+    }
+}

+ 30 - 10
src/main/java/com/uas/platform/b2b/filter/SSOInterceptor.java

@@ -67,7 +67,7 @@ import java.util.stream.Collectors;
  * @date 2018-07-18 19:21
  */
 @SuppressWarnings("deprecation")
-public class SSOInterceptor extends AbstractSSOInterceptor {
+public class SSOInterceptor extends B2bAbstractSSOInterceptor {
 
 	private static final Logger logger = LoggerFactory.getLogger(SSOInterceptor.class);
 
@@ -175,7 +175,15 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
 			}
 		}
 		if (user != null) {
-            checkIsPersonal(user);
+        	// 个人用户,跳转至提示页面
+            if (checkIsPersonal(user)) {
+				try {
+					response.sendRedirect("/error_personal");
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				return false;
+			}
             // 登录之前判断在当前企业的角色信息
             if (null != user.getEnterprise() && user.getEnterprise().getEnAdminuu().equals(user.getUserUU())) {
                 Enterprise enterprise = user.getEnterprise();
@@ -294,7 +302,7 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
      * @param response response
      */
 	@Override
-	protected void onAuthenticateSuccess(HttpServletRequest request, HttpServletResponse response) {
+	protected boolean onAuthenticateSuccess(HttpServletRequest request, HttpServletResponse response) {
 		User user = (User) request.getSession().getAttribute("user");
 		SSOToken token = SSOHelper.attrToken(request);
 		// cookie变化的情况下,session可能还未变化
@@ -312,7 +320,13 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
 			if (token.getData() != null) {
 				UserAccount tokenUser = FlexJsonUtils.fromJson(token.getData(), UserAccount.class);
 				if (StringUtils.isEmpty(tokenUser.getBusinessCode()) || StringUtils.isEmpty(tokenUser.getSpaceUU())) {
-                    throw new IllegalAccessError("个人用户无法使用B2B商务平台");
+					// 如果个人用户跳转至提示页面
+					try {
+						response.sendRedirect("/error_personal");
+					} catch (IOException e) {
+						e.printStackTrace();
+					}
+					return false;
                 }
 				// 如果是从个人用户切换或者当前企业切换
 				boolean flag = null == user.getEnterprise() || !user.getEnterprise().getUu().equals(tokenUser.getSpaceUU());
@@ -324,8 +338,15 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
 			}
 		}
 		if (user != null) {
-		    // 判断是否个人用户
-            checkIsPersonal(user);
+		    // 判断是否个人用户,如果个人用户跳转至提示页面
+            if (checkIsPersonal(user)) {
+				try {
+					response.sendRedirect("/error_personal");
+				} catch (IOException e) {
+					e.printStackTrace();
+				}
+				return false;
+			}
             // 登录之前判断在当前企业的角色信息
             if (null != user.getEnterprise() && user.getEnterprise().getEnAdminuu().equals(user.getUserUU())) {
                 Enterprise enterprise = user.getEnterprise();
@@ -340,6 +361,7 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
 				e.printStackTrace();
 			}
 		}
+		return true;
 	}
 
 	/**
@@ -371,11 +393,9 @@ public class SSOInterceptor extends AbstractSSOInterceptor {
      *
      * @param user 用户信息
      */
-    private void checkIsPersonal(User user) {
+    private boolean checkIsPersonal(User user) {
 	    boolean personalAccount = null == user.getEnterprise() || (null != user.getEnterprise() && null == user.getEnterprise().getUu());
-	    if (personalAccount) {
-            throw new IllegalAccessError("个人用户无法使用B2B商务平台");
-        }
+	    return personalAccount;
     }
 
     /**

+ 12 - 0
src/main/java/com/uas/platform/b2b/openapi/controller/CustDataController.java

@@ -79,6 +79,8 @@ public class CustDataController {
 		if (brands == null) {
             throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
         }
+        return new ArrayList<CustData<Stock>>();
+		/* 应客户要求,接口不返回数据,2019-2-19 09:24:33,suntg
 		return iteratorCustTasks(custId, new ICallable<CustData<Stock>, Vendor>() {
 
 			@Override
@@ -87,6 +89,7 @@ public class CustDataController {
 			}
 
 		});
+		*/
 	}
 
 	/**
@@ -112,6 +115,8 @@ public class CustDataController {
 		if (brands == null) {
             throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
         }
+        return new ArrayList<CustData<Sale>>();
+		/* 应客户要求,接口不返回数据,2019-2-19 09:24:33,suntg
 		// 起始日期为空则取当月第一天
 		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
 		return iteratorCustTasks(custId, new ICallable<CustData<Sale>, Vendor>() {
@@ -122,6 +127,7 @@ public class CustDataController {
 			}
 
 		});
+		*/
 	}
 
 	/**
@@ -147,6 +153,8 @@ public class CustDataController {
 		if (brands == null) {
             throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
         }
+		return new ArrayList<CustData<IO>>();
+		/* 应客户要求,接口不返回数据,2019-2-19 09:24:33,suntg
 		// 起始日期为空则取当月第一天
 		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
 		return iteratorCustTasks(custId, new ICallable<CustData<IO>, Vendor>() {
@@ -157,6 +165,7 @@ public class CustDataController {
 			}
 
 		});
+		*/
 	}
 
 	/**
@@ -182,6 +191,8 @@ public class CustDataController {
 		if (brands == null) {
             throw new SystemError(ErrorUtils.NO_BRAND_FOUND);
         }
+		return new ArrayList<CustData<Forecast>>();
+		/* 应客户要求,接口不返回数据,2019-2-19 09:24:33,suntg
 		// 起始日期为空则取当月第一天
 		final String _startDate = startDate == null ? DateUtils.getMinMonthDateS(new Date()) : startDate;
 		return iteratorCustTasks(custId, new ICallable<CustData<Forecast>, Vendor>() {
@@ -192,6 +203,7 @@ public class CustDataController {
 			}
 
 		});
+		*/
 	}
 
 	/**

+ 2 - 0
src/main/webapp/WEB-INF/spring/webmvc.xml

@@ -68,6 +68,7 @@
 	<mvc:view-controller path="/authen" view-name="authen" />
 	<mvc:view-controller path="/login/proxy" view-name="proxyLogin" />
 	<mvc:view-controller path="/logout/proxy" view-name="proxyLogout" />
+	<mvc:view-controller path="/error_personal" view-name="error_personal" />
 	<mvc:interceptors>
 		<mvc:interceptor>
 			<mvc:mapping path="/**"></mvc:mapping>
@@ -92,6 +93,7 @@
 			<mvc:exclude-mapping path="/openapi/api/trade/**" />
 			<mvc:exclude-mapping path="/openapi/usoft/**" />
 			<mvc:exclude-mapping path="/erp/listen" />
+			<mvc:exclude-mapping path="/error_personal" />
 			<bean class="com.uas.platform.b2b.filter.SSOInterceptor"></bean>
 		</mvc:interceptor>
 		<!-- 对所有的请求拦截,将Session中的User信息设置进SystemSession -->

+ 126 - 0
src/main/webapp/WEB-INF/views/normal/error_personal.html

@@ -0,0 +1,126 @@
+<!DOCTYPE HTML>
+<html lang="zh-CN">
+<head>
+<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+<meta name="renderer" content="webkit">
+<meta name="baidu-site-verification" content="S0kf5fz0uA" />
+<meta charset="utf-8">
+<title>B2B商务</title>
+<meta name="keywords"
+	content="B2B商务,优软商务,优软B2B平台,商务平台,B2B平台,B2B,电子商务,ERP,UAS,UBTOB.COM,USOFTCHINA.COM,优软,优软科技,深圳市优软科技有限公司">
+<meta name="description" content="B2B商务,企业供销信息交流平台。">
+<link href="static/img/icon/u.png" rel="icon" type="image/x-icon" />
+<link rel="stylesheet" href="static/lib/bootstrap/css/bootstrap.min.css" />
+<link rel="stylesheet"
+	href="static/lib/fontawesome/css/font-awesome.min.css" />
+<link rel="stylesheet" href="static/lib/angular/toaster.css" />
+<link rel="stylesheet" href="static/lib/treeview/css/angular.treeview.css" />
+<link rel="stylesheet" href="static/css/index.css" />
+</head>
+<body ng-controller="AuthCtrl">
+<div class="header-action">
+	<!-- header Start -->
+		<!--header 顶部头-->
+		<div>
+			<nav id="site-nav">
+				<ul class="ghost-center">
+					<li class="uas-cloud">
+						<a href="https://www.usoftchina.com/" target="_blank">
+							<img src="static/img/all/logo_uas.png"/>
+							<span>进入优软云</span>
+						</a>
+					</li>
+					<li><a href="https://mall.usoftchina.com">商城首页</a></li>
+					<li><a href="https://mall.usoftchina.com/help/home" target="_black">帮助中心</a></li>
+				</ul>
+			</nav>
+		</div>
+		<!--header 2-->
+	    <div ng-include src="'static/tpl/index/common/header.html'"></div>
+	</div>
+	<!-- header End -->
+	<!-- body Start -->
+	<div class="body">
+		<div class="container">
+			<h1 class="text-center" style="margin-top: 150px; margin-bottom: 100px;">个人用户无法使用B2B商务平台,请使用企业账号登录,或返回<a
+					href="https://mall.usoftchina.com">商城首页</a>!</h1>
+		</div>
+	</div>
+	<!-- body End -->
+
+
+<!-- footer Start -->
+<div id="footer">
+		<ul class="footer-main list-unstyled">
+			<li>
+				<h3>用户指南</h3>
+				<ul class="list-unstyled">
+					<li><a href="http://mall.usoftchina.com/help#/issue/50" target="_blank">服务条款</a></li>
+					<li><a href="http://mall.usoftchina.com/help#/issue/16" target="_blank">买卖条例</a></li>
+					<li><a href="http://mall.usoftchina.com/help#/issue/51" target="_blank">代收代付协议</a></li>
+				</ul>
+			</li>
+			<!--<li>
+                <h3>技术支持</h3>
+                <ul class="list-unstyled">
+                    <li>原理图</li>
+                    <li>设计方案</li>
+                    <li>BOM清单</li>
+                </ul>
+            </li>-->
+			<li>
+				<h3>关于我们</h3>
+				<ul class="list-unstyled">
+					<li><a href="http://mall.usoftchina.com/help#/issue/1" target="_blank">公司简介</a></li>
+					<li><a href="http://mall.usoftchina.com/help#/issue/28" target="_blank">公司地址</a></li>
+					<li><a href="http://mall.usoftchina.com/help#/issue/1" target="_blank">联系我们</a></li>
+				</ul>
+			</li>
+			<li>
+				<h3>更多服务</h3>
+				<ul class="list-unstyled">
+					<li><a href="http://uas.usoftchina.com"  target="_blank" target="_blank">优软科技</a></li>
+					<li><a href="http://www.usoftchina.com/" target="_blank" target="_blank">优软云</a></li>
+				</ul>
+			</li>
+			<li>
+				<h3>商城公众号</h3>
+				<img src="static/img/footer/qrcode_mall.png" />
+			</li>
+			<li>
+				<h3>科技公众号</h3>
+				<img src="static/img/footer/qrcode_uas.png" />
+			</li>
+		</ul>
+		<div class="friend-link row">
+			<span>友情链接:</span>
+			<a href="http://www.worldshine.net" target="_blank" title="深圳华商龙">深圳华商龙</a>|
+			<a href="http://www.yitoa.com" target="_blank" title="深圳市英唐智能科技">深圳市英唐智能科技</a>|
+			<a href="http://uas.usoftchina.com" target="_blank" title="深圳市优软科技">深圳市优软科技</a>|
+			<a href="http://www.fantem.com" target="_blank" title="丰唐物联技术(深圳)">丰唐物联技术(深圳)</a>|
+			<a href="http://www.hiways.com" target="_blank" title="深圳市海威思科技">深圳市海威思科技</a>|
+			<a href="http://www.huashangweitai.com" target="_blank" title="深圳市华商维泰显示科技">深圳市华商维泰显示科技</a>|
+			<a href="http://www.ufct.com.cn/" target="_blank" title="联合创泰科技">联合创泰科技</a>|
+			<a href="http://www.hi-mantech.com/" target="_blank" title="怡海能达">怡海能达</a>
+		</div>
+		<ul class="list-unstyled footer-bottom">
+			<li>客服电话:400-830-1818</li>
+			<li>公司地址:深圳市南山区英唐大厦一楼</li>
+			<li>©2016 深圳市优软科技有限公司 粤ICP备15112126号-4</li>
+		</ul>
+		<div class="credit">
+			<a href="javascript:void(0)"><img src="static/img/footer/credit01.jpg" /></a>
+			<a href="javascript:void(0)"><img src="static/img/footer/credit02.jpg" /></a>
+			<a href="javascript:void(0)"><img src="static/img/footer/credit03.jpg" /></a>
+			<a href="javascript:void(0)"><img src="static/img/footer/credit04.jpg" /></a>
+			<a href="javascript:void(0)"><img src="static/img/footer/credit05.jpg" /></a>
+		</div>
+	</div>
+<!-- footer End -->
+
+<script src="static/lib/jquery/jquery.min.js"></script>
+<!--<script src="static/lib/treeview/js/angular.treeview.min.js"></script>-->
+<script src="static/lib/bootstrap/js/bootstrap.js"></script>
+
+</body>
+</html>