一、实记前言 各位看官你们好,经过上一篇我的文章通篇的介绍以及铺垫,我相信您已经大概的知道了我们的应用场景了。下面继续介绍发现问题的过程以及如何解决我们遇到的问题
一、实记前言
各位看官你们好,经过上一篇我的文章通篇的介绍以及铺垫,我相信您已经大概的知道了我们的应用场景了。下面继续介绍发现问题的过程以及如何解决我们遇到的问题。 先上一张图,让大家了解一下各个系统的情况。

二、开发以及内测环境问题赘述
(一)开发环境
(二)内测环境
三、 开发以及内测环境遇到的问题解决方案(从此处开始上干货!!!!!!!)
因为起初iframe采用的是http协议请求我们的系统。也就是在决定采取https协议之前。
从此处开始着重挨个说明开发环境遇到的问题以及表现出的现象,以及对应的解决办法。还有内测环境遇到的问题以及表现出的还有对应的解决办法。
开发环境如下:
A系统页面代码(此处只是为了演示,真正的页面比下面展示的要复杂,而且采用的是动态的赋值给iframe 的src属性)
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
</head>
<body class="" style="height: 700px;width: 1150px" >
<div align="center" style="height: 600px;width: 1000px" >
<iframe id="testPage" align="center" style="height: 500px;width: 850px"
src="http://192.168.0.166:18080/accident/transmission/handle?devId=11111&bayId=22222&stId=33333&from=robot" about="about:blank" >
</iframe>
</div>
<th:block th:include="include :: footer" />
<script type="text/javascript">
</script>
</body>
</html>
复制代码
nginx配置如下:
events {worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
underscores_in_headers on;
server {
listen 18080;
server_name cyber.com;
location / {
root E:/WORKSPACE-DY/CyberMonitor-ui/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/ {
proxy_set_header NGINX-REQEST-URL $host:$server_port/prod-api;
proxy_set_header Host $host:$server_port;
add_header Access-Control-Allow-Origin * always;
add_header Access-Control-Allow-Credentials true;
proxy_pass http://192.168.0.166:21080/;
}
}
}
复制代码
Vue前端打包配置如下:
ENV = 'production'VUE_APP_BASE_API = '/prod-api/'
VUE_APP_BASE_LOGIN_API = '/prod-api/'
复制代码
(一)、开发环境遇到问题(用的是谷哥99版本浏览器,谷哥79版本浏览器,Edge99版本浏览器)
- 1:集成cas单点登录 遇到casClient相关的jar包不加载
问题原因:SpringBoot启动类未添加对应的casClient相关jar包的扫描路径配置:
如下代码配置则导致容器扫描不到casClient的jar包
exclude = { DataSourceAutoConfiguration.class })
public class CyberApplication {
public static void main(String[] args) {
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(CyberApplication.class, args);
}
}
复制代码
对应的应该修改为下面的配置,com 是casClient jar包最外层的包名
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class },
scanBasePackages = {"com"})
public class CyberApplication {
public static void main(String[] args) {
// System.setProperty("spring.devtools.restart.enabled", "false");
SpringApplication.run(CyberApplication.class, args);
}
}
//因为我们引入的cas是p平台团队修改过的,所以cas客户端的源码跟网络上开源的有稍微的区别
复制代码
- 2. cas客户端的jar包加载了但是casClient客户端拦截不到用户的请求
该问题的原因如下,是因为我们采用的开源框架本身是为了前后端分离的方式量身定制的,有一定的局限性。但是p平台团队之前研发的单点登录系统虽然有微服务版本的,也支持SpringBoot,但是因为我们的开源框架请求头没有包含 X-Requested-With 这个请求头,但是casClient过滤器需要这个请求头进行逻辑判断,所以导致casClient过滤器无法拦截我们的请求。casClient部分源码如下:因为他是首先通过获取请求头中的X-Requested-With这个变量,然后继续后面的过滤操作。
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {HttpServletRequest request = (HttpServletRequest)servletRequest;
HttpServletResponse response = (HttpServletResponse)servletResponse;
String requestX = request.getHeader("X-Requested-With");
if (!"XMLHttpRequest".equalsIgnoreCase(requestX)) {
String queryStr = request.getQueryString();
String url = request.getRequestURL().toString();
if (url.contains("?")) {
url = url.substring(0, url.indexOf("?"));
}
int tmep = url.indexOf(";jsessionid=");
if (tmep > 0) {
url = url.substring(0, tmep);
if (!Util.isEmpty(queryStr)) {
response.sendRedirect(url + "?" + queryStr);
} else {
response.sendRedirect(url);
}
return;
}
if (Util.isExcludePage(url)) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
HttpSession session = request.getSession(false);
if (session != null && session.getAttribute("ssoWhiteURL") != null) {
List<String> list = (List)session.getAttribute("ssoWhiteURL");
if (list.contains(request.getRequestURI())) {
filterChain.doFilter(servletRequest, servletResponse);
return;
}
}
if (!Util.isEmpty(queryStr)) {
int index = queryStr.lastIndexOf("WT=");
if (index >= 0) {
session = request.getSession();
if (session.getAttribute("ssoWhiteURL") == null) {
List<String> whiteURL = new ArrayList();
session.setAttribute("ssoWhiteURL", whiteURL);
}
((List)session.getAttribute("ssoWhiteURL")).add(request.getRequestURI());
if (index == 0) {
response.sendRedirect(url);
} else {
response.sendRedirect(url + "?" + queryStr.substring(0, index - 1));
}
return;
}
}
super.setCasServerLoginUrl(Util.findMatchingCasServerUrlPrefix(request) + "login");
super.doFilter(servletRequest, servletResponse, filterChain);
} else {
super.setCasServerLoginUrl(Util.findMatchingCasServerUrlPrefix(request) + "login");
super.doFilter(servletRequest, servletResponse, filterChain);
}
}
