Hej,
walcze z autentykacją na linii frontend AngularJS - REST w Springu. Kiedyś bawiłem się z Bootem i sprawnie mi to poszło, niestety chcąc wszystko konfigurować nie jest tak kolorowo.
Moja klasa security:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(securedEnabled = true, prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private AuthEntryPoint authenticationEntryPoint;
@Autowired
private AuthFailureHandler authenticationFailureHandler;
@Autowired
private AuthSuccessHandler authenticationSuccessHandler;
@Bean
@Override
public AuthenticationManager authenticationManagerBean() throws Exception {
return super.authenticationManagerBean();
}
@Override
protected void configure(AuthenticationManagerBuilder builder) throws Exception {
builder.inMemoryAuthentication().withUser("user").password("user").roles("USER").and().withUser("admin")
.password("admin").roles("ADMIN");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
final HttpSessionCsrfTokenRepository tokenRepository = new HttpSessionCsrfTokenRepository();
tokenRepository.setHeaderName("X-XSRF-TOKEN");
http.authorizeRequests().antMatchers("/xx/**").authenticated()
.and().csrf().csrfTokenRepository(tokenRepository)
.and().exceptionHandling().authenticationEntryPoint(authenticationEntryPoint)
.and().formLogin().successHandler(authenticationSuccessHandler)
.failureHandler(authenticationFailureHandler).permitAll()
.and().addFilterAfter(new CsrfHeaderFilter(), CsrfFilter.class);
}
A następnie z poziomu czy to sztucznego klienta REST czy z Angulara wysyłam POST na localhost:8080/login (stoję na Tomcacie) i otrzymuję soczyste 404
Dodam, że endpointy w kontrolerach działają bez zarzutu. Jakieś rady? :)