私は本当に奇妙な問題があります。 Grails 1.3.6アプリケーションにspring-security-core 1.0.1をインストールし、チュートリアルに従って設定しました。テーブルは整然と作成され、BootStrap.groovyによって作成されます。私はPostgreSQL 8.4データベースを使用しています - すべてがローカルホスト上で実行されています。さて、ブートストラップは完璧に動作しますが、私は、ログインしようとしたとき、私はGrails spring-security-coreプラグインは、ロールテーブルのユーザ名列を期待しています
org.hibernate.exception.SQLGrammarException: could not execute query
を言う例外を取得し、さらに下:
select
authrole0_.id as id1_,
authrole0_.version as version1_,
authrole0_.authority as authority1_
from
auth_role authrole0_
where
username=?
:
Caused by: org.postgresql.util.PSQLException: ERROR: Column »username« does not exist
失敗したクエリを次のようです
これは問題ありません。これは、auth_roleテーブルにusernameカラムが含まれていないためです。しかし、なぜHibernateはusernameカラムを期待していますか?
これを解決する手掛かりはありますか?
私は、効果のない2つの異なる休止状態選択肢を試しました。私は、テーブルのマッピングが何とか興味をそそられていることに気付きました。ルックアップテーブルもマップされています。残念ながら、プラグインのドキュメントでは、クラスをプラグインで必要としているため、プラグインのマニュアルでは変更する必要はありません。
私のクラスには、そのようになります。
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
}
}
彼らはかなりのプラグインがそれらを作成した方法です。
おかげで、 アル
をカスタマイズすることになるとプラグインは、本当に厄介なようです。代わりに: grails.plugins.springsecurity.authority.className = 'auth.AuthRole' 私が持っていた: grails.plugins.springsecurity.authority.className = 'auth.AuthUser' がそれを固定した後、私は取得次の例外: 2011-01-26 15:35:47,077 [http-9000-1]エラー[/aquaWell].[default] - サーブレットのデフォルトのServlet.service()が例外を投げた groovy.lang.MissingPropertyException:いいえそのようなプロパティは:class:auth.AuthUserの有効化 –