繁体   English   中英

使用Spring Security的访问被拒绝的页面不起作用

[英]access denied page using spring security not working

我正在将以下配置用于拒绝访问页面

 <security:access-denied-handler error-page="/noAccess"/>

然后将/ noAccess映射到控制器。 但是当我尝试访问我无权访问的资源时,出现错误页面

HTTP状态404-浏览器中的/ mycontext / noAccess

虽然当我输入整个URL http://abc.mycompany:8080 / mycontext / noAccess时,我可以看到错误页面。 知道为什么spring不重定向到控制器吗?

我正在为我的项目中的拒绝访问页面使用以下配置,它正在为我工​​作。

根据您的需要进行更改。

<security:http auto-config="true" use-expressions="true" access-denied-page="/accessDenied.jsp">

        <security:form-login login-page="/index.jsp"
            default-target-url="/jsp/home.jsp" />


        <security:intercept-url pattern="/jsp/listInBetweenPlaces.jsp"
            access="permitAll" />
</security:http>

将以下内容添加到您的bean配置中。

  <mvc:view-controller path="/uncaughtException"/>
  <mvc:view-controller path="/resourceNotFound"/>
  <mvc:view-controller path="/dataAccessFailure"/>

 <bean class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"    p:defaultErrorView="uncaughtException">
    <property name="exceptionMappings">
        <props>
            <prop key=".DataAccessException">dataAccessFailure</prop>
            <prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
            <prop key=".TypeMismatchException">resourceNotFound</prop>
            <prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
        </props>
    </property>
</bean>

创建以下页面并将其添加到Context文件夹

     resourceNotFound.jsp
     uncaughtException.jsp
     dataAccessFailure.jsp

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM