我在我的项目中使用Grails 2.1.1,现在我正在使用springSecurityService.currentUser来获取用户凭据等。
在过去的两天里,我的项目需要一些CMS扩展,我偶然发现了Weceem插件。 在这里和那里设置东西,最后我的Weceem插件项目现在正在运行,但每次调用springSecurityService.currentUser方法时都会得到Null Pointer Exception。
没有weceem grails-plugin一切运行正常,所以我假设有一些我需要做的设置。问题是在哪里和什么?
这是我的用户类
class User {
transient springSecurityService
String username
String password
boolean enabled = true
boolean accountExpired = false
boolean accountLocked = false
boolean passwordExpired = false
Person person
static hasOne = [Person]
static hasMany = [roles: Role]
static constraints = {
username blank: false, unique: true
password blank: false
}
static mapping = {
password column: '`password`'
}
Set<Role> getAuthorities() {
roles as Set
}
def beforeInsert() {
encodePassword()
}
def beforeUpdate() {
if (isDirty('password')) {
encodePassword()
}
}
protected void encodePassword() {
password = springSecurityService.encodePassword(password)
}}
这是我的控制器,它调用了springSecurityService
//show the list of all person
def list = {
//get all the sorting params
params.sort = params.sort ?: 'firstName'
params.order = params.order ?: 'asc'
params.max = params.max ?: 10
params.offset = params.offset ?: 0
def test = springSecurityService.getCurrentUser()
def personList = Person.createCriteria().list (max: params.max, offset: params.offset) {
if (springSecurityService.currentUser.person.affiliate.value != 'Admin'){
eq("affiliate", springSecurityService.currentUser.person.affiliate)
eq("deleted", false)
}
order(params.sort, params.order)
}
render view:'list', model:[persons: personList, personTotal: personList.totalCount]
}