Spring Security 报错记录

在配置Security完成后,启动服务器 会报

严重: Servlet.service() for servlet [jsp] in context with path [] threw exception
java.lang.IllegalArgumentException: Failed to evaluate expression 'ROLE_SP'

的问题,其中ROLE_SP是我配置的一个权限,自己很纳闷,明明是按照书上的写法写的。

后来发现问题出在这里

    <http auto-config="true" use-expressions="true">
        <form-login login-page="/login"
                login-processing-url="/static/j_spring_security_check"
                authentication-failure-url="/login?login_error=t"/>
        <logout logout-url="/static/j_spring_security_logout"/>
        <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')"/>
        <intercept-url pattern="/login" requires-channel="https"/>
        <intercept-url pattern="/spitter/form" requires-channel="http"/>
        <intercept-url pattern="/**" access="ROLE_SP"/>
    </http>

我在use-expression当中把它置为true,开启这个选项后,要给ROLE_SP赋予权限,就只能用access=hasRole(‘ROLE_SP’)的形式,而不能用

access=”ROLE_SP”的形式,所以,上述的配置文件因改为

    <http auto-config="true" use-expressions="true">
        <form-login login-page="/login"
                login-processing-url="/static/j_spring_security_check"
                authentication-failure-url="/login?login_error=t"/>
        <logout logout-url="/static/j_spring_security_logout"/>
        <intercept-url pattern="/admin/**" access="hasRole('ROLE_ADMIN')"/>
        <intercept-url pattern="/login" requires-channel="https"/>
        <intercept-url pattern="/spitter/form" requires-channel="http"/>
        <intercept-url pattern="/**" access="hasRole('ROLE_SP')"/>
    </http>

你可能感兴趣的:(Spring Security 报错记录)