cas_client之代理配置
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cas_client之代理配置相关的知识,希望对你有一定的参考价值。
本环境基于cas3.4.2进行配置,3个tomcat环境:单点登录tomcat、代理tomcat和被代理tomcat。目的是通过代理app1访问被代理app2,此配置完全根据源代码分析而来(因此基础好的直接读源代码研究更好)。
1、单点登录tomcat发布配置,网上有很多资料,不在赘述。
2、代理app配置:网上有说
AuthenticationFilter和Cas20ProxyReceivingTicketValidationFilter2个过滤器顺序需要调换,其实是错误的,把握好以下红色字体足以。 proxyCallback网上介绍的很草率,这里只需要在代理端新建一个servlet作为代理url即可,内部逻辑什么都不用做。
CAS Authentication Filter org.jasig.cas.client.authentication.AuthenticationFilter casServerLoginUrl http://127.0.0.1:8081/tjsso/login serverName http://127.0.0.1:8080 CAS Validation Filter org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter casServerUrlPrefix http://127.0.0.1:8081/tjsso serverName http://127.0.0.1:8080 useSession true redirectAfterValidation true CAS HttpServletRequest Wrapper Filter org.jasig.cas.client.util.HttpServletRequestWrapperFilter CAS Assertion Thread Local Filter org.jasig.cas.client.util.AssertionThreadLocalFilter CAS Authentication Filter /* CAS Validation Filter /* CAS HttpServletRequest Wrapper Filter /* CAS Assertion Thread Local Filter /* casProxyTest com.supermap.proxy.CasProxyTestServlet casProxyTest /casProxyTest
3、被代理app配置:
CAS Authentication Filter org.jasig.cas.client.authentication.AuthenticationFilter casServerLoginUrl http://127.0.0.1:8081/tjsso/login serverName http://127.0.0.1:8080 CAS Validation Filter org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter casServerUrlPrefix http://127.0.0.1:8081/tjsso serverName http://127.0.0.1:8080 useSession true redirectAfterValidation true CAS HttpServletRequest Wrapper Filter org.jasig.cas.client.util.HttpServletRequestWrapperFilter CAS Assertion Thread Local Filter org.jasig.cas.client.util.AssertionThreadLocalFilter CAS Authentication Filter /* CAS Validation Filter /* CAS HttpServletRequest Wrapper Filter /* CAS Assertion Thread Local Filter /*
4、实例验证,在代理端新建一个servlet,我这里就是上述配置的
casProxyTest
源码如下:
com.supermap.proxy; org.jasig.cas.client.authentication.AttributePrincipal; org.jasig.cas.client.util.AssertionHolder; javax.servlet.ServletException; javax.servlet.http.HttpServlet; javax.servlet.http.HttpServletRequest; javax.servlet.http.HttpServletResponse; java.io.BufferedReader; java.io.IOException; java.io.InputStreamReader; java.io.OutputStream; java.net.HttpURLConnection; java.net.URL; java.net.URLEncoder; CasProxyTestServlet HttpServlet { doGet(HttpServletRequest req, HttpServletResponse resp) ServletException, IOException { (req, resp); } (HttpServletRequest req, HttpServletResponse resp) ServletException, IOException { AttributePrincipal principal = AssertionHolder.().getPrincipal(); String proxyTicket = principal.getProxyTicketFor(); URL url = URL(+ URLEncoder.(proxyTicket, )); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setDoOutput(); conn.setDoInput(); OutputStream out = conn.getOutputStream(); out.write((+URLEncoder.(proxyTicket, )).getBytes()); out.flush(); out.close(); BufferedReader br = BufferedReader(InputStreamReader(conn.getInputStream(), )); StringBuffer content = StringBuffer(); String line = ; ((line=br.readLine()) != ) { content.append(line).append(); } resp.getWriter().write(content.toString()); } }
总结:其中的原理在网上有很多资料介绍,最主要还是需要个人去研读源代码,把握核心。
本文出自 “12664863” 博客,请务必保留此出处http://12674863.blog.51cto.com/12664863/1904900
以上是关于cas_client之代理配置的主要内容,如果未能解决你的问题,请参考以下文章
cas_client之AuthenticationFilter源码分析