如何跳过某些路由的安全检查?

问题描述 投票:0回答:1

应用以下配置,我仍然从服务器获取异常

{“ timestamp”:“ 2019-10-13T17:13:41.168 + 0000”,“状态”:401,“错误”:“未经授权”,“ message”:“未经授权”,“路径”:“ /客人/替代”}

路由器

@GetMapping("/guests/alternate")
public String showAny() {
    return "alternate";
}

配置

// For pre-auth
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
@EnableJpaRepositories(basePackageClasses = UsersRepository.class)
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {


    @Autowired
    private CustomUserDetailsService userDetailsService;

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {

        auth.userDetailsService(userDetailsService)
        .passwordEncoder(getPasswordEncoder());
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {

        http.csrf().disable();
        http.authorizeRequests()
                .antMatchers("/guests**").permitAll()
                .antMatchers("**/secured/**").authenticated()
                .anyRequest().permitAll()
                .and()
                .formLogin().permitAll();
    }
java spring spring-mvc java-ee spring-security
1个回答
0
投票

[在尝试重现您的问题时,我遇到了以下AntPathMatcher文档:

**匹配路径中的零个或多个目录

您可以尝试使用.antMatchers("/guests/**").permitAll()代替.antMatchers("/guests**").permitAll()吗?我在末尾添加了一个额外的斜杠。

© www.soinside.com 2019 - 2024. All rights reserved.