1

I use Oauth and want to create user but have error

POST http://localhost:4200/proxy/user/createUser 401 (Unauthorized)

In spring i have some configuration

@Configuration
@EnableWebSecurity
public class WebSecurity extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/createUser", "/user/**", "/user/createUser", "proxy/user/createUser").permitAll();
        http.csrf().disable();
        http.formLogin().disable();
        http.authorizeRequests().anyRequest().authenticated();
    }
}

and

@Configuration
@EnableResourceServer
public class ResourceServerConfig extends ResourceServerConfigurerAdapter {

    @Override
    public void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/createUser", "/register", "/token", "/token/createUser", "proxy/user/createUser").permitAll();
        http.requestMatchers()
                .and()
                .authorizeRequests()
                .anyRequest()
                .authenticated();
    }
}

What configuration changes are required to enable access to ../createUser?

1 Answer 1

2

looks like http.authorizeRequests().anyRequest().authenticated() this is creating problem in code. just change in WebSecurity as

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.csrf().disable()
         .authorizeRequests().antMatchers("/createUser", "/user/**", "/user/createUser", "proxy/user/createUser")
         .permitAll()
         .formLogin().disable();

}}`

AND

change in ResourceServerConfig as

http.authorizeRequests() .antMatchers("/createUser", "/register", "/token", "/token/createUser", "proxy/user/createUser") .permitAll();

for details checkout Security-config.

10
  • Still unauthorized Jul 16, 2018 at 13:40
  • Have you made changes in ResourceServerConfig? Jul 16, 2018 at 13:52
  • Yes but i must in Websecurity http.formLogin().disable() because i have error can't resolve method Jul 16, 2018 at 13:57
  • I have also AuthorizationServerConfig maybe this class make conflict Jul 16, 2018 at 13:59
  • can you once try only with end-point with which you are trying i.e use only "proxy/user/createUser" in antMatchers? so that we can atleast know what is happening with this end-point. Thanks Jul 16, 2018 at 14:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.