首页 > 解决方案 > 发布具有基本身份验证的用户

问题描述

我正在使用 OAuth2 和 JWT 身份验证来访问我的 Spring Boot 应用程序的资源。我不想限制新用户的发布,但我想添加基本身份验证以及我的客户端应用程序可以发送的用户和密码。我尝试使用httpBasic()并添加域名,但在 Postman 中我仍然可以不受限制地发布用户。

这是我的资源服务器:

@Configuration
@EnableResourceServer
public class ResourceServer extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http
            .authorizeRequests()
                .antMatchers(HttpMethod.GET, "api/users").permitAll()
                .antMatchers(HttpMethod.GET,"/api/users/{id}","/api/rols" ).hasRole("ADMIN")
                .antMatchers(HttpMethod.POST,"/api/users" ).permitAll()
            //  .and()
            //.httpBasic()
            //    .realmName("My realm");
    }
}

标签: javaspringspring-bootspring-security

解决方案


推荐阅读