- 浏览: 533438 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (278)
- freemarker (6)
- flex应用 (12)
- Ext应用 (11)
- 软件 (16)
- java (61)
- 报表 (6)
- 框架基础 (6)
- 登录页面素材 (7)
- oracle (1)
- cas (10)
- lucene (6)
- linux (11)
- 视频 (10)
- springmvc (3)
- 视频服务器相关 (12)
- 开发工具 (7)
- IOS (20)
- 网站相关 (4)
- Java 任务调度系统带图形界面的 (1)
- maven (2)
- android (29)
- hadoop (3)
- SpagoBI (3)
- docx4j (4)
- 多线程 (2)
- storm (2)
- mobile 框架 (3)
- scala (1)
- socket (1)
- saiku (1)
最新评论
-
ZXCLTN:
1.streams目录,在里面放些flv,mp3之类的文件,这 ...
red5 整合到tomcat中(二) -
ZXCLTN:
写的没偷没尾的,还不如提供整个项目下载
red5 整合到tomcat中(二) -
01jiangwei01:
测试方法1:测试50个线 ...
hibernate 乐观锁 测试 -
01jiangwei01:
测试方法1:测试50个线程,同时并发访问。目标:只有一个通过, ...
hibernate 乐观锁 测试 -
xiaobadi:
你每次登陆都是跳到http://localhost:8081/ ...
cas 系统实例 服务端配置(二) 自定义登录
学习一下,自定义登录
在web.xml中增加remoteLogin,例如:
<servlet-mapping>
<servlet-name>cas</servlet-name>
<url-pattern>/myRemoteLogin</url-pattern>
</servlet-mapping>
<servlet-name>cas</servlet-name>
<url-pattern>/myRemoteLogin</url-pattern>
</servlet-mapping>
在cas-servlet.xml 中增加新的bean并添加相应的映射
<webflow:flow-registry id="flowRegistry" flow-builder-services="builder">
<webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
<webflow:flow-location path="/WEB-INF/mylogin-webflow.xml" id="myRemoteLogin" />
</webflow:flow-registry>
<webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
<webflow:flow-location path="/WEB-INF/mylogin-webflow.xml" id="myRemoteLogin" />
</webflow:flow-registry>
<bean id="remoteLoginAction"
class="org.jasig.cas.web.my.login.RemoteLoginAction"
p:argumentExtractors-ref="argumentExtractors"
p:warnCookieGenerator-ref="warnCookieGenerator"
p:centralAuthenticationService-ref="centralAuthenticationService"
p:initialFlowSetupAction-ref="initialFlowSetupAction"
p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"
/>
<bean id="generateResponse" class="org.jasig.cas.web.my.login.GenerateResponse"></bean>
class="org.jasig.cas.web.my.login.RemoteLoginAction"
p:argumentExtractors-ref="argumentExtractors"
p:warnCookieGenerator-ref="warnCookieGenerator"
p:centralAuthenticationService-ref="centralAuthenticationService"
p:initialFlowSetupAction-ref="initialFlowSetupAction"
p:ticketGrantingTicketCookieGenerator-ref="ticketGrantingTicketCookieGenerator"
/>
<bean id="generateResponse" class="org.jasig.cas.web.my.login.GenerateResponse"></bean>
mylogin-webflow.xml代码如下:
<?xml version="1.0" encoding="UTF-8"?> <flow xmlns="http://www.springframework.org/schema/webflow" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/webflow http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd"> <!-- 开始 --> <on-start> <!-- 定义执行方法 到数据库相关验证 --> <evaluate expression="remoteLoginAction" /> </on-start> <!-- 判断是否有错误 --> <decision-state id="hasError"> <if test="flowScope.error neq null && flowScope.error neq '' " then="hasfailPageCheck" else="sendTicketGrantingTicket" /> </decision-state> <!-- 取得错误信息,及返回页面 --> <action-state id="hasfailPageCheck"> <evaluate expression="generateResponse.getResponse( flowRequestContext,true)" result-type="org.jasig.cas.authentication.principal.Response" result="flowScope.response" /> <transition to="postView" /> </action-state> <action-state id="sendTicketGrantingTicket"> <evaluate expression="sendTicketGrantingTicketAction" /> <transition to="serviceCheck" /> </action-state> <decision-state id="serviceCheck"> <if test="flowScope.service neq null" then="generateServiceTicket" else="viewGenericLoginSuccess" /> </decision-state> <!-- 产生service票据 --> <action-state id="generateServiceTicket"> <evaluate expression="generateServiceTicketAction" /> <transition on="success" to ="getReturnResponse" /> <transition on="gateway" to="hasError" /> </action-state> <!-- 取得正常返回,及返回页面 --> <action-state id="getReturnResponse"> <evaluate expression="generateResponse.getResponse( flowRequestContext,false)" result-type="org.jasig.cas.authentication.principal.Response" result="flowScope.response" /> <transition to="redirectView" /> </action-state> <end-state id="postView" view="postResponseView"> <on-entry> <set name="requestScope.parameters" value="flowScope.response.attributes" /> <set name="requestScope.originalUrl" value="flowScope.response.url" /> </on-entry> </end-state> <end-state id="viewGenericLoginSuccess" view="casLoginGenericSuccessView" /> <end-state id="redirectView" view="externalRedirect:http://localhost:8081/casclient4/sso/index.jsp" /> <global-transitions> <transition to="viewServiceErrorView" on-exception="org.springframework.webflow.execution.repository.NoSuchFlowExecutionException" /> <transition to="viewServiceSsoErrorView" on-exception="org.jasig.cas.services.UnauthorizedSsoServiceException" /> <transition to="viewServiceErrorView" on-exception="org.jasig.cas.services.UnauthorizedServiceException" /> </global-transitions> </flow>
RemoteLoginAction.java
package org.jasig.cas.web.my.login; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotEmpty; import org.jasig.cas.CentralAuthenticationService; import org.jasig.cas.authentication.principal.Credentials; import org.jasig.cas.authentication.principal.Service; import org.jasig.cas.authentication.principal.UsernamePasswordCredentials; import org.jasig.cas.ticket.TicketException; import org.jasig.cas.web.flow.InitialFlowSetupAction; import org.jasig.cas.web.support.ArgumentExtractor; import org.jasig.cas.web.support.CookieRetrievingCookieGenerator; import org.jasig.cas.web.support.WebUtils; import org.springframework.util.StringUtils; import org.springframework.webflow.action.AbstractAction; import org.springframework.webflow.execution.Event; import org.springframework.webflow.execution.RequestContext; /** * 远程登陆票据提供Action. * 根据InitialFlowSetupAction修改. * 由于InitialFlowSetupAction为final类,因此只能将代码复制过来再进行修改. * * @author GuoLin */ public class RemoteLoginAction extends AbstractAction { /** CookieGenerator for the Warnings. */ @NotNull private CookieRetrievingCookieGenerator warnCookieGenerator; /** Extractors for finding the service. */ @NotEmpty private List<ArgumentExtractor> argumentExtractors; /** Core we delegate to for handling all ticket related tasks. */ @NotNull private CentralAuthenticationService centralAuthenticationService; @NotNull private CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator; private InitialFlowSetupAction initialFlowSetupAction; protected Event doExecute(final RequestContext context) { final HttpServletRequest request = WebUtils.getHttpServletRequest(context); /*** * 必须的 */ context.getFlowScope().put( "warnCookieValue", Boolean.valueOf(this.warnCookieGenerator.retrieveCookieValue(request))); String uName = request.getParameter("username"); String password = request.getParameter("password"); Credentials credentials =new UsernamePasswordCredentials(uName,password); if (!this.initialFlowSetupAction.pathPopulated) { final String contextPath = request.getContextPath(); final String cookiePath = StringUtils.hasText(contextPath) ? contextPath + "/" : "/"; logger.info("Setting path for cookies to: " + cookiePath); this.warnCookieGenerator.setCookiePath(cookiePath); this.ticketGrantingTicketCookieGenerator.setCookiePath(cookiePath); this.initialFlowSetupAction.pathPopulated = true; } context.getFlowScope().put("credentials", credentials); String createTicketGrantingTicket; try { createTicketGrantingTicket = this.centralAuthenticationService.createTicketGrantingTicket(credentials); /*** * 必须的 */ WebUtils.putTicketGrantingTicketInRequestScope(context,createTicketGrantingTicket ); } catch (TicketException e) { context.getFlowScope().put("error", "error.userOrPassword.error"); e.printStackTrace(); } // putWarnCookieIfRequestParameterPresent(context); final Service service = WebUtils.getService(this.argumentExtractors, context); if (service != null && logger.isDebugEnabled()) { logger.debug("Placing service in FlowScope: " + service.getId()); } context.getFlowScope().put("service", service); return result("submit"); } public void setWarnCookieGenerator(final CookieRetrievingCookieGenerator warnCookieGenerator) { this.warnCookieGenerator = warnCookieGenerator; } public void setArgumentExtractors( final List<ArgumentExtractor> argumentExtractors) { this.argumentExtractors = argumentExtractors; } public final void setCentralAuthenticationService(final CentralAuthenticationService centralAuthenticationService) { this.centralAuthenticationService = centralAuthenticationService; } public void setInitialFlowSetupAction( InitialFlowSetupAction initialFlowSetupAction) { this.initialFlowSetupAction = initialFlowSetupAction; } public void setTicketGrantingTicketCookieGenerator( final CookieRetrievingCookieGenerator ticketGrantingTicketCookieGenerator) { this.ticketGrantingTicketCookieGenerator = ticketGrantingTicketCookieGenerator; } }
GenerateResponse.java
package org.jasig.cas.web.my.login; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.jasig.cas.authentication.principal.Response; import org.jasig.cas.web.support.WebUtils; import org.springframework.webflow.execution.RequestContext; public class GenerateResponse { public Response getResponse( final RequestContext context,boolean haveError) { String orgUrl = ""; final Map<String, String> parameters = new HashMap<String, String>(); final HttpServletRequest request = WebUtils.getHttpServletRequest(context); if(haveError) { orgUrl =request.getParameter("failpae"); String error = (String) context.getFlowScope().get("error"); parameters.put("error", error); parameters.put("result", "false"); }else { orgUrl =request.getParameter("service"); parameters.put("result", "true"); } context.getFlowScope().put("responseUrl", orgUrl); Response ret = Response.getRedirectResponse(orgUrl, parameters); return ret; } }
客户端端方法:
<form id="myLoginForm" action="http://localhost:8081/casserver/myRemoteLogin" method="post"> <input type="hidden" id="targetService" name="service" value="http://localhost:8081/casclient4/sso/index.jsp"> <input type="hidden" name="failpae" value="http://localhost:8081/casclient4/index.jsp"> <table> <tr> <td>用户名:</td> <td><input type="text" name="username"></td> </tr> <tr> <td>密 码:</td> <td><input type="password" name="password"></td> </tr> <tr><td>验证码</td> <td><input type="text" /><img src="http://localhost:8081/casserver/random" class="sign_img fl mt5" /></td></tr> <tr> <td colspan="2"><input type="submit" value="登陆" /></td> </tr> </table> </form>
评论
4 楼
xiaobadi
2014-10-30
你每次登陆都是跳到http://localhost:8081/casclient4/sso/index.jsp。如果有多个客户端就有问题了吧
3 楼
Han_Zhou
2013-09-28
确实不行啊,可否发送一份配置好了的cas-server给我asher_sys@163.com
2 楼
01jiangwei01
2012-06-05
配合着几个可以登录运行啊。
1 楼
snowspice
2012-05-29
这个能正常运行吗?我试了下,不行呀
发表评论
-
cas 进阶篇二
2013-02-16 22:45 1202保存,并重新启动服务,输入用户名密码,进行登录。 4,通 ... -
cas 进阶篇一
2013-02-16 22:42 1431可以自己参考网站http://www.ja-sig.org ... -
cas 关注资料
2012-04-18 13:50 105网址一:http://hi.baidu.com/%D3%D2% ... -
cas 系统实例 客户配置(四) 访问受保护资源跳转到自定义登录页面
2012-03-20 15:25 3626方法和简单。就是在客户端web.xml的配置中。 <f ... -
cas 系统实例 服务端配置(三) 自定义登录 不使用webFlow
2012-03-20 15:09 107421,修改org.jasig.cas.web.flow.Init ... -
cas 系统实例 配置及使用
2012-03-15 17:46 1294我个人想法使用方式是: 登录,采用客户端登录 找回密码:采 ... -
cas 系统实例 服务端配置(三) 退出到指定页面
2012-03-15 17:34 2468CAS退出默认是转向CAS内置的退出页面,在实际应用中需要跳转 ... -
cas 系统实例 客户端配置
2012-03-15 16:49 27021.解压后把modules下面的包放到我们的web应用中 2 ... -
cas 系统实例 服务端配置(一)
2012-03-01 15:39 2886最近在研究cas 并对其进行改版,终于有所成就,写出来与大 ... -
cas 简单配置 不用证书
2012-02-24 16:17 2168cas单点登录配置速成 服务端配置 ca ...
相关推荐
[置顶] SSO单点登录系列3:cas-server端配置认证方式实践(数据源+自定义java类认证) http://blog.csdn.net/ae6623/article/details/8851801 [置顶] SSO单点登录系列2:cas客户端和cas服务端交互原理动画图解,cas...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...
Tcp服务端与客户端的JAVA实例源代码,一个简单的Java TCP服务器端程序,别外还有一个客户端的程序,两者互相配合可以开发出超多的网络程序,这是最基础的部分。 递归遍历矩阵 1个目标文件,简单! 多人聊天室 3...
注意: 如果不带任何参数,fixboot 命令将向用户登录的系统分区写入新的分区引导扇区。 Fixmbr 修复启动磁盘的 主启动记录。fixmbr 命令仅在使用故障恢复控制台时才可用。 fixmbr [ device_name] 参数 ...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...
AutoTips是为解决应用系统对于【自动提示】的需要(如:Google搜索), 而开发的架构无关的公共控件, 以满足该类需求可以通过快速配置来开发。AutoTips基于搜索引擎Apache Lucene实现。AutoTips提供统一UI。 WAP浏览器...