Spring Security 基本认证

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

在这里遇到春季安全问题:

我需要:

  1. /new-pathx/**
    与基本身份验证
  2. /health
    允许所有。
  3. 其他路径:anyRequest().authenticated()

我是这样做的:

  protected void configure(HttpSecurity http) throws Exception {
    http
      .antMatcher("/new-pathx/**")
      .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and()
      .csrf().disable()
      .httpBasic().and()
      .authorizeRequests()
      .antMatchers("/health").permitAll()
      .anyRequest()
      .authenticated();
    
  }

  @Override
  protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth
      .inMemoryAuthentication()
      .withUser(apiUser)
      .password(passwordEncoder.encode(apiPassword))
      .roles("API_USER");
  } 

Works OK for the

/new-pathx/**
I can only enter with the user and password.但是我可以在没有任何身份验证的情况下进入任何其他路径。

我的代码有什么问题?

java spring security
© www.soinside.com 2019 - 2024. All rights reserved.