1

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

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Another solution could be to use /*/basicauth and it's more general (the mapping before basicauth can be anything). But for authentication purposes it's better in my opinion to use the full endpoint.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.