码迷,mamicode.com
首页 > 其他好文 > 详细

InitialFlowSetupAction 说明

时间:2015-04-20 07:01:38      阅读:549      评论:0      收藏:0      [点我收藏+]

标签:cas sso

开源的CAS已经很多牛人分析过了,最近在看源码,也总结一下

InitialFlowSetupAction.java主要代码

 

   protected Event doExecute(final RequestContext context) throws Exception {

        final HttpServletRequest request = WebUtils.getHttpServletRequest(context);

        if (!this.pathPopulated) {

            final String contextPath = context.getExternalContext().getContextPath();

            final String cookiePath = StringUtils.hasText(contextPath) ? contextPath + "/" : "/";

            logger.info("Setting path for cookies to: "

                + cookiePath);

            

            /** 给两个CookieGenerator设置CookiePath,通过cas-servlet.xml配置可以看出两个CookieGenerator分别对应了

             * warnCookieGenerator.xml和ticketGrantingTicketCookieGenerator.xml的注入bean

             * 所以CookiePath都为/cas*/

            this.warnCookieGenerator.setCookiePath(cookiePath);

            this.ticketGrantingTicketCookieGenerator.setCookiePath(cookiePath);

            this.pathPopulated = true;

        }

        

        /** 从request中取回cookie的值存在FlowScope中

         * 从哪个cookie取取决于warnCookieGenerator.xml或ticketGrantingTicketCookieGenerator.xml

         */

        context.getFlowScope().put(

            "ticketGrantingTicketId", this.ticketGrantingTicketCookieGenerator.retrieveCookieValue(request));

        context.getFlowScope().put(

            "warnCookieValue",

            Boolean.valueOf(this.warnCookieGenerator.retrieveCookieValue(request)));


        /** 在初始化的时候给this.argumentExtractors注入了两个ArgumentExtractor,配置在argumentExtractorsConfiguration.xml中

         * 分别是CasArgumentExtractor和SamlArgumentExtractor

         */

        final Service service = WebUtils.getService(this.argumentExtractors,

            context);


        if (service != null && logger.isDebugEnabled()) {

            logger.debug("Placing service in FlowScope: " + service.getId());

        }

        //把service放入FlowScope

        context.getFlowScope().put("service", service);


        return result("success");

    }



CookieRetrievingCookieGenerator.java

    /**

     * 从request里面取出name为cookieName的cookie

     * cookieName定义在warnCookieGenerator.xml或ticketGrantingTicketCookieGenerator.xml中

     * @param request

     * @return

     */

    public String retrieveCookieValue(final HttpServletRequest request) {

        final Cookie cookie = org.springframework.web.util.WebUtils.getCookie(

            request, getCookieName());


        return cookie == null ? null : cookie.getValue();

    }


本文出自 “ping blog” 博客,请务必保留此出处http://liyanping.blog.51cto.com/6241230/1635885

InitialFlowSetupAction 说明

标签:cas sso

原文地址:http://liyanping.blog.51cto.com/6241230/1635885

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!