带有 DelegatingFilterProxy 的 Spring Security [英] Spring Security with DelegatingFilterProxy

查看:64
本文介绍了带有 DelegatingFilterProxy 的 Spring Security的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个弹簧安全过滤器,如下所示.

I have created a spring security Filter as below.

<!-- Enables Spring Security -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
        org.springframework.web.filter.DelegatingFilterProxy
    </filter-class>
</filter>

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
<!-- End Spring Security -->

<servlet>
    <servlet-name>remoting</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-        
class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/remoting-servlet.xml</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>remoting</servlet-name>
    <url-pattern>/remoting/*</url-pattern>
</servlet-mapping>

<servlet-mapping>
    <servlet-name>remoting</servlet-name>
    <url-pattern>/admin</url-pattern>
</servlet-mapping>

除此之外,我可以保证一切都是正确的.但我唯一的问题是,

And apart from this I can assure everything is correct. But only problem I have is,

当我访问链接 http://localhost:8080/myContext/remoting/Services 时,不会调用 Spring 过滤器进行身份验证,而是直接访问我的服务.

When I access a link http://localhost:8080/myContext/remoting/Services the Spring Filter is not called for authentication but directly it accesses my Services.

当我在 web.xml 中添加以下行时.它工作正常.

When I add the below line in web.xml. It works correctly.

<filter-mapping>
    <filter-name>springSecurityFilterChain</filter-name>
    <url-pattern>/remoting/*</url-pattern>
</filter-mapping>

我有什么疑问,因为我的过滤器映射已经定义为/*.为什么我还要再定义一个过滤器映射.

What doubt I have is since my filter-mapping is already defined as /*. why should I again define one more filter-mapping.

推荐答案

当我在 spring-security.xml 中添加以下代码段时,它对我很成功

It worked for me successfully as I added the below snippet in the spring-security.xml

 <http auto-config="true">
    <intercept-url pattern="/**" access="ROLE_USER" />// pattern was modified to /**
    <http-basic/>
</http>

这篇关于带有 DelegatingFilterProxy 的 Spring Security的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆