Dasma
Dasma

Reputation: 1263

Spring security Annotation expected to be inline constant

I get below error in grails when I try to define my String outside @Secured annotation.

I get following error Role.USER' to be an inline constant of type java.lang.String not a property expression in @grails.plugin.springsecurity.annotation.Secured

class Role {
    final static String USER = "ROLE_USER"
    final static String ADMIN = "ROLE_ADMIN"


    public final static String[] LOGINED_USER = [USER, ADMIN].asImmutable()

}

The below controller illustrate my issue..

class MyController {

    @Secured(["permitAll"]) //Works fine
    def action1() {
    }


    @Secured(LOGINED_USER) //Doesn't work
    def action2() {
    }

    @Secured([Role.ADMIN, Role.USER]) //Doesn't work
    def action3() {
    }


    @Secured(["ROLE_ADMIN", "ROLE_USER"]) //Works fine
    def action4() {
    }
}

Upvotes: 0

Views: 3779

Answers (1)

Dmitry
Dmitry

Reputation: 902

You have to make USER and ADMIN constants public explicitly, add public modifier

public final static String USER = "ROLE_USER"
public final static String ADMIN = "ROLE_ADMIN"

In that case Groovy will not use geters setter which is not allowed in annotations.

Upvotes: 5

Related Questions