I have implemented Spring boot, with Spring security. And here is how I configure the http requests:
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers( "/registeration").permitAll()
.antMatchers("/home").hasRole("USER")
.anyRequest().authenticated().and()
.formLogin().loginPage("/login").permitAll();
http.formLogin().defaultSuccessUrl("/home", true);
}
So, I am trying to redirect my logged in users to the /home url, and here is the controller:
@GetMapping("/home")
public String home(Model model,@RequestParam Long userId) {
model.addAttribute("user", userService.getUserById(userId));
return "home";
}
But, as you see, I need to pass the userId, to add it as a model into my view. The problem is, I don't know how to retrieve the information of yje user before redirect, and after log in.