Grails: Custom Comment Evaluator Using Spring Security Plugin

I am trying to use a comment plugin with Spring Security.

I can not write the right ones

grails.commentable.poster.evaluator

I tried {User.get (springSecurityService.principal.id)}, but from CommentController both users and springSecurity seem to be inaccessible.

What should I do?

+3
source share
2 answers

For springSecurityService.principal.id, since there is no field for dependency injection for springSecurityService, it cannot work, so you need to call a call springSecurityService.principal.id-org.springframework.security.core.context.SecurityContextHolder.context.authentication.principal.id

To fix the problem with the user, you will need the full name of the class with the package. So it should be

{com.yourcompany.yourapp.User.get(org.springframework.security.core.context.SecurityContextHolder.context.authentication.principal.id)}
+4

Burt answer, ,

grails.commentable.poster.evaluator = {

    def principal = org.springframework.security.core.context.SecurityContextHolder.context.authentication?.principal

    if (principal?.hasProperty('id')) {

        def currentUserId = principal.id
        if (currentUserId) {
            com.yourcompany.yourapp.User.get(currentUserId)
        }
    }
}
+3

Source: https://habr.com/ru/post/1760980/


All Articles