acegi Grails 开发应用 不过有个问题 搞不明白 注册用户 始终无法登陆
来源:互联网 发布:最新理财软件 编辑:程序博客网 时间:2024/06/04 18:44
Basic Tutorial using Requestmap
There are three ways to define security mappings - see Securing URLs for more details. This tutorial uses the Requestmap approach. To use Controller annotations, use this tutorial and to specify security mappings using the standard Spring Security approach use this tutorial.
Create your Grails application
# grails create-app bookstore
# cd bookstore
Install the Spring Security plugin
# grails install-plugin acegi
Create the User, Role, and Requestmap domain classes
# grails create-auth-domains User Role Requestmap
You can choose other names for User, Role, and Requestmap, and can create them in packages; these are just examples.
Note: Depending on your database, some names might not be valid. Thisgoes for any domain classes you create, but names for security seem tohave an affinity towards trouble. So before you use names like "User"or "Group", make sure they are not reserved keywords in your database:)
The script will create this User class:
/**
* User domain class.
*/
class User {
static transients = ['pass']
static hasMany = [authorities: Role]
static belongsTo = Role/** Username */
String username
/** User Real Name*/
String userRealName
/** MD5 Password */
String passwd
/** enabled */
boolean enabledString email
boolean emailShow/** description */
String description = ''/** plain password to create a MD5 password */
String pass = '[secret]'static constraints = {
username(blank: false, unique: true)
userRealName(blank: false)
passwd(blank: false)
enabled()
}
}
and this Role class:
/**
* Authority domain class.
*/
class Role {static hasMany = [people: User]
/** description */
String description
/** ROLE String */
String authoritystatic constraints = {
authority(blank: false, unique: true)
description()
}
}
and this Requestmap class:
/**
* Request Map domain class.
*/
class Requestmap {String url
String configAttributestatic constraints = {
url(blank: false, unique: true)
configAttribute(blank: false)
}
}
Optional - create controllers and GSPs for User, Role, and Requestmap domain classes
# grails generate-manager
will create:
- grails-app/controllers/RequestmapController.groovy
- grails-app/controllers/RoleController.groovy
- grails-app/controllers/UserController.groovy
- grails-app/views/requestmap/create.gsp, edit.gsp, list.gsp, view.gsp
- grails-app/views/role/create.gsp, edit.gsp, list.gsp, view.gsp
- grails-app/views/user/create.gsp, edit.gsp, list.gsp, view.gsp
Note that these generated files are not part of the plugin - theseare application files. So you're free to edit them however you like -they're examples to get you started. You could also generate standardGrails controllers and GSPs using
# grails generate-all User
# grails generate-all Role
# grails generate-all Requestmap
although for this tutorial I assume you're using the plugin-generated files.
Optional - create controllers and GSPs for Captcha, Register, and an Emailer Service.
# grails generate-registration
will create:
- grails-app/controllers/CaptchaController.groovy
- grails-app/controllers/RegisterController.groovy
- grails-app/services/EmailerService.groovy
- grails-app/views/register/edit.gsp, index.gsp, show.gsp
Again note that these generated files are not part of the plugin -these are application files that you're free to edit and customize.
Create a controller that will be restricted by role
# grails create-controller Secure
This will create grails-app/controllers/SecureController.groovy - add some output so we can verify that things are working:
class SecureController {
def index = {
render 'Secure access only'
}
}
Start the server
# grails run-app
Before we secure the page, navigate to http://localhost:8080/bookstore/secure to verify that you can see the page without being logged in:
Navigate to http://localhost:8080/bookstore/role/create and create an 'admin' role:
then navigate to http://localhost:8080/bookstore/requestmap/create and create the mapping for SecureController:
URL: /secure/**
Role: ROLE_ADMIN
Note: If your controller class names havea capital letter in the name (other than the first character, e.g.BigCar or BigTruck), then the url you provide here should be somethinglike "/bigcar/**" or "/bigtruck/**". The url you would expect to put in(i.e. "/bigCar/**" or "/bigTruck/**") will not work since the defaultbehavior is to convert the url to lowercase before comparing withsecurity rules.
and finally navigate to http://localhost:8080/bookstore/user/create to create a test user:
Now navigate again to http://localhost:8080/bookstore/secure and this time, you should be presented with the login page:
Log in with the username and password you used for the test user, and you should again be able to see the secure page:
When logging in, you can test the RememberMe functionality. Check the checkbox, and once you've tested the securepage close your browser and re-open it. Navigate again the the securepage, and since you have a cookie stored, you shouldn't need to log inagain. Logout at any time by navigating to http://localhost:8080/bookstore/logout
- acegi Grails 开发应用 不过有个问题 搞不明白 注册用户 始终无法登陆
- 始终搞不懂的问题!!!
- acegi中文登陆账号问题
- shopNC注册后无法登陆的问题
- 基于openfire+smack开发Android即时聊天应用[二]-用户注册、登陆、修改密码、注销等
- 基于openfire+smack开发Android即时聊天应用[一]-用户注册、登陆、修改密码、注销等
- 基于openfire+smack开发Android即时聊天应用[一]-用户注册、登陆、修改密码、注销等
- Fedora12 Ubuntu root用户无法登陆问题
- 解决Genymotion无法注册,无法登陆的问题
- android 登陆、注册、并个指定用户充值
- 栈,进制转换(用数组输出) 有个问题不明白,请高人指点
- dlopen,dlsym的问题,实在搞不明白了。
- 装入地图,不过有问题
- scott用户无法登陆
- 使用STS开发Grails应用
- 使用STS开发Grails应用
- 项目开发登陆注册
- 用户注册登陆查询界面
- C#解析Json的类{经典}【转】
- 一些不错的sql语句
- DELPHI快捷键
- 上下拉电阻的使用
- JS讀取XML
- acegi Grails 开发应用 不过有个问题 搞不明白 注册用户 始终无法登陆
- 绿色供应链为我们带来灵感
- JS event使用方法
- 多边形背面剔除
- 今天学习了ECSide这个开源列表组件.
- 关于eXtremeComponents 导出excel 的问题
- 关于三极管和场效应管
- opencv的图象格式IplImage 和CBitmap的转换
- SHELL笔试题