springSecurityService missed in domain

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

springSecurityService missed in domain

Vladimir Havenchyk
Hi, I'm using grails 2.2.4 and have file sructure:

under src/groovy
  BaseEntity {
      def springSecurityService
   
      static transients = ['springSecurityService']
  }

Under grails-app/domain

  CustomEntity {
    transient springSecurityService

    //use springSecurityService in custom validation
  }

and when I invoke springSecurityService.getCurrentUser() from CustomEntity, I got

Stacktrace follows:
groovy.lang.MissingPropertyException: No such property: springSecurityService for class ...

Any suggestions, how to solve it?
Reply | Threaded
Open this post in threaded view
|

Re: springSecurityService missed in domain

Vladimir Havenchyk
Sorry, forgot extends

 CustomEntity extends BaseEntity {
    transient springSecurityService

    //use springSecurityService in custom validation
  }
Reply | Threaded
Open this post in threaded view
|

Re: springSecurityService missed in domain

burtbeckwith
You have 2 fields of the same name, and only one will be set. If you want the service to be available in all subclasses, remove the field from the subclasses and leave just the one in the base class. If you only need it in the subclass(es) remove it from the base class.

This has nothing to do with Spring Security - it's a general Java/Groovy issue.

Burt

Vladimir Havenchyk wrote
Sorry, forgot extends

 CustomEntity extends BaseEntity {
    transient springSecurityService

    //use springSecurityService in custom validation
  }
Reply | Threaded
Open this post in threaded view
|

Re: springSecurityService missed in domain

Vladimir Havenchyk
Thanks, Burt, but I still can't fix it. More details
 
  CustomEntity extends BaseEntity {

    static belongsTo = [privateInfo: PrivateInfo]

    static constraints = {
        privateInfo(nullable: true, validator: customInfoValidator)
    }

    static customInfoValidator = { val, obj ->
        def currentUser = springSecurityService.currentUser
        println "********************************"
    }
}

And in this case I got same exception. I use spring security core 1.2.7.3
Reply | Threaded
Open this post in threaded view
|

Re: springSecurityService missed in domain

Vladimir Havenchyk
Ok, I think, I should validate privateInfo in PrivateInfo domain, right?
Reply | Threaded
Open this post in threaded view
|

Re: springSecurityService missed in domain

burtbeckwith
In reply to this post by Vladimir Havenchyk
You can't access instance variables from static methods or closures. But "obj" is the instance being validated, so you can change that to

   def currentUser = obj.springSecurityService.currentUser

Burt

Vladimir Havenchyk wrote
Thanks, Burt, but I still can't fix it. More details
 
  CustomEntity extends BaseEntity {

    static belongsTo = [privateInfo: PrivateInfo]

    static constraints = {
        privateInfo(nullable: true, validator: customInfoValidator)
    }

    static customInfoValidator = { val, obj ->
        def currentUser = springSecurityService.currentUser
        println "********************************"
    }
}

And in this case I got same exception. I use spring security core 1.2.7.3