禁止访问指定的资源

时间:2017-09-15 13:08:52

标签: java spring spring-mvc spring-security

我使用spring Security。我正在尝试从profile.jsp重定向。

禁止访问指定的资源。

所以,据我所知,这是因为某处的访问失败。我希望重定向的页面也是profile.jsp。所以,我改变选项,我想重新加载页面。但有一个例外

我在其他主题上看过许多类似的内容,但仍然无法解决

弹簧配置

 <http auto-config="true">
    <intercept-url pattern="/" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')"/>
    <intercept-url pattern="/chat" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')"/>
    <intercept-url pattern="/admin" access="hasRole('ROLE_ADMIN')"/>
    <intercept-url pattern="/profile" access="hasAnyRole('ROLE_USER','ROLE_ADMIN')" />
    <form-login login-page="/login" default-target-url="/chat" authentication-failure-url="/login?error"
                username-parameter="username" password-parameter="password"/>

    <logout logout-success-url="/login?logout"/>
</http>

<authentication-manager alias="authenticationManager">
    <authentication-provider user-service-ref="userDetailsServiceImpl">
        <password-encoder ref="encoder"></password-encoder>
    </authentication-provider>
</authentication-manager>

<beans:bean id="userDetailsServiceImpl"
            class="com.chat.my.service.UserDetailsServiceImpl"></beans:bean>

<beans:bean id="encoder"
            class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder">
    <beans:constructor-arg name="strength" value="11"/>
</beans:bean>

1 个答案:

答案 0 :(得分:0)

尝试添加

<intercept-url pattern="/login*" access="isAnonymous()" />

可能是您的登录页面也希望通过

进行身份验证
<intercept-url pattern="/" access="hasAnyRole('ROLE_USER', 'ROLE_ADMIN')"/>
相关问题