Reputation: 185
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
Upvotes: 1
Views: 4701
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