Windchill 单点登录配置
为了适用现代企业的系统整合适用,很多企业会使用SSO单点登陆,统一管理企业用户。在此背景下,基于windchill的认证重构,实现单点登陆,借此文章与大家分享。此次使用的认证系统是windchill 10.2, 实现方式在windchill11 同样适用,但是不同版本适用的拦截认证信息会出现不同,需要进行不同的测试。
- 此方案经过的测试包括 shell 命令行、core、wgm工具端认证、后台应用访问。
如果需要实现自定义登陆也可以参考此方案。增加认证 ,进行用户注册等。
备份文件
<apache_home>/conf/extra/app-Windchill-AJP.conf
<apache_home>/conf/extra/app-Windchill-Auth.conf
<apache_home>/conf/extra/app-Windchill-AuthProvider.xml
<apache_home>/conf/extra/app-Windchill-AuthRes.xml
<apache_home>/conf/extra/webAppAJPConf.template
1.配置web.xml拦截器,对所有的请求进行拦截。filter需要配置在web.xml 第一个filter位置
<filter>
<description>LoginFilter use User login Authentication for thrid System </description>
<filter-name>LoginFilter</filter-name>
<filter-class>com.kwafoo.login.LoginFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>LoginFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
- 需要配置Apache的认证拦截,取消掉默认的Apache认证拦截。
默认Apache会拦截/Windchill
下所有的连接。
1. 禁用 </windchill> 拦截,修改 HTTPServer\conf\extra\app-Windchill-Auth.conf
#<LocationMatch ^/+Windchill/+(;.*)?>
#AuthzLDAPAuthoritative off
#AuthName "Windchill"
#AuthType Basic
#AuthBasicProvider Windchill-AdministrativeLdap Windchill-EnterpriseLdap
#require valid-user
#</LocationMatch>
当禁用此配置后,Windchill所有初始认证会消失,导致request中没有用户,所有后续进入到filter会报错,
所有需要将LoginFilter放在第一个位置
AuthzLDAPAuthoritative off
AuthName "Windchill"
AuthType Basic
AuthBasicProvider Windchill-AdministrativeLdap Windchill-EnterpriseLdap
require valid-user
如上配置说明请求被认证拦截,所以在filter中针对如上的配置都需要增加用户拦截,进行用户信息注入
进入 Windchill/HttpServer目录下 执行命令
ant -f webAppConfig.xml regenWebAppConf
4 代码增加系统全局拦截器filter
String isFilter = (String) session.getAttribute("isFilter");
String username = request.getRemoteUser();
if(isWhiteURL(url,whiteListURLs) || StringUtils.isNotBlank(username)){
filterchain.doFilter(request, response);
}else if(url.contains("CAlogin/checkUser")){ //特殊情况,预登陆查询用户是否存在
RequestWrap newRequest = new RequestWrap(
request);
newRequest.setRemoteUser("wcadmin");
filterchain.doFilter(newRequest, response);
return;
}else if(isIncludeUrl(specalUrl, url)){ //处理执行windchill一些命令报错, 目前测试情况不需要单独配置命令
RequestWrap newRequest = new RequestWrap(
request);
newRequest.setRemoteUser("wcadmin");
filterchain.doFilter(newRequest, response);
return;
}
else{
//系统认证登陆
//如果是通过后台登陆的,则获取Authorization,解析之后再重构request
//如果不是通过后台登陆的,则需要校验是否有认证信息,如果有
if("false".equals(isFilter)){
RequestWrap newRequest = new RequestWrap(
request);
newRequest.addHeader("Authorization", (String)session.getAttribute("auth"));
String[] usernamepsw = converAuthHeader((String)session.getAttribute("auth"));
newRequest.setRemoteUser(usernamepsw[0]);
filterchain.doFilter(newRequest, response);
return;
}
//登陆之后会将用户名称存在session中,如果session中有用户,则模拟登陆
String sessionUser = (String) session.getAttribute("username");
if (StringUtils.isNotBlank(sessionUser)){
String encodeUserInfo = BASE64Encoder
.encode((sessionUser + ":"+salt).getBytes());
RequestWrap newRequest = new RequestWrap(
request);
newRequest.addHeader("Authorization", "Basic "
+ encodeUserInfo);
newRequest.setRemoteUser(sessionUser);
filterchain.doFilter(newRequest, response);
return;
}else{
//如果没有则跳转到登陆页面
response.sendRedirect("/Windchill/netmarkets/login/login.jsp" + "?redirectURL="
+ URLEncoder.encode(url,"utf-8"));
return;
}
}
5 白名单配置
SpacalURL=Windchill/servlet/WindchillAuthGW/wt.httpgw.HTTPAuthentication/login
whiteListURL=.*Windchill/wtcore/getWtProperties.jsp;;;qqq.*Windchill/netmarkets/register/.+;;;qqq.*Windchill/+infoengine/+verifyCredentials.html;;;qqq.*Windchill/+protocolAuth/.+;;;qqq.*/Windchill/servlet/WindchillGW/.+;;;qqq.*/Windchill/servlet/ProwtGW.*;;;qqq.*/Windchill/servlet/InterSiteJmxProxy.*;;;qqq.*/Windchill/servlet/JNLPGeneratorServlet.*;;;qqq.*/Windchill/servlet/XML4Cognos.*;;;qqq.*/Windchill/wt.properties;;;qqq.*/netmarkets/login/login.jsp;;;qqq
6 认证时序图