[英]Grails Spring Security querying users which don't have a certain role
[英]Grails spring-security-core plugin expects a username column in the role table
我有一個很奇怪的問題。 我已經在Grails 1.3.6應用程序中安裝了spring-security-core 1.0.1並根據教程進行了配置-表是按順序創建的,並由BootStrap.groovy填充。 我正在使用PostgreSQL 8.4數據庫-整個事情都在我的本地主機上運行。 現在,引導程序可以正常運行,但是當我嘗試登錄時,出現一個異常,上面寫着
org.hibernate.exception.SQLGrammarException: could not execute query
再往下走:
Caused by: org.postgresql.util.PSQLException: ERROR: Column »username« does not exist
失敗的查詢如下:
select
authrole0_.id as id1_,
authrole0_.version as version1_,
authrole0_.authority as authority1_
from
auth_role authrole0_
where
username=?
可以,因為auth_role表不應具有username列。 但是,為什么Hibernate期望一個用戶名列而不應該是一個呢?
有什么線索可以解決這個問題嗎?
我已經嘗試了兩種不同的冬眠方法,但都沒有效果。 我注意到表的映射有點奇怪-查找表也被映射了。 不幸的是,它在插件的文檔中說我不應該更改它,因為插件需要該類。
我的課看起來像這樣:
class AuthUser {
String username
String password
boolean active
boolean accountExpired
boolean accountLocked
boolean passwordExpired
static mapping = {
cache true
username column: '`username`'
password column: '`password`'
}
Set<AuthRole> getAuthorities() {
UserRole.findAllByUser(this).collect { it.role } as Set
}
}
import java.util.Set;
class AuthRole {
String authority
static constraints = {
authority blank: false, unique: true
}
}
import org.apache.commons.lang.builder.HashCodeBuilder
class UserRole implements Serializable {
AuthRole role
AuthUser user
boolean equals(other) {
if (!(other instanceof UserRole)) {
return false
}
other.user?.id == user?.id &&
other.role?.id == role?.id
}
int hashCode() {
def builder = new HashCodeBuilder()
if (role) builder.append(role.id)
if (user) builder.append(user.id)
builder.toHashCode()
}
static UserRole get(long roleId, long userId) {
find 'from UserRole where role.id=:roleId and user.id=:userId',
[roleId: roleId, userId: userId]
}
static UserRole create(AuthRole role, AuthUser user, boolean flush = false) {
new UserRole(role: role, user: user).save(flush: flush, insert: true)
}
static boolean remove(AuthRole role, AuthUser user, boolean flush = false) {
UserRole instance = UserRole.findByRoleAndUser(role, user)
instance ? instance.delete(flush: flush) : false
}
static void removeAll(AuthRole role) {
executeUpdate 'DELETE FROM UserRole WHERE role=:role', [role: role]
}
static void removeAll(AuthUser user) {
executeUpdate 'DELETE FROM UserRole WHERE user=:user', [user: user]
}
static mapping = {
id composite: ['user', 'role']
version false
}
}
它們幾乎是插件創建它們的方式。
謝謝,al
好的,找到它-“啟用”是默認值。 在我的課堂上,我定義了“活動”而不是“啟用”。
似乎在定制時,該插件確實很敏感;-)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.