1

i'm using Grails 2.1.1 in my project, right now i'm using springSecurityService.currentUser to get user credential, etc.

in the past 2 days, my project need some CMS extension and i've stumbled upon Weceem plugins. set things here and there, in the end my project with Weceem plugins is now running, but getting Null Pointer Exception each time the springSecurityService.currentUser method is called.

Without weceem grails-plugin everything is running fine, so i assume there's some settings that i need to make. the question is where and what?

this is my user class

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)
}}

and this is my controller that called the 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]
}
tyrion
  • 23
  • 6
  • What's the NPE you're getting? – doelleri Nov 29 '12 at 01:09
  • i'm not sure since my project is at home and i'm at office right now, but as far as i remember, it was: can't call "person" on a null object... i don't know why the springSecurityService object is not autowired for any reason – tyrion Nov 29 '12 at 08:30
  • here's the error output Error 500: Executing action [list] of controller [grii.PersonController] caused exception: Runtime error executing action Servlet: grails URI: /grii/grails/person/list.dispatch Exception Message: Cannot get property 'person' on null object Caused by: Cannot get property 'person' on null object Class: PersonController At Line: [25] – tyrion Nov 29 '12 at 18:48
  • nobody is using weceem grails plugins?? – tyrion Dec 03 '12 at 13:13

0 Answers0