标签: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
标签:cas sso
原文地址:http://liyanping.blog.51cto.com/6241230/1635885