Spring Security REST Angular

0

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
user image

Dodam, że endpointy w kontrolerach działają bez zarzutu. Jakieś rady? :)

0

localhost:8080/login

Nie zaglądałem do kodu specjalnie ale już od razu widze brak context - roota
Generalnie to działa tak: host:/context-root/mapowany-url
np. jak pisze sobie aplikację expenses manager to na localhoście mam http://localhost:8080/expenses-manager/register
gdzie /register to mapowany już przez controller springa URL a expenses-manager to context-root

0

@scibi92, deployuje na roocie, dlatego brak kontekstu po slashu ;) Jak mówiłem - kontrolery łapią bez problemu mapowanie.

0

W logach widać ze powstaje maping dla /login ?

0

@Szczery, w klasie

RequestMappingHandlerMapping
mam tylko informacje, a po zwiększeniu poziomu logów drukuje jeszcze coś takiego:

2016-07-06 2128 DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for ExactUrl [processUrl='/login']
2016-07-06 2128 DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'permitAll', for ExactUrl [processUrl='/login']
2016-07-06 2128 DEBUG o.s.s.w.a.e.ExpressionBasedFilterInvocationSecurityMetadataSource - Adding web access control expression 'authenticated', for Ant [pattern='/xx/**']

czyli widzi moją konfiguracje :/

0

Dla uściślenia: bezpośrednio info, że "URL mapped /login" nie ma. Jest tylko to wyżej.

1 użytkowników online, w tym zalogowanych: 0, gości: 1