【发布时间】:2014-01-21 20:39:39
【问题描述】:
这是我的用户类,上面有 Spring Security
package rms
import java.util.Date;
import java.util.Set;
import enums.EmployeeStatus;
class User {
transient springSecurityService
String username
String password
boolean enabled
boolean accountExpired
boolean accountLocked
boolean passwordExpired
String firstName
String lastName
String middleName
String contactNumber
String position
String emailAddress
String employeeID
Date dateOfBirth
EmployeeStatus employeeStatus
int age
byte [] picture
static hasMany = [employeeReport: EmployeeReport]
static constraints = {
picture maxSize:20* 1024 * 1024
dateOfBirth nullable: true
employeeStatus blank: false
position blank: false
contactNumber blank: false
emailAddress blank: false, matches: "([a-z0-9_.-]+)@([da-z.-]+).([a-z.]{2,6})", email: true
age min: 18
username blank: false, unique: true
password blank: false, password: true
}
static mapping = { password column: '`password`' }
Set<SecRole> getAuthorities() {
SecUserSecRole.findAllBySecUser(this).collect { it.secRole } as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}
String toString(){
return "SecUser $username"
}
}
我试过这个标签<sec:loggedInUserInfo field="username"/>,它工作正常,但这不起作用<sec:loggedInUserInfo field="firstName"/>。它给出了一个
没有这样的属性:类的名字:org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
有没有其他方法可以显示当前登录用户的其他属性?
【问题讨论】:
-
<sec:loggedInUserInfo field="username"/>用于 Spring Security 定义的字段,如用户名、启用等,而不用于开发人员定义的其他字段。