views:

69

answers:

1

I am trying to use the commentable plugin with Spring Security.

I can't manage to write the right

grails.commentable.poster.evaluator

I tried {User.get(springSecurityService.principal.id)}, but from the CommentController, both User and springSecurity seems unaccessible.

What should I do?

+1  A: 

For springSecurityService.principal.id since there's no dependency injection field for springSecurityService it can't work, so you need to call what springSecurityService.principal.id calls - org.springframework.security.core.context.SecurityContextHolder.context.authentication.principal.id

To fix the problem with User, you'll need the full class name with package. So combined, this should be

{com.yourcompany.yourapp.User.get(org.springframework.security.core.context.SecurityContextHolder.context.authentication.principal.id)}
Burt Beckwith
Thank you very much for your help and the very quick answer. In the meantime, I wrote a small plugin that adds a getCurrentUser to each controller. Then I use the currentUser in the evaluator. It seems to workIs that a bad idea? (I am new to both Groovy and Grails, so wouldn't know if it is an anti-idiom to add this kind of methods)
Nicolas Oury
That reminded me that there's already a `getPrincipal()` method added by Spring Security Core, so that would shorten the call to `com.yourcompany.yourapp.User.get(principal.id)`, but it would be better to also have a `getCurrentUser` method - I'll add that for the next release.
Burt Beckwith