`

cas client AuthenticationFilter

    博客分类:
  • sso
 
阅读更多
必要参数:

casServerLoginUrl :定义CAS服务器的登录URL地址,例如: https://localhost:8443/cas/login

service or serverName:

    service :发送到CAS服务器的service URL地址,例如https://localhost:8443/yourwebapp/index.html

    serverName:CAS客户端的服务器名称,Service URL使用这个名称动态组装,例如:http://localhost:8080 (必须包括协议,如果端口是标准端口则可以不写,例如80端口)

可选参数:

    renew : 指定renew是否为true,有效值为true和false,如果为true则每次请求都产生新的session。默认是false。
    gateway - 指定是否使用防火墙,有效值是true和false,默认是false。
    artifactParameterName - 指定request保存票据的参数名称,默认是ticket。
    serviceParameterName - 指定request保存service的参数名称,默认是service。


 public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
        // 转换参数
    	final HttpServletRequest request = (HttpServletRequest) servletRequest;
        final HttpServletResponse response = (HttpServletResponse) servletResponse;
        //从session中取得Assertion
        final HttpSession session = request.getSession(false);
        final Assertion assertion = session != null ? (Assertion) session.getAttribute(CONST_CAS_ASSERTION) : null;
        //如果存在,则说明已经登录,本过滤器处理完成,处理下个过滤器
        if (assertion != null) {
            filterChain.doFilter(request, response);
            return;
        }
        //如果session中没有Assertion对象,组装serviceUrl并试着从参数中取得ticket属性。
        final String serviceUrl = constructServiceUrl(request, response);
        final String ticket = CommonUtils.safeGetParameter(request,getArtifactParameterName());
        final boolean wasGatewayed = this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);
        //如果ticket不为空,或者wasGatewayed为true,则本过滤器处理完成,处理下个过滤器
        if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {
            filterChain.doFilter(request, response);
            return;
        }
        // 定义需要条状的url地址
        final String modifiedServiceUrl;

        log.debug("no ticket and no assertion found");
        //ticket 为空,并且wasGatewayed也为false,则根据初始化参数gateway的值来组装跳转url。
        if (this.gateway) {
            log.debug("setting gateway attribute in session");
            modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);
        } else {
            modifiedServiceUrl = serviceUrl;
        }

        if (log.isDebugEnabled()) {
            log.debug("Constructed service url: " + modifiedServiceUrl);
        }
        
        //组装跳转url
        final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl, getServiceParameterName(), 
        		modifiedServiceUrl, this.renew, this.gateway, this.aspId);

        if (log.isDebugEnabled()) {
            log.debug("redirecting to \"" + urlToRedirectTo + "\"");
        }
        //跳转到urlToRedirectTo指定的url,如果没有配置gateway,则跳转到casServerLoginUrl参数指定的url。
        response.sendRedirect(urlToRedirectTo);
    }
分享到:
评论

相关推荐

    spring boot整合CAS Client实现单点登陆验证的示例

    <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter <param-name>casServerLoginUrl <param-value>http://127.0.0.1/login</param-value> <param-name>serverName <param-value>...

    cas 配置client 1.0 &2.0 及proxy DEMO 说明

    org.jasig.cas.client.authentication.AuthenticationFilter <!-- cas server LOGIN URL --> <!-- https://www.test.com:8443/cas/login--> <param-name>casServerLoginUrl ...

    CAS客户端JAR包版本3.3.3

    org.jasig.cas.client.authentication.AuthenticationFilter <param-name>casServerLoginUrl <param-value>http://192.168.156.120:8080/cas/login</param-value> <!--这里的 server 是服务端的 IP --&gt...

    关于cas安装和配置

    1. **部署 CAS Client 应用**:将测试应用 casClient2 部署到 Tomcat 的 webapps 目录下,并将 cas-client-core-3.2.1.jar 添加到 lib 目录。 2. **修改 web.xml**:在应用的 web.xml 文件中添加必要的配置元素,以...

    CAS 客户端排除不需要过滤的路径

    排除CAS客户端不需要过滤的路径,在web.xml文件中配置排除地址。

    CAS多数据库配置单点登录

    * 认证过滤器:org.jasig.cas.client.authentication.AuthenticationFilter * Ticket校验过滤器:org.jasig.cas.client.validation.Cas20ProxyReceivingTicketValidationFilter * HttpServletRequest包裹过滤器:org...

    CAS实现内外网映射访问的解决办法

    本例中使用的是`cas-client-3.2.1-release.zip`,其中包含了`cas-client-core-3.2.1.jar`的源代码。可以从官方网址`http://developer.jasig.org/cas-clients/`下载。 2. **导入源码至IDE** 将下载的`cas-client-...

    shiro整合cas的实例

    设置 `filter-class` 为 `org.jasig.cas.client.authentication.AuthenticationFilter`,并配置相应的参数如 `casServerLoginUrl` 和 `serverName`。 - 接下来,配置 `ServiceValidateFilter` 用于验证从 CAS ...

    cas-java-client

    示例CASified Java Web应用程序这是一个示例Java Web应用程序,它通过Java CAS Client行使CAS协议功能。配置在文件中调整CAS服务器和应用程序服务器的url端点。 如果您希望执行代理身份验证,请在同一文件Cas20...

    JA-SIG(CAS)简单部署01

    - **添加依赖库**:将 `casclient.jar` 和 `commons-logging-1.0.4.jar` 复制到 `examples\WEB-INF\lib` 目录下。 ##### STEP 5: 部署 JA-SIG (CAS) 服务器 - **部署 CAS Server**:将 `cas.war` 文件解压至 `E:\...

    spring boot整合CAS配置详解

    Spring Boot 整合 CAS ...其中,我们定义了多个 Bean,包括 `SingleSignOutHttpSessionListener`、`AuthenticationFilter`、`AssertionThreadLocalFilter`、`HttpServletRequestWrapperFilter`、`LogoutFilter`、`Cas20...

    单点登录cas的配置过程

    <filter-class>org.jasig.cas.client.authentication.AuthenticationFilter <param-name>casServerLoginUrl <param-value>https://www.travel.com:8443/cas/login</param-value> <param-name>serverName ...

    CAS技术文档.docx

    为了实现 CAS 客户端与业务系统的集成,你需要将 `cas-client.jar` 添加到业务系统的类路径中。CAS 提供了几个过滤器来拦截用户请求,判断用户登录状态,并在必要时重定向到 CAS 服务器进行身份验证。关键过滤器包括...

    统一身份认证对外文档

    org.jasig.cas.client.authentication.AuthenticationFilter <param-name>casServerLoginUrl http://CASServer:8080/CAS-yuan02/login <param-name>serverName <param-value>...

    Spring Security整合CAS的示例代码

    nt.validation.Cas20ServiceTicketValidator"> ${cas.server.url}"/> </bean> <bean id="authenticationFilter" class="org.jasig.cas.client.authentication.Saml11AuthenticationFilter"> ${cas.server.url}/login...

Global site tag (gtag.js) - Google Analytics