截取url需要java配置中的通道

9jyewag0  于 2021-10-10  发布在  Java
关注(0)|答案(1)|浏览(541)

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

  1. <sec:http entry-point-ref="authenticationEntryPoint"
  2. use-expressions="true"
  3. disable-url-rewriting="false">
  4. <!-- ERRORS -->
  5. <sec:intercept-url pattern="/error/**" requires-channel="any"/>
  6. <!-- private -->
  7. <sec:intercept-url pattern="/`private/**" requires-channel="https"/>
  8. </sec:http>

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

  1. @Override
  2. protected void configure(HttpSecurity http) throws Exception {
  3. http.requiresChannel() /**How can specify channels at authorizeRequest level?**/
  4. .channelProcessors(channelProcessors()).and()
  5. .authorizeRequests()
  6. .antMatchers("/error/**")
  7. .permitAll()
  8. .and()
  9. .authorizeRequests()
  10. .antMatchers("/private/**")
  11. .authenticated();
  12. }

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

jmp7cifd

jmp7cifd1#

您还可以在java配置中指定模式。这个 requiresChannel 块与您在中指定的内容无关 authorizeRequests .
这是等效的配置

  1. http
  2. .requiresChannel(channel -> channel
  3. .antMatchers("/error/**").requires(ChannelDecisionManagerImpl.ANY_CHANNEL)
  4. .antMatchers("/private/**").requiresSecure()
  5. );

相关问题