Java cas 实例 客户端配置

Java cas 实例 客户端配置

第二步 客户端web应用程序集成CAS

1. 从官网下载CAS Client, 将客户端的jar,
cas-client-core-3.2.1.jar   commons-logging-1.1.jar 引入到web应用程序的classpath中
2 .配置web.xml文件, 主要是添加过滤器拦截通信, 下面的实例代码, 假设web应用程序的端口是8888

	<!-- CAS 单点登录(SSO) 过滤器配置 (start) -->  
      
    <!-- 该过滤器用于实现单点登出功能。-->  
    <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: 用于单点退出 -->  
    <listener>  
        <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>  
    </listener>  
	
	    <!-- 该过滤器负责用户的认证工作,必须启用它 -->  
    <filter>  
        <filter-name>CASFilter</filter-name>  
        <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>  
        <init-param>  
            <param-name>casServerLoginUrl</param-name>  
            <!-- 下面的URL是Cas服务器的登录地址 -->  
            <param-value>http://localhost:8888/cas-server/login</param-value>  
        </init-param>  
        <init-param>  
            <param-name>serverName</param-name>  
            <!-- 下面的URL是具体某一个应用的访问地址 -->  
            <param-value>http://localhost:8888/</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>CASFilter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  
       
    <!-- 该过滤器负责对Ticket的校验工作,必须启用它 -->  
    <filter>  
        <filter-name>CAS Validation Filter</filter-name>  
        <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>  
        <init-param>
		  <param-name>redirectAfterValidation</param-name>
		  <param-value>true</param-value>
		</init-param>
        <init-param>  
            <param-name>casServerUrlPrefix</param-name>  
            <!-- 下面的URL是Cas服务器的认证地址 -->  
            <param-value>http://localhost:8888/cas-server</param-value>  
        </init-param>  
        <init-param>  
            <param-name>serverName</param-name>  
            <!-- 下面的URL是具体某一个应用的访问地址 -->  
            <param-value>http://localhost:8888/</param-value>  
        </init-param>  
        <init-param>  
          <param-name>renew</param-name>  
          <param-value>false</param-value>  
        </init-param>  
        <init-param>  
          <param-name>gateway</param-name>  
          <param-value>false</param-value>  
        </init-param>  
    </filter>  
    <filter-mapping>  
        <filter-name>CAS Validation Filter</filter-name>  
        <url-pattern>/*</url-pattern>  
    </filter-mapping>  

3、启动报错如下

java.lang.RuntimeException: java.io.FileNotFoundException: https://localhost:8443/serviceValidate?ticket=ST-1-1HUXO9iETnaNI2jbuvqK-cas01.example.org&service=http%3A%2F%2Flocalhost%3A8080%2FCasClient%2FIndex.jsp
    org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:328)
    org.jasig.cas.client.util.CommonUtils.getResponseFromServer(CommonUtils.java:291)
    org.jasig.cas.client.validation.AbstractCasProtocolUrlBasedTicketValidator.retrieveResponseFromServer(AbstractCasProtocolUrlBasedTicketValidator.java:32)
    org.jasig.cas.client.validation.AbstractUrlBasedTicketValidator.validate(AbstractUrlBasedTicketValidator.java:187)
    org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:164)
    org.jasig.cas.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:102)

原因:


4、测试是否会跳转到cas验证页面,以及登录成功后会不会回到原页面

5、只要在系统的登出事件中, 将URL访问地址指向CAS服务登出的servlet, 就可以了。http://CAS服务器IP:8080/cas/logout

「点点赞赏,手留余香」

    还没有人赞赏,快来当第一个赞赏的人吧!
0 条回复 A 作者 M 管理员
    所有的伟大,都源于一个勇敢的开始!
欢迎您,新朋友,感谢参与互动!欢迎您 {{author}},您在本站有{{commentsCount}}条评论