• Eclipse配置CAS client


    1.新建一个Maven项目

     

    2.Next,选择

     

    3.输入group id 和 artifact id -->  Finish

     

    4.项目创建完成的目录结构

    编辑pom.xml文件,写上依赖

    注意把servlet-api依赖给去掉了,因为Tomcat库中已经有了这个jar包,不去掉会导致冲突,程序无法正常运行。

    不去掉servlet-api依赖的库,可以看到两个包冲突了。

     

     

    5.配置web.xml

     

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app>
      <display-name>Archetype Created Web Application</display-name>
      
      <!-- 单点退出 -->
      <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>
      
      <!-- 该filter负责对请求进行登录验证拦截 -->
      <filter>
          <filter-name>CAS Authentication Filter</filter-name>
          <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
          <init-param>
              <param-name>casServerLoginUrl</param-name>
              <param-value>https://rs-pc:8443/cas-server-webapp-3.5.2.1/login</param-value>
          </init-param>
          <init-param>
              <param-name>serverName</param-name>
              <param-value>http://rs-pc:8080</param-value>
          </init-param>
      </filter>
      <filter-mapping>
          <filter-name>CAS Authentication Filter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
      
      <!-- 该filter负责对请求参数ticket进行验证 -->
      <filter>
          <filter-name>CAS Validation Filter</filter-name>
          <filter-class>org.jasig.cas.client.validation.Cas10TicketValidationFilter</filter-class>
          <init-param>
              <param-name>casServerUrlPrefix</param-name>
              <param-value>https://rs-pc:8443/cas-server-webapp-3.5.2.1</param-value>
          </init-param>
          <init-param>
              <param-name>serverName</param-name>
              <param-value>http://rs-pc:8080</param-value>
          </init-param>
      </filter>
      <filter-mapping>
          <filter-name>CAS Validation Filter</filter-name>
          <url-pattern>/*</url-pattern>
      </filter-mapping>
      
      <!-- HttpServletRequest包裹类,支持getUserPrincipal,getRemoteUser方法取得用户信息 -->
      <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>
      
      <!-- 把Assertion信息放在ThreadLocal变量中,不在web层也能获取当前登录信息 -->
      <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>
       
      
    </web-app>

     

     7.让客户端信任服务端生成的证书,首先将服务端生成的证书casserver.cer文件,复制到$JAVA_HOME/Jre/lib/security下,以管理员方式运行cmd,切换到$JAVA_HOME/Jre/lib/security目录下执行命令:

    keytool -import -trustcacerts -alias casclient -storepass changeit -file casserver.cer -keystore cacerts

    提示是否导入证书,输入y,回车即可。

     

    8.右键项目Run As -> Run on Server

     

    要将(Cas Server也运行起来)

  • 相关阅读:
    解决配置Windows Update失败问题
    Rabbit MQ 消息确认和持久化机制
    Spring Boot事务管理(上)
    Spring Boot事务管理(中)
    Spring Boot事务管理(下)
    接口和抽象类的区别
    MySQL索引优化
    Spring 注解之@RestController与@Controller的区别
    Spring Boot核心注解@SpringBootApplication
    Java抽象类与接口的区别
  • 原文地址:https://www.cnblogs.com/13jhzeng/p/5728977.html
Copyright © 2020-2023  润新知