安装Spring Security的核心不记录作为插件然后做快速入门春季安全Grails核心在
这里是我的用户领域类
package auth
class User {
def springSecurityService
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static mapping = {
// password is a keyword in some sql dialects, so quote with backticks
// password is stored as 44-char base64 hashed value
password column: '`password`', length: 64
}
static constraints = {
username blank: false, size: 1..50, unique: true
password blank: false, size: 8..100
}
Set getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected encodePassword() {
password = springSecurityService.encodePassword(password, username)
}
}
而且我boostrap.groovy是
class BootStrap {
def init = { servletContext ->
auth.User james = new auth.User(username: 'test', enabled: true, password: 'password')
james.save()
if (james.hasErrors())
{
println("he has errors")
}
println("we made it! ")
}
def destroy = {
}
}
但当我登录时,它会一直说“对不起,我们无法找到具有该用户名和密码的用户。”有什么想法吗?
所以我使用intellij和使用tomcat插件。还使用内存数据库。这只是涉及到删除和添加tomcat插件? – Badmiral
不,我不这么认为。但是,另一个人问了一个类似的问题,并说清理该项目帮助:http://stackoverflow.com/questions/18985126/grails-2-3-0-view-rendering-issue/18985225#18985225 –