Spring boot Spring boot完全身份验证问题-不确定哪里出了问题

Spring boot Spring boot完全身份验证问题-不确定哪里出了问题,spring-boot,spring-security,Spring Boot,Spring Security,我在使用SpringBoot和maven组装的RESTAPI上进行身份验证时遇到了问题。我根本无法得到认证 以下是我当前的安全配置: @Configuration @EnableGlobalMethodSecurity(prePostEnabled = true) @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Override protec

我在使用SpringBoot和maven组装的RESTAPI上进行身份验证时遇到了问题。我根本无法得到认证

以下是我当前的安全配置:

@Configuration
@EnableGlobalMethodSecurity(prePostEnabled = true)
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
            .antMatchers("/", "/person/getAll").permitAll()
            .anyRequest().authenticated();
    }

    @Autowired
    public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
        auth.inMemoryAuthentication()
            .withUser("user").password("password").roles("USER");
    }
}
这里是“/person/getAll”端点

@RequestMapping("/getAll")
List<Person> getAllPeople()
{
    log.info("Getting all users in system.");
    return repository.findAll();
}

为了每个人的理智-当我使用这个问题中列出的代码时(我得到了数据-即使密码是错误的,哈哈)

从长远来看,我的目标实际上是删除内存中的东西,并执行常规查询以获取凭据,但我只想确保我的东西现在可以正常工作

我在使用SpringBoot和maven组装的RESTAPI上进行身份验证时遇到了问题我根本无法获得身份验证。

我认为您根本无法进行身份验证,因为您没有在Spring安全配置文件中指定在访问页面时必须执行哪种安全性

例如:您可以选择使用httpBasic或formLogin安全性

现在,我在这里看到的是一个实际工作的端点-,但它未经身份验证(因为我在安全配置的Perminal部分列出了它)-

例如,如果您将在Spring安全配置文件中添加httpBasic,您将获得http basic身份验证,但如果您不指定任何安全方法,您将无法获得任何身份验证

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.httpBasic()
        .and()
        .authorizeRequests()
        .antMatchers("/", "/person/getAll").permitAll()
        .anyRequest().authenticated();
}

这里有一个帖子可能会有所帮助。您需要将
.antMatchers(“/person/getAll”).hasRole(“ROLE\u USER”)
放在
antMatchers(“/”)之前。permitAll()
您的antMatchers的顺序很重要,谢谢!!这正是我需要的。
curl user:password@localhost:8080/person/getAll
@Override
protected void configure(HttpSecurity http) throws Exception {
    http.httpBasic()
        .and()
        .authorizeRequests()
        .antMatchers("/", "/person/getAll").permitAll()
        .anyRequest().authenticated();
}