配置FR作为CAS客户端

编辑
文档创建者:文档助手1 (67727 )     浏览次数:9185次     编辑次数:27次     最近更新:ukae 于 2018-07-02     

目录:

1. 概述编辑

制作完上述步骤后,下面我们来看下如何将FR与CAS单点登录结合。

2. 实现过程编辑

2.1 拷贝jar
将cas两个client-jar包拷贝到%TOMCAT_HOME%\webapps\WebReport\WEB-INF\lib下,如下图:

222


2.2 修改web.xml
首先打开%TOMCAT_HOME%\webapps\WebReport\WEB-INF下的web.xml文件,
找到以下代码
<servlet> <servlet-name>ReportServer</servlet-name> <servlet-class>com.fr.web.ReportServlet</servlet-class> <load-on-startup>0</load-on-startup>
在上面加入如下过滤条件:
<filter> <filter-name>CASFilter</filter-name> <filter-class>edu.yale.its.tp.cas.client.filter.CASFilter</filter-class> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.loginUrl</param-name> <param-value>https://suise:8443/cas/login</param-value> <!--cas提供登陆页面的url--> </init-param> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.validateUrl</param-name> <param-value>https://suise:8443/cas/proxyValidate</param-value> <!--cas提供service ticker或者proxy ticket验证服务的url--> </init-param> <init-param> <param-name>edu.yale.its.tp.cas.client.filter.serverName</param-name> <param-value>suise:8443</param-value> <!--客户端应用的域名和端口--> </init-param> </filter> <filter-mapping> <filter-name>CASFilter</filter-name> <url-pattern>/ReportServer</url-pattern> </filter-mapping>

222

若报表应用设置了权限,则需要将如下java代码:
package com.fr; import com.fr.base.FRContext; import com.fr.fs.base.entity.User; import com.fr.fs.base.entity.UserInfo; import com.fr.fs.control.UserControl; import com.fr.fs.privilege.auth.FSAuthentication; import com.fr.fs.privilege.base.FServicePrivilegeLoader; import com.fr.fs.privilege.entity.DaoFSAuthentication; import com.fr.privilege.session.PrivilegeInfoSessionMananger; import org.jasig.cas.client.validation.Assertion; import javax.servlet.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; public class FrFilter implements Filter { public FrFilter() { } public void doFilter(ServletRequest req, ServletResponse res, FilterChain filterChain) throws IOException, ServletException { HttpServletRequest re = (HttpServletRequest) req; HttpServletResponse resp = (HttpServletResponse) res; HttpSession session = re.getSession(true); String username; String userpass = ""; Object object = re.getSession().getAttribute("_const_cas_assertion_"); if (object != null) { Assertion assertion = (Assertion) object; username = assertion.getPrincipal().getName(); } else { username = (String) session.getAttribute("edu.yale.its.tp.cas.client.filter.user"); if (username == null || "".equals(username)) { resp.sendRedirect("http://www.baidu.com"); //如果用户名为空跳转到百度 } } try { User user1 = UserControl.getInstance().getByUserName(username); if (user1 != null && session.getAttribute("fr_fs_auth_key") == null) { //如果用户名在fs的用户列表里则做登陆操作 FSAuthentication authentication = new DaoFSAuthentication(new UserInfo(user1.getId(), user1.getUsername(), user1.getPassword())); long userid = authentication.getUserInfo().getId(); PrivilegeInfoSessionMananger.login(new FServicePrivilegeLoader(username, UserControl.getInstance().getAllSRoleNames(userid), UserControl.getInstance().getUserDP(userid)), session, resp); authentication.setAuthenticated(true); session.setAttribute("fr_fs_auth_key", authentication); UserControl.getInstance().login(userid); System.out.println("fr FrFilter is over with username is -" + username + "- and userpass is -" + userpass + "-"); FRContext.getLogger().error("fr FrFilter is over with username is ###" + username + "### and userpass is ###" + userpass + "###"); filterChain.doFilter(req, res); } else if (user1 != null & session.getAttribute("fr_fs_auth_key") != null) { filterChain.doFilter(req, res); FRContext.getLogger().error("no need"); } else { resp.sendRedirect("http://www.hao123.com"); //如果用户名不在fs的用户列表里则跳转hao123 } } catch (Exception var14) { var14.printStackTrace(); } } public void init(FilterConfig filterconfig) throws ServletException { } public void destroy() { } }

FrFilter.java编译成class文件,并放在%TOMCAT_HOME%\WebReport\WEB-INF\classes\com\fr目录下。

点击下载FrFilter.class
222

然后在web.xml文件中增加如下代码:

<filter> <filter-name>FrFilter</filter-name> <filter-class>com.fr.FrFilter</filter-class> </filter> <filter-mapping> <filter-name>FrFilter</filter-name> <url-pattern>/ReportServer</url-pattern> </filter-mapping>  
222

2.3 测试

最后启动tomcat服务器,在浏览器中输入:https://localhost:8443/WebReport/ReportServer?op=fs即进入了cas登录界面,通过cas认证后,FRFilter会看用户名是否在fs的用户中,如果在,则登录成功,否则登录失败跳转hao123,如下图:

222



附件列表


主题: 部署集成
如果您认为本文档还有待完善,请编辑

文档内容仅供参考,如果你需要获取更多帮助,付费/准付费客户请咨询帆软技术支持
关于技术问题,您还可以前往帆软社区,点击顶部搜索框旁边的提问按钮
若您还有其他非技术类问题,可以联系帆软传说哥(qq:1745114201

此页面有帮助吗?