博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
org.jasig.cas.client校验
阅读量:5809 次
发布时间:2019-06-18

本文共 4256 字,大约阅读时间需要 14 分钟。

AbstractTicketValidationFilter

org.jasig.cas.client.validation.AbstractTicketValidationFilter

public final void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse,            final FilterChain filterChain) throws IOException, ServletException {        if (!preFilter(servletRequest, servletResponse, filterChain)) {            return;        }        final HttpServletRequest request = (HttpServletRequest) servletRequest;        final HttpServletResponse response = (HttpServletResponse) servletResponse;        final String ticket = retrieveTicketFromRequest(request);        if (CommonUtils.isNotBlank(ticket)) {            logger.debug("Attempting to validate ticket: {}", ticket);            try {                final Assertion assertion = this.ticketValidator.validate(ticket,                        constructServiceUrl(request, response));                logger.debug("Successfully authenticated user: {}", assertion.getPrincipal().getName());                request.setAttribute(CONST_CAS_ASSERTION, assertion);                if (this.useSession) {                    request.getSession().setAttribute(CONST_CAS_ASSERTION, assertion);                }                onSuccessfulValidation(request, response, assertion);                if (this.redirectAfterValidation) {                    logger.debug("Redirecting after successful ticket validation.");                    response.sendRedirect(constructServiceUrl(request, response));                    return;                }            } catch (final TicketValidationException e) {                logger.debug(e.getMessage(), e);                onFailedValidation(request, response);                if (this.exceptionOnValidationFailure) {                    throw new ServletException(e);                }                response.sendError(HttpServletResponse.SC_FORBIDDEN, e.getMessage());                return;            }        }        filterChain.doFilter(request, response);    }

AuthenticationFilter

org.jasig.cas.client.authentication.AuthenticationFilter

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;                if (isRequestUrlExcluded(request)) {            logger.debug("Request is ignored.");            filterChain.doFilter(request, response);            return;        }                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;        }        final String serviceUrl = constructServiceUrl(request, response);        final String ticket = retrieveTicketFromRequest(request);        final boolean wasGatewayed = this.gateway && this.gatewayStorage.hasGatewayedAlready(request, serviceUrl);        if (CommonUtils.isNotBlank(ticket) || wasGatewayed) {            filterChain.doFilter(request, response);            return;        }        final String modifiedServiceUrl;        logger.debug("no ticket and no assertion found");        if (this.gateway) {            logger.debug("setting gateway attribute in session");            modifiedServiceUrl = this.gatewayStorage.storeGatewayInformation(request, serviceUrl);        } else {            modifiedServiceUrl = serviceUrl;        }        logger.debug("Constructed service url: {}", modifiedServiceUrl);        final String urlToRedirectTo = CommonUtils.constructRedirectUrl(this.casServerLoginUrl,                getProtocol().getServiceParameterName(), modifiedServiceUrl, this.renew, this.gateway);        logger.debug("redirecting to \"{}\"", urlToRedirectTo);        this.authenticationRedirectStrategy.redirect(request, response, urlToRedirectTo);    }

filter执行顺序

先AbstractTicketValidationFilter后AuthenticationFilter。即先看有没ticket,有的话,去跟cas server验证,验证成功则往下,不成功则跳转到cas/login。如果没有ticket则往下验证有没有session,有的成功,没有则跳转到cas请求service ticket。

doc

转载地址:http://fhjbx.baihongyu.com/

你可能感兴趣的文章
python 开发之selenium
查看>>
Xcode3.2.5中找不到Mac OS X - Command Line Utility -...
查看>>
css的div垂直居中的方法,百分比div垂直居中
查看>>
如何理解EM算法
查看>>
nginx 域名跳转一例~~~(rewrite、proxy)
查看>>
linux用户家目录无损迁移到独立硬盘
查看>>
文件查找
查看>>
shell编程前言(一)
查看>>
5、centos7.*配置yum的EPEL源及其它源
查看>>
JSON前后台简单操作
查看>>
shell中一些常见的文件操作符
查看>>
CentOS 7 装vim遇到的问题和解决方法
查看>>
JavaScript基础教程1-20160612
查看>>
使用第三方类、库需要注意的正则类RegexKitLite的使用
查看>>
iOS \U7ea2 乱码 转换
查看>>
FCN图像分割
查看>>
ios xmpp demo
查看>>
设计模式之-工厂模式、构造函数模式
查看>>
python matplotlib 中文显示参数设置
查看>>
数据库事务隔离级别
查看>>