For Cors handling with spring security, you should have a CorsConfigurationSource
in your class that extends WebSecurityConfigurerAdapter
like the following.
@Bean
public CorsConfigurationSource corsConfigurationSource() {
final CorsConfiguration configuration = new CorsConfiguration();
configuration.applyPermitDefaultValues();
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
source.registerCorsConfiguration("/**", configuration);
return source;
}
As for getting angular to recognize the authenticated user, you most likely want to have a controller in Spring that returns the status of the login. Remember to enable cors on this method as well.
@CrossOrigin
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String login(Model model, String error, String logout) {
if (error != null) {
model.addAttribute("error", "Your username and password is invalid.");
}
if (logout != null) {
model.addAttribute("message", "You have been logged out successfully.");
}
return "login";
}
Hope this helps.