错误描述

最近在做黑马的管理系统练习,在使用spring security进行登录验证时报错:Access is denied (user is anonymous); redirecting to authentication entry point

报错信息如下:

在这里插入图片描述
使用的spring-security.xml文件如下:

在这里插入图片描述

错误分析

我在网上查阅了各种导致Access is denied (user is anonymous)的解决办法,都无法解决我的问题,我转换思路,由于我是在未进入登录页面是就出现此异常,说明可能是<security:intercept-url pattern="/**" access="ROLE_USER"/>权限验证拦截导致的,然后我查看我的spring-security.xml中的拦截路径

webapp的目录结构如下:

在这里插入图片描述

由于<security:http pattern="/login.jsp" security="none" ></security:http>中 pattern是读取webapp目录下的资源,我的jsp文件均放在webapp的二级目录pages中,所以login.jsp页面无法被阻止拦截,在访问时被直接拦截。

解决办法

后对配置文件中的路径进行了修改,可正常进入登录页面。

修改后的spring-security.xml如下:

在这里插入图片描述

补充

<security:form-login>中login-page,authentication-success-forward-url,authentication-failure-forward-url读取的均为webapp下资源

Logo

快速构建 Web 应用程序

更多推荐