- 浏览: 315714 次
- 性别:
- 来自: 宁波
文章分类
最新评论
-
bqlin1987:
请问是不是ITeye的代码莫名的换行了?
学习SSO-1 Tomcat启用ssl -
a6821122:
在data-config.xml 里的javascript 不 ...
solr导入Oracle日期时间数据的处理 -
jie_kong:
是flexigrid不是flexgrid
FlexGrid自己用的经验 -
zjnbshifox:
呵呵,我也在摸索阶段,谢谢提醒ligywin 写道还需要补充以 ...
CAS自定义Credentials登录 -
ligywin:
还需要补充以下方法import org.apache.comm ...
CAS自定义Credentials登录
先看了这篇文章http://www.blogjava.net/junky/archive/2007/08/20/138136.html,但是这个的版本是3.1的,而最新的是3.5的,差别还是有一点的,网上找了很多资料,也看了一点CAS server的源代码,终于搞定,因为想用idea开发,结果环境不熟悉,蛋疼,虽然现在Eclipse越来越慢,也只好将就着用,废话不说,代码说话,首先定义自己的Credentials
然后修改登录页面,在password后面增加一个选项,这里直接用中文会乱码,需要到资源文件里去定义,为了方便我直接这么写了
找到/WEB-INF/下的login-webflow.xml文件,需要修改两个地方,第一把原来的Credentials注释,然后定义自己的
然后找到
这样数据就能绑定了,还要自定义一个处理登录过程的类
最后把处理类注册到/WEB-INF/deployerConfigContext.xml文件中,替换原有的AuthenticationHandler
public class NbrcCredentials implements Credentials { private static final long serialVersionUID = 2053021031579470710L; private String idtype; private String username; private String password; //getter and setter... }
然后修改登录页面,在password后面增加一个选项,这里直接用中文会乱码,需要到资源文件里去定义,为了方便我直接这么写了
<spring:message code="screen.welcome.label.password.accesskey" var="passwordAccessKey" /> <form:password cssClass="required" cssErrorClass="error" id="password" size="25" tabindex="2" path="password" accesskey="${passwordAccessKey}" htmlEscape="true" autocomplete="off" /> <br/> User TYPE<select name="idtype" id="idtype"> <option value="1">ADMIN</option> <option value="2">OPER</option> </select>
找到/WEB-INF/下的login-webflow.xml文件,需要修改两个地方,第一把原来的Credentials注释,然后定义自己的
<!-- <var name="credentials" class="org.jasig.cas.authentication.principal.UsernamePasswordCredentials" /> --> <var name="credentials" class="com.nbrc.sso.cas.principal.NbrcCredentials"/>
然后找到
<view-state id="viewLoginForm" view="casLoginView" model="credentials"> <binder> <binding property="username" /> <binding property="password" /> <binding property="idtype"/> <!--增加这一行 --> </binder> ... </view-state>
这样数据就能绑定了,还要自定义一个处理登录过程的类
package com.nbrc.cas.handler.support; import com.nbrc.sso.cas.principal.NbrcCredentials; import org.jasig.cas.authentication.handler.*; import org.jasig.cas.authentication.principal.Credentials; import org.springframework.dao.IncorrectResultSizeDataAccessException; import org.springframework.jdbc.core.JdbcTemplate; import javax.sql.DataSource; public class NbrcAuthenticationHandler implements AuthenticationHandler { private static final Class<NbrcCredentials> DEFAULT_CLASS = NbrcCredentials.class; private PasswordEncoder passwordEncoder = new PlainTextPasswordEncoder(); private JdbcTemplate jdbcTemplate; private DataSource dataSource; private PrincipalNameTransformer principalNameTransformer = new NoOpPrincipalNameTransformer(); /** Class that this instance will support. */ private Class<?> classToSupport = DEFAULT_CLASS; private boolean supportSubClasses = true; @Override public boolean authenticate(Credentials credentials) throws AuthenticationException { final NbrcCredentials nc = (NbrcCredentials) credentials; final String username = getPrincipalNameTransformer().transform(nc.getUsername()); final String password = nc.getPassword(); final String encryptedPassword = this.getPasswordEncoder().encode( password); if("1".equals(nc.getIdtype())){ try { final String sql = "select `password` from t_admin_user where login_name=?"; final String dbPassword = getJdbcTemplate().queryForObject( sql , String.class, username); return dbPassword.equals(encryptedPassword); } catch (final IncorrectResultSizeDataAccessException e) { // this means the username was not found. return false; } } if("2".equals(nc.getIdtype())){ try { final String sql = "select `password` from t_oper_user where login_name=?"; final String dbPassword = getJdbcTemplate().queryForObject( sql , String.class, username); return dbPassword.equals(encryptedPassword); } catch (final IncorrectResultSizeDataAccessException e) { // this means the username was not found. return false; } } return false; //To change body of implemented methods use File | Settings | File Templates. } @Override public boolean supports(Credentials credentials) { return credentials != null && (this.classToSupport.equals(credentials.getClass()) || (this.classToSupport .isAssignableFrom(credentials.getClass())) && this.supportSubClasses); } public PasswordEncoder getPasswordEncoder() { return passwordEncoder; } public void setPasswordEncoder(PasswordEncoder passwordEncoder) { this.passwordEncoder = passwordEncoder; } public PrincipalNameTransformer getPrincipalNameTransformer() { return principalNameTransformer; } public void setPrincipalNameTransformer(PrincipalNameTransformer principalNameTransformer) { this.principalNameTransformer = principalNameTransformer; } public final void setDataSource(final DataSource dataSource) { this.jdbcTemplate = new JdbcTemplate(dataSource); this.dataSource = dataSource; } /** * Method to return the jdbcTemplate * * @return a fully created JdbcTemplate. */ protected final JdbcTemplate getJdbcTemplate() { return this.jdbcTemplate; } protected final DataSource getDataSource() { return this.dataSource; } }
最后把处理类注册到/WEB-INF/deployerConfigContext.xml文件中,替换原有的AuthenticationHandler
<!--<bean class="org.jasig.cas.adaptors.jdbc.QueryDatabaseAuthenticationHandler"> <property name="dataSource" ref="dataSource"></property> <property name="sql" value="select password from t_admin_user where login_name=?"></property> <property name="passwordEncoder" ref="MD5PasswordEncoder"></property> </bean>--> <bean class="com.nbrc.cas.handler.support.NbrcAuthenticationHandler" > <property name="dataSource" ref="dataSource"></property> </bean>
评论
2 楼
zjnbshifox
2013-10-13
呵呵,我也在摸索阶段,谢谢提醒
ligywin 写道
还需要补充以下方法
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.Principal;
import org.jasig.cas.authentication.principal.SimplePrincipal;
public final class NbrcCredentialsToPrincipalResolver implements
CredentialsToPrincipalResolver {
/** Logging instance. */
private final Log log = LogFactory.getLog(getClass());
public Principal resolvePrincipal(final Credentials credentials) {
final NbrcCredentialsciatCredentials = (NbrcCredentials) credentials;
if (log.isDebugEnabled()) {
log.debug("Creating SimplePrincipal for ["
+ ciatCredentials.getUsername() + "]");
}
return new SimplePrincipal(ciatCredentials.getUsername());
}
public boolean supports(final Credentials credentials) {
return credentials != null
&& NbrcCredentials.class.isAssignableFrom(credentials
.getClass());
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.Principal;
import org.jasig.cas.authentication.principal.SimplePrincipal;
public final class NbrcCredentialsToPrincipalResolver implements
CredentialsToPrincipalResolver {
/** Logging instance. */
private final Log log = LogFactory.getLog(getClass());
public Principal resolvePrincipal(final Credentials credentials) {
final NbrcCredentialsciatCredentials = (NbrcCredentials) credentials;
if (log.isDebugEnabled()) {
log.debug("Creating SimplePrincipal for ["
+ ciatCredentials.getUsername() + "]");
}
return new SimplePrincipal(ciatCredentials.getUsername());
}
public boolean supports(final Credentials credentials) {
return credentials != null
&& NbrcCredentials.class.isAssignableFrom(credentials
.getClass());
}
}
1 楼
ligywin
2013-10-11
还需要补充以下方法
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.Principal;
import org.jasig.cas.authentication.principal.SimplePrincipal;
public final class NbrcCredentialsToPrincipalResolver implements
CredentialsToPrincipalResolver {
/** Logging instance. */
private final Log log = LogFactory.getLog(getClass());
public Principal resolvePrincipal(final Credentials credentials) {
final NbrcCredentialsciatCredentials = (NbrcCredentials) credentials;
if (log.isDebugEnabled()) {
log.debug("Creating SimplePrincipal for ["
+ ciatCredentials.getUsername() + "]");
}
return new SimplePrincipal(ciatCredentials.getUsername());
}
public boolean supports(final Credentials credentials) {
return credentials != null
&& NbrcCredentials.class.isAssignableFrom(credentials
.getClass());
}
}
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jasig.cas.authentication.principal.CredentialsToPrincipalResolver;
import org.jasig.cas.authentication.principal.Credentials;
import org.jasig.cas.authentication.principal.Principal;
import org.jasig.cas.authentication.principal.SimplePrincipal;
public final class NbrcCredentialsToPrincipalResolver implements
CredentialsToPrincipalResolver {
/** Logging instance. */
private final Log log = LogFactory.getLog(getClass());
public Principal resolvePrincipal(final Credentials credentials) {
final NbrcCredentialsciatCredentials = (NbrcCredentials) credentials;
if (log.isDebugEnabled()) {
log.debug("Creating SimplePrincipal for ["
+ ciatCredentials.getUsername() + "]");
}
return new SimplePrincipal(ciatCredentials.getUsername());
}
public boolean supports(final Credentials credentials) {
return credentials != null
&& NbrcCredentials.class.isAssignableFrom(credentials
.getClass());
}
}
发表评论
-
jasper report与Spring mvc整合
2015-10-19 16:02 1645配置jasper view resolver <be ... -
solr导入Oracle日期时间数据的处理
2013-02-08 10:01 5162参考文章: http://stackoverflow.com/ ... -
solr服务端加亮设置
2013-02-06 23:25 1314在${solr.home}/conf/solrconfig.x ... -
Solr客户端自定义开发
2013-02-06 16:52 1680@Service @Qualifier(" ... -
CAS 客户端获取Credentials额外信息
2013-02-06 09:40 4001服务端的配置 1、在deployerContext.xml中加 ... -
Spring data MongoDB DSL
2013-01-29 13:38 2609这两天自己配置了一个通过Spring Data来连接Mongo ... -
Spring MVC和freemarker配置
2013-01-21 13:45 2480参考文章:http://www.cnblogs.com/hoo ... -
我自己的maven环境
2013-01-17 14:37 1107今天把自己的maven环境记录下来,准备重装系统能找到 mav ... -
Spring-data jpa学习
2013-01-17 14:25 1820一个早上加一个中午就耗在这里了啊,就一个小问题,让我吐血不已, ... -
今天学会的DetachedCriteria用法
2013-01-12 22:01 10184以前用hibernate,一般都是使用hql语句的,因为和sq ... -
学习SSO-1 Tomcat启用ssl
2012-11-29 10:41 6990根据网上的http://www.kafeitu.me/sso/ ... -
Solr连接数据库
2012-04-10 09:40 6218要建立自己的全文检索 ... -
Solr试用小记
2012-04-10 09:15 15671、下载tomcat7、solr 3.5.0 以及IKAnal ... -
java生成二维码,qrcode
2012-03-22 15:41 7018通过barcode4j生成 @Controller @R ... -
使用HttpClient 4.1.2调用webservice
2012-01-19 14:22 19243下载httpclient,把压缩包里lib目录的所有jar放到 ... -
Spring MVC3 Hibernate3 Annotation 补充
2011-05-30 11:59 1405通过配置文件进行事务声明 app-config.xml & ... -
Spring MVC3 Hibernate3 Annotation
2011-05-30 11:56 1775web.xml <?xml version=&quo ... -
Tomcat Mod_jk负载均衡Session复制的几点补充
2010-02-24 16:49 1336tomcat和mod_jk进行负载均衡的时候,如果要实现Ses ... -
第一次实际应用Spring MVC
2009-11-17 08:37 1599要做一个简单的投票的东西,看spring mvc的文章已经很久 ... -
我的ant脚本
2009-07-27 15:40 1331<?xml version="1.0&qu ...
相关推荐
由于登录界面发生改变,请求参数增加了账号所在的系统名称,所以,登录凭据也不能继续使用UsernamePasswordCredentials,而是要自定义一个包含了系统名称的Credentials,并进行配置让CAS服务器启用这个自定义的...
cas单点登录系统,带源码,可定制开发;CASServer负责完成对用户的认证工作,CASServer需要独立部署,CASServer处理用户名/密码等凭证(Credentials)验证,它可能会到数据库检索一条用户帐号信息,也可能在XML文件中...
标签“源码”意味着文章可能涵盖了CAS的内部实现,包括代码结构、关键类或模块的功能,这对于开发者来说是非常有价值的资源,因为理解源码可以帮助他们自定义CAS以满足特定需求。 另一个标签“工具”暗示CAS作为一...
这个压缩包包含的项目"SpringMVCSecurity-master"很可能是用来演示如何配置和使用Spring Security来实现自定义登录表单、处理无效凭证、基于角色的访问控制以及自定义访问拒绝错误消息的示例代码。 在Spring ...
credentials-java-0.2.4.jar
- **bindAndValidate**: 收集用户在登录页面输入的信息,并封装成 CAS 内部的 `Credentials` 对象。 - **submit**: 调用 `centralAuthenticationService` 的 `grantServiceTicket` 方法来完成认证工作。如果认证成功...
使用 Windows Vista 的凭据提供程序创造自定义的登录体验 Windows Vista 在平台集成方面为开发人员提供了许多新的机会。新的凭据提供程序模型是变动最大的方面之一,由于它的出现,实现操作系统支持的新用户身份验证...
"Laravel开发-credentials"指的是Laravel 5版本中引入的一种高效的身份验证机制,它旨在简化和加强用户认证流程。让我们深入探讨一下这个话题。 首先,Laravel的凭据(Credentials)主要涉及到用户登录时输入的...
Credentials Plugin version:1.11 download from github,and have build it by: Run mvn clean package to create the plugin .hpi file. To install: 1. copy the resulting ./target/credentials.hpi file ...
CAS(Central Authentication Service)则是一个开放源码的身份验证系统,它允许用户通过单一登录(Single Sign-On, SSO)访问多个应用系统,大大简化了用户管理和权限控制。 在"acegi集成CAS示例"中,我们主要探讨...
python库。 资源全名:alibabacloud_credentials-0.0.3.tar.gz
这段代码会打开一个本地Web服务器,引导用户通过Google登录并授权应用访问Gmail API。授权成功后,它会返回认证凭据,这些凭据用于后续的API调用。 现在我们可以编写发送邮件的函数。这里假设我们有一个包含收件人...
pac4j是Java的一个简单而强大的安全引擎,用于对用户进行身份验证,获取其个人资料并管理授权,以保护Web应用程序和Web服务的安全。 它提供了一套完整的。 它基于Java 8,并在Apache 2许可下可用。...
Invalid Login Credentials(解决方案).md
JA-SIG CAS是其最初的开发者,它允许用户通过一个统一的登录界面访问多个相互独立的应用系统,从而简化了用户的登录体验。 CAS Server是CAS的核心组件,它负责处理用户的认证请求。在我们讨论的环境中,CAS Server ...
copy the resulting ./target/credentials.hpi file to the $JENKINS_HOME/plugins directory. Don't forget to restart Jenkins afterwards. 2. or use the plugin management console ...
Windows Credentials Viewer是一款用来查找浏览器存储凭据的小工具,帮助您检索在Firefox,Chrome或Internet Explorer中随时间存储的凭据。 用户友好和干净的界面,该应用程序不需要安装或配置,直接打开就可以使用...
在这个"credentials"项目中,我们可能涉及到的身份验证、授权、密码重置、API令牌管理和用户权限控制等关键概念。 1. **身份验证(Authentication)**:Laravel提供了开箱即用的身份验证系统,包括登录、注册、会话...
3. **桌面应用程序**:对于需要用户登录或需要访问外部资源的桌面应用,`infi.credentials_store`可以用来存储用户的登录信息。 4. **Web服务**:在后端服务器中,它可以帮助安全地存储数据库连接信息、第三方服务...