简体   繁体   English

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

[英]access denied page using spring security not working

I am using the below configuration for access denied page 我正在将以下配置用于拒绝访问页面

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

and then mapped /noAccess to the controller. 然后将/ noAccess映射到控制器。 but when I try to access resource to which i dont have access I get an error page 但是当我尝试访问我无权访问的资源时,出现错误页面

HTTP Status 404 - /mycontext/noAccess in the browser HTTP状态404-浏览器中的/ mycontext / noAccess

though when I type the whole url http://abc.mycompany:8080/mycontext/noAccess I can see the error page. 虽然当我输入整个URL http://abc.mycompany:8080 / mycontext / noAccess时,我可以看到错误页面。 any idea why spring is not redirecting to the controller ? 知道为什么spring不重定向到控制器吗?

I am using below configuration for access denied page in my project and it is working for me. 我正在为我的项目中的拒绝访问页面使用以下配置,它正在为我工​​作。

Make changes according to your need. 根据您的需要进行更改。

<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>

Add the following to your bean configuration. 将以下内容添加到您的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>

Create the following pages and add these to Context folder 创建以下页面并将其添加到Context文件夹

     resourceNotFound.jsp
     uncaughtException.jsp
     dataAccessFailure.jsp

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

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