为什么这个 Spring rest API 强制执行用户名而不是密码

Why does this Spring rest API enforce username but not password

当我使用 postman 向

提交 get 请求时

`http://localhost:8080/students/

如果我使用凭据 admin1 123,我会收到 401 错误。

如果我使用凭据 admin 123,则需要 returns 用户列表。

如果我使用凭据 admin 1234,请求还会 returns 用户列表。

我没有正确验证密码吗?

      @EnableWebSecurity
    public class SecurityConfig extends WebSecurityConfigurerAdapter {

        @Bean
        @Override
        public UserDetailsService userDetailsService() {
            UserDetails user = User.withDefaultPasswordEncoder()
                    .username("admin")
                    .password("123")
                    .roles("ADMIN")
                    .build();
            return new InMemoryUserDetailsManager(user);
        }

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.httpBasic().and().authorizeRequests()
                    .antMatchers("/user/**").hasRole("ADMIN")
                    .and().csrf().disable().headers().frameOptions().disable();
        }
    }


    @RestController
public class StudentResource {

    @Autowired private StudentRepository studentRepository;

    @GetMapping("/students")
    public List<Student> retrieveAllStudents() {
        return studentRepository.findAll();
    }

}

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    @Bean
    @Override
    public UserDetailsService userDetailsService() {
        UserDetails user = User.withDefaultPasswordEncoder()
                .username("admin")
                .password("123")
                .roles("ADMIN")
                .build();
        return new InMemoryUserDetailsManager(user);
    }

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.httpBasic().and().authorizeRequests()
                .antMatchers("/user/**").hasRole("ADMIN")
                .and().csrf().disable().headers().frameOptions().disable();
    }
}

@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {

}


data.sql
        insert into student
        values(10001,'Ranga', 'E1234567');

        insert into student

控制器中的路径与配置中的路径不匹配。