cas server 端配置+2客户端配置

1  cas server 端配置

ticketGrantingTicketCookieGenerator.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<description>
Defines the cookie that stores the TicketGrantingTicket.  You most likely should never modify these (especially the "secure" property).
You can change the name if you want to make it harder for people to guess.
</description>
<bean id="ticketGrantingTicketCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false"
p:cookieMaxAge="6000"

p:cookieName="CASTGC"
p:cookiePath="/cas" />
</beans>



warnCookieGenerator.xml

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd">
<description>
This Spring Configuration file describes the cookie used to store the WARN parameter so that a user is warned whenever the CAS service
is used.  You would modify this if you wanted to change the cookie path or the name.
</description>

<bean id="warnCookieGenerator" class="org.jasig.cas.web.support.CookieRetrievingCookieGenerator"
p:cookieSecure="false"
p:cookieMaxAge="6000"

p:cookieName="CASPRIVACY"
p:cookiePath="/cas" />
</beans>

deployerConfigContext.xml

添加:bean

 <bean id="mysqlDataSource" class="org.apache.commons.dbcp.BasicDataSource">
     <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver" />
     <property name="url" value="jdbc:sqlserver://192.168.1.188:1433;DatabaseName=Performance_report"/>
     <property name="username" value="performance" />
     <property name="password" value="performance" />
</bean>


替换authenticationHandlers下面配置如下:

<property name="authenticationHandlers">
<list>
<bean class="org.jasig.cas.authentication.handler.support.HttpBasedServiceCredentialsAuthenticationHandler" p:httpClient-ref="httpClient" />
<!--注释掉默认的的认证实现<bean 
class="org.jasig.cas.authentication.handler.support.SimpleTestUsernamePasswordAuthenticationHandler" />-->
<!-- 数据库查询认证处理器 -->
<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler">
<property name="dataSource" ref="mysqlDataSource"/>
<property name="sql"  value=" select password from pl_user where name = ?" />
<!-- <property name="passwordEncoder">
  <bean class="org.jasig.cas.authentication.handler.DefaultPasswordEncoder">
<constructor-arg value="MD5"/>
  </bean>
</property>-->
</bean>
</list>
</property>

cas-server-support-jdbc-3.5.2.jar

sqljdbc4.jar  sqlserver驱动放到cas服务端项目lib下

commons-dbcp-1.2.2.jar

commons-collections-3.2.jar

commons-logging-1.1.jar


2  客户端配置-client-1


web.xml 添加


cas-client-core-3.2.0.jar

log4j-1.2.15.jar

commons-logging-1.1.jar






<!-- ???? -->
<listener>
<listener-class>
org.jasig.cas.client.session.SingleSignOutHttpSessionListener
</listener-class>
</listener>


<!-- ??????????????,????? -->


<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>
org.jasig.cas.client.session.SingleSignOutFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- cas登录认证服务,发放ticik -->
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>
org.jasig.cas.client.authentication.AuthenticationFilter
</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>
http://cas.demo.com:8080/cas/login
</param-value>
<!--app1客户端IP -->
</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://app1.demo.com:8081</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- cas登录验证tick服务 -->
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>
org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter
</filter-class>


<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>http://cas.demo.com:8080/cas</param-value>
</init-param>


<init-param>
<param-name>serverName</param-name>
<param-value>http://app1.demo.com:8081</param-value>
</init-param>


</filter>


<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- ????????HttpServletRequest?????,
?????????HttpServletRequest?getRemoteUser()????SSO????????,?????
-->


<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.HttpServletRequestWrapperFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!--
?????????????org.jasig.cas.client.util.AssertionHolder??????????
??AssertionHolder.getAssertion().getPrincipal().getName()? -->


<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.AssertionThreadLocalFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



3  客户端配置-client-2

web.xml 添加



<!-- ???? -->
<listener>
<listener-class>
org.jasig.cas.client.session.SingleSignOutHttpSessionListener
</listener-class>
</listener>





<filter>
<filter-name>CAS Single Sign Out Filter</filter-name>
<filter-class>
org.jasig.cas.client.session.SingleSignOutFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS Single Sign Out Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<!-- cas登录认证ticked -->

<filter>
<filter-name>CASFilter</filter-name>
<filter-class>
org.jasig.cas.client.authentication.AuthenticationFilter
</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<param-value>
http://cas.demo.com:8080/cas/login
</param-value>

</init-param>
<init-param>
<param-name>serverName</param-name>
<param-value>http://app2.demo.com:8082</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>CASFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- cas登录验证ticked-->
<filter>
<filter-name>CAS Validation Filter</filter-name>
<filter-class>
org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter
</filter-class>


<init-param>
<param-name>casServerUrlPrefix</param-name>
<param-value>http://cas.demo.com:8080/cas</param-value>
</init-param>


<init-param>
<param-name>serverName</param-name>
<param-value>http://app2.demo.com:8082</param-value>
</init-param>


</filter>


<filter-mapping>
<filter-name>CAS Validation Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!-- ????????HttpServletRequest?????,
?????????HttpServletRequest?getRemoteUser()????SSO????????,?????
-->


<filter>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.HttpServletRequestWrapperFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS HttpServletRequest Wrapper Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


<!--
?????????????org.jasig.cas.client.util.AssertionHolder??????????
??AssertionHolder.getAssertion().getPrincipal().getName()? -->


<filter>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<filter-class>
org.jasig.cas.client.util.AssertionThreadLocalFilter
</filter-class>
</filter>


<filter-mapping>
<filter-name>CAS Assertion Thread Local Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>


4  C:\Windows\System32\drivers\etc\hosts文件


127.0.0.1       cas.demo.com
127.0.0.1       app1.demo.com
127.0.0.1       app2.demo.com


5 对应3个tomcat server.xml 配置

<Engine name="Catalina" defaultHost="app2.demo.com">


      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
      <!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->        


      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->


      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>


      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="app2.demo.com"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">


        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->


        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"  
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->




<!--








<Context path="/web" docBase="E:\workspace\dxj\WebRoot\"  reloadable="true" debug="0" />


<Context path="/web" docBase="E:\workspace\pl_report\WebRoot\"  reloadable="true" debug="0" />




<Context path="/web" docBase="E:\workspace\report_single\WebRoot\"  reloadable="true" debug="0" />


<Context path="/app2" debug="0" docBase="E:\App2Work\app2\WebRoot" reloadable="true" />
-->


      </Host>



6  浏览器

http://app1.demo.com:8081/examples/servlets/TestLoginServlet

http://app2.demo.com:8082/examples/servlets/TestLoginServlet

或者tomcat6-x64自带的

examples

http://app1.demo.com:8081/examples/servlets/

http://app2.demo.com:8082/examples/servlets/


输入任意地址,均跳转到cas登录,登陆成功app1,则app2无需再次输入用户名和密码。就可以访问资源。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值