有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java配置中的Spring安全5拦截URL请求通道

我正在基于WebSecurityConfigureAdapter将xml Spring安全配置迁移到Java配置。在xml配置中,我可以指定每个截取url需要的通道,例如:

<sec:http entry-point-ref="authenticationEntryPoint"
          use-expressions="true"
          disable-url-rewriting="false">

    <!-- ERRORS -->
    <sec:intercept-url pattern="/error/**" requires-channel="any"/>

    <!-- private -->
    <sec:intercept-url pattern="/`private/**" requires-channel="https"/>
</sec:http>

在我的java配置中,我有如下内容:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.requiresChannel()          /** How can specify channels at authorizeRequest level?  **/
            .channelProcessors(channelProcessors()).and()
            .authorizeRequests()
            .antMatchers("/error/**")
            .permitAll()
            .and()
            .authorizeRequests()
            .antMatchers("/private/**")
            .authenticated();
}

如何在授权请求级别指定通道

问候


共 (1) 个答案

  1. # 1 楼答案

    您还可以在Java配置中指定模式。requiresChannel块与您在authorizeRequests中指定的内容无关

    这是等效的配置

    http
        .requiresChannel(channel -> channel
            .antMatchers("/error/**").requires(ChannelDecisionManagerImpl.ANY_CHANNEL)
            .antMatchers("/private/**").requiresSecure()
        );