spring mvc 接入cas登录

费劲千辛万苦开发出来的系统要接入sso 让我头大还好有大佬帮忙

 

首先在配置文件中写入启动的ip地址

HOST=http://127.0.0.1:8080/  地址写你的地址和端口

 

 

 

然后在pom文件中导入cas-client包用来连接cas的server端口

 

        <dependency>
            <groupId>org.jasig.cas.client</groupId>
            <artifactId>cas-client-core</artifactId>
            <version>3.5.1</version>
        </dependency>

 

 

然后在配置文件中进行配置

 

<!--   cas监听 -->

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

<!--    监听结束-->


<!--cas配置开始-->

    <filter>
        <filter-name>CasSingleSignOutFilter</filter-name>
        <filter-class>org.jasig.cas.client.session.SingleSignOutFilter</filter-class>
        <init-param>
            <param-name>casServerUrlPrefix</param-name>
            <param-value>http://sso.caicaivip.com/</param-value>  // 你的 sso服务端地址
        </init-param>
    </filter>

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

    <filter>
        <filter-name>CasAuthenticationFilter</filter-name>
        <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
        <init-param>
            <param-name>casServerLoginUrl</param-name>
            <param-value>http://sso.caicaivip.com/login</param-value>   // 服务端口的登录接口
        </init-param>
        <init-param>
            <param-name>serverName</param-name>
            <param-value>${HOST}</param-value>
        </init-param>
        <init-param>
            <param-name>ignorePattern</param-name>
            <param-value>/status</param-value>
        </init-param>
    </filter>

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

    <filter>
        <filter-name>CasValidationFilter</filter-name>
        <filter-class>org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter</filter-class>
        <init-param>
            <param-name>casServerUrlPrefix</param-name>
            <param-value>http://sso.caicaivip.com/</param-value>  //server地址
        </init-param>
        <init-param>
            <param-name>serverName</param-name>
            <param-value>${HOST}</param-value>
        </init-param>
        <init-param>
            <param-name>redirectAfterValidation</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

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

    <filter>
        <filter-name>CasHttpServletRequestWrapperFilter</filter-name>
        <filter-class>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>CasHttpServletRequestWrapperFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
<!--cas配置结束-->

 

然后就可以启动接入你的sso的服务端口了

 

posted @ 2019-05-20 17:07  可爱的红领巾  阅读(2307)  评论(0编辑  收藏  举报