安裝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 –