Grails, spring-security-core plugin:使用email登录
来源:互联网 发布:淘宝好评100字通用评论 编辑:程序博客网 时间:2024/06/11 23:49
1. Implement the first requirement – Add an email address property to the user domain
This is really simple, just add the property to the domain class
2. Implement the second requirement – Authenticate using the username or the email
In order to implement this requirement, I will have to implement a new UserDetailsService
3. With the custom service in place, I need to register it in grails-app/conf/spring/resources.groovy by adding
This is really simple, just add the property to the domain class
- package org.customauth
- class CustomUser {
- String username
- String password
- String email
- boolean enabled
- boolean accountExpired
- // *******
- // the rest of the generated class contents
- // *******
- }
2. Implement the second requirement – Authenticate using the username or the email
In order to implement this requirement, I will have to implement a new UserDetailsService
- package org.customauth
- import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
- import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUserDetailsService
- import org.codehaus.groovy.grails.plugins.springsecurity.SpringSecurityUtils
- import org.springframework.security.core.authority.GrantedAuthorityImpl
- import org.springframework.security.core.userdetails.UserDetails
- import org.springframework.security.core.userdetails.UsernameNotFoundException
- class CustomUserDetailsService implements GrailsUserDetailsService {
- static final List NO_ROLES = [new GrantedAuthorityImpl(SpringSecurityUtils.NO_ROLE)]
- UserDetails loadUserByUsername(String username, boolean loadRoles)
- throws UsernameNotFoundException {
- return loadUserByUsername(username)
- }
- UserDetails loadUserByUsername(String username)
- throws UsernameNotFoundException {
- CustomUser.withTransaction { status ->
- CustomUser user = CustomUser.findByUsernameOrEmail(username, username)
- if (!user)
- throw new UsernameNotFoundException('User not found', username)
- def authorities = user.authorities.collect {
- new GrantedAuthorityImpl(it.authority)}
- return new GrailsUser(user.username, user.password, user.enabled,
- !user.accountExpired, !user.passwordExpired, !user.accountLocked,
- authorities ?: NO_ROLES, user.id)
- }
- }
- }
3. With the custom service in place, I need to register it in grails-app/conf/spring/resources.groovy by adding
- beans = {
- userDetailsService(org.customauth.CustomUserDetailsService)
- }
原文:http://mafiadada.iteye.com/blog/1166625
- Grails, spring-security-core plugin:使用email登录
- grails 之 Spring Security Core Plugin 使用
- Grails 之 Acegi Plugin 转移到Spring Security Core Plugin
- 诊断Grails Spring Security Core登录错误的一些方法
- grails之spring-security-core自定义加密方式
- grails+spring Security项目demo
- Spring-Security-core插件使用教程
- 使用Spring Security进行自动登录验证
- 使用Spring Security进行自动登录验证
- Spring Security Core Plugin - 5. 配置到安全URL的请求映射
- spring security 登录验证
- spring Security 登录验证
- Spring security登录原理
- spring security手动登录
- Spring security注销登录
- spring security登录验证
- spring security core哪里有
- 使用spring security 2.0 和extjs 3.0实现web登录
- 【KMP算法详解】
- Detours2.1静态库编译和使用方法
- JVM之---内存区域
- 【转载】TestNG 简易指南
- java的移位操作详解,左移和右移
- Grails, spring-security-core plugin:使用email登录
- mysql 导出数据
- java相关学习小记
- dede5.7非常漂亮的全站透明层载入效果教程附演示
- final 类
- Linux文件系统之文件的读写
- 让VS2005中的fstream支持中文路径文件打开
- VC++ 调用 C#生成DLL的两种方法
- playbook横竖屏处理