Code Lღver
Code Lღver

Reputation: 185

Http failure response for http url: 401 Unauthorized

When ever I use the following method I am able to call my service from angular

   @Override
    protected void configure(HttpSecurity http) throws Exception{
        http.csrf().disable().authorizeRequests().antMatchers("/").permitAll();
    }

but when I change the configure method as below I am getting 401 error.

@Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity.csrf().disable()
                // dont authenticate this particular request
                .authorizeRequests().antMatchers("/authenticate", "/register","/basicauth").permitAll().
                // all other requests need to be authenticated
                        anyRequest().authenticated().and().
                // make sure we use stateless session; session won't be used to
                // store user's state.
                        exceptionHandling().authenticationEntryPoint(jwtAuthenticationEntryPoint).and().sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS);

        // Add a filter to validate the tokens with every request
        httpSecurity.addFilterBefore(jwtRequestFilter, UsernamePasswordAuthenticationFilter.class);
    }

How to overcome this problem.

my error as below

enter image description here

Upvotes: 1

Views: 4701

Answers (1)

user1234SI.
user1234SI.

Reputation: 1860

You need to specify the entire endpoint in antMatchers(). As far as I can see, the url you're trying to reach is .../api/v1/basicauth => change the /basicauth string to /api/v1/basicauth.

Upvotes: 1

Related Questions