I have a problem which is I can’t login even I authorize login path in webConfiguration so please can someone help me to solve this issue and thank you.
User.Controller
@PostMapping("/login")
public ResponseEntity login(@Valid @RequestBody LoginRequest data) {
try {
String username = data.getUsername();
authenticationManager.authenticate(new UsernamePasswordAuthenticationToken(username, data.getPassword()));
String token = jwtTokenProvider.createToken(username, this.utilisateurRepository.findByUsername(username).getRoles());
Map<Object, Object> model = new HashMap<>();
model.put("username", username);
model.put("token", token);
return ok(model);
} catch (AuthenticationException e) {
throw new BadCredentialsException("Invalid email/password supplied");
}
WebSecurityConfigure
@Override
protected void configure(HttpSecurity http) throws Exception {
http.cors().and()
.csrf().disable()
.exceptionHandling().authenticationEntryPoint(unauthorizedHandler)
.and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)
.and()
.authorizeRequests()
.antMatchers( "/user/login/**","/","/signup/**","/logout/**")
.permitAll()
.antMatchers("/facture/all/**").permitAll()
.antMatchers("/user/add/**").permitAll()
.antMatchers("/user/all/**").hasAuthority("ADMIN")
.anyRequest().authenticated()
.and()
.addFilter(new JWTAuthenticationFilter(authenticationManager()))
.addFilterBefore(new JWTAuthorizationFilter(), UsernamePasswordAuthenticationFilter.class);
}
POST.method
{
"username":"admin",
"password":"1100"
}
Postman.result
{
“timestamp”: “2020-04-09T00:29:58.982+0000”,
“status”: 500,
“error”: “Internal Server Error”,
“message”: “No message available”,
“trace”: "java.lang.StackOverflowError\r\n\tat org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$UserDetailsServiceDelegator.loadUserByUsername(WebSecurityConfigurerAdapter.java:449)\r\n\tat org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$UserDetailsServiceDelegator.loadUserByUsername(WebSecurityConfigurerAdapter.java:449)\r\n\tat org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$UserDetailsServiceDelegator.loadUserByUsername(WebSecurityConfigurerAdapter.java:449)\r\n\tat org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter$UserDetailsServiceDelegator. “path”: “/user/login”
}