首页 > 解决方案 > 如何使 Spring Security 对每个包含单词 admin 的 URL 都有效?

问题描述

            .antMatchers("**/admin/**").authenticated()

显然上面的代码不起作用

标签: javaspringspring-security

解决方案


可以参考:https ://www.baeldung.com/spring-security-basic-authentication

   @Override
protected void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
      .antMatchers("/securityNone").permitAll()
      .anyRequest().authenticated()
      .and()
      .httpBasic()
      .authenticationEntryPoint(authenticationEntryPoint);

    http.addFilterAfter(new CustomFilter(),
      BasicAuthenticationFilter.class);
}

PermitAll 应该可以解决您的问题。


推荐阅读