• 单点登录cas的最简单使用


    做单点登录-----cas 技术

    1 网上下载cas工程

    找到cas.war 放在服务器下(可以改cas的端口)启动

    2 建立项目maven 工程

    2.1 pom.xml 引入

    <!--单点登录-->
          <dependency>
              <groupId>org.jasig.cas.client</groupId>
              <artifactId>cas-client-core</artifactId>
              <version>3.3.3</version>
              <exclusions>
                  <exclusion>
                      <groupId>org.slf4j</groupId>
                      <artifactId>log4j-over-slf4j</artifactId>
                  </exclusion>
              </exclusions>
          </dependency>

    2.2 在web.xml 中引入配置,改四个IP 地址

     <!-- ======================== 单点登录开始 (本工程用了第三方提供的jar 包)========================
       -->
       <!-- &lt;!&ndash; 用于单点退出,该过滤器用于实现单点登出功能,可选配置&ndash;&gt;
        <listener>
            <listener-class>org.jasig.cas.client.session.SingleSignOutHttpSessionListener</listener-class>
        </listener>
        &lt;!&ndash; 该过滤器用于实现单点登出功能,可选配置。&ndash;&gt;
        <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>
    
       &lt;!&ndash;  该过滤器负责用户的认证工作,必须启用它&ndash;&gt;
        <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://170.35.252.77:9080/cas/login</param-value>
                &lt;!&ndash;这里的server是服务端的IP&ndash;&gt;
            </init-param>
            <init-param>
                <param-name>serverName</param-name>
                <param-value>http://127.0.0.1:8080</param-value>//工程访问路径
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>CASFilter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        &lt;!&ndash; 该过滤器负责对Ticket的校验工作,必须启用它&ndash;&gt;
        <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://170.35.252.77:9080/cas</param-value>
            </init-param>
            <init-param>
                <param-name>serverName</param-name>
                <param-value>http://127.0.0.1:8080</param-value>
            </init-param>
        </filter>
        <filter-mapping>
            <filter-name>CAS Validation Filter</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
         &lt;!&ndash;该过滤器负责实现HttpServletRequest请求的包裹, 比如允许开发者通过HttpServletRequest的getRemoteUser()方法获得SSO登录用户的登录名,可选配置。
       &ndash;&gt;
        <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>
    
        &lt;!&ndash; 该过滤器使得开发者可以通过org.jasig.cas.client.util.AssertionHolder来获取用户的登录名。 比如AssertionHolder.getAssertion().getPrincipal().getName()。&ndash;&gt;
        <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>-->
         <!--======================== 单点登录结束 ========================-->

    简单的cas 使用就这样结束了

    注意事项:1 cas 过滤器要放在第二位

         2  第一位放的是post 请求解决乱码的,如果不放在第一位,会出现乱码问题 

  • 相关阅读:
    Java学习开篇
    《我的姐姐》
    世上本无事,庸人自扰之
    这48小时
    补觉
    淡定
    es java api 设置index mapping 报错 mapping source must be pairs of fieldnames and properties definition.
    java mongodb groupby分组查询
    linux 常用命令
    mongodb too many users are authenticated
  • 原文地址:https://www.cnblogs.com/jsbk/p/9830382.html
Copyright © 2020-2023  润新知