当前位置: 首页 > 知识库问答 >
问题:

如何在Spring Security中删除默认筛选器堆栈中的一个筛选器?

任绪
2023-03-14
public class CustomFilterChainProxy extends FilterChainProxy {

Logger LOGGER = Logger.getLogger(CustomFilterChainProxy.class);

public CustomFilterChainProxy() {
    super();
    LOGGER.debug("Run custom filter proxy");
    LOGGER.debug("String filters: " + this.toString());
}

public CustomFilterChainProxy(SecurityFilterChain chain) {
    super(chain);
    LOGGER.debug("Run custom filter proxy with chains");
}
}

正如您所看到的,它有一个构造函数,它可以得到过滤器列表,所以我可以根据需要从链中删除一个过滤器,其余的都可以正常工作。但是我不能为这样的构造函数在安全配置中创建bean。如果我使用

<bean id="filterChainProxy" class="com.pkg.CustomFilterChainProxy">

当然,它使用默认构造函数构建对象。好的,我试着用一些过滤器的列表来制作bean:

<bean id="filterChainProxy" class="ru.olekstra.backoffice.util.CustomFilterChainProxy">
<constructor-arg>
    <list>
        <sec:filter-chain pattern="/**" 
        filters="BasicUserApprovalFilter" />
    </list>
</constructor-arg>
</bean>

但这无法编译,因为BasicUserApprovalFilter是未知bean。那么如何从默认筛选器堆栈中排除一个筛选器呢?如果我用自定义过滤链代理的方式是好的决定,那么如何用默认的过滤链创建bean呢?

共有1个答案

宋志学
2023-03-14

如果您提供更多关于您想要删除的过滤器以及为什么要删除的细节,可能会有所帮助。

如果愿意,可以使用BeanPostProcessor在创建筛选器链后修改它。在默认命名空间配置中,可以为 元素创建的筛选器链指定一个名称:

<http name="myFilterChain">
   ...

这将注册一个SecurityFilterChain类型的bean。FilterChainProxy是从以下列表中创建的。

public class SecurityFilterChainPostProcessor implements BeanPostProcessor {

    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        if (beanName.equals("myFilterChain")) {
            DefaultSecurityFilterChain fc = (DefaultSecurityFilterChain)bean;
            List<Filter> filters = fc.getFilters();

            // Modify the filter list as you choose here.                
            List<Filter> newFilters = ...

            return new DefaultSecurityFilterChain(fc.getRequestMatcher(), newFilters);
        }

        return bean;
    }

    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        return bean;
    }
}
 类似资料:
  • 问题内容: 我必须从Spring Security堆栈中排除一个默认过滤器。因此,所有过滤器都应照常工作。看来我找到了解决方法,请创建自定义FilterChainProxy: 如您所见,它具有获取过滤器列表的构造函数,因此我将能够根据需要从链中删除一个过滤器,其余所有过滤器将照常工作。但是我不能在这样的构造函数的安全配置中制作bean。如果我用 当然,使用默认构造函数构建对象。好的,我尝试用一​​

  • 首先,我试图使选择所有复选框,如果我单击表头中的选择所有复选框,整个表行将选择并显示一个复选框反向消息,即我选择了多少复选框。这里的问题是,如果我单击select all复选框,反向消息不会显示楼上的表,即我选择了多少行。 其次,如果我从任何列中筛选任何数字,相同的数字将显示同一列中有多少行具有相同的数字。如果我选中了所有复选框,那么反向消息将显示我选中了多少行复选框。这里,问题是显示整个表行计数

  • 对于Spring Integration FTP入站通道适配器,如果我没有显式设置,是否可以使用远程过滤器的值作为默认值? 例如,在我的用例中,远程目录包含、等,模式将让我成功下载所有这些文件。但是,如果我的本地目录包含附加文件,例如,则将生成、和s的所有3个文件。 我认为,如果本地筛选器默认情况下尊重远程筛选器(如果我没有显式设置),即只生成和两条消息,则更有意义。

  • 有什么建议吗?

  • 筛选器。 Usage 全部引入 import { Picker } from 'beeshell'; 按需引入 import Picker from 'beeshell/dist/components/Picker'; Examples Code import { Picker } from 'beeshell'; <Picker ref={(c) => { this._pick

  • 我在lexer语法文件中编写并用antlr4编译它。上面说 看来“filter”只适用于ANTLR3 我查了wikihttp://www.antlr.org/wiki/display/antlr4/options,没有找到答案。“filter”关键字也不在源文件https://github.com/antlr/antlr4/blob/master/tool/src/org/antlr/v4/too