Je tente de sécuriser une application qui utiliser rest.
J'utilise spring boot, spring security, spring rest, spring-data-jpa dans une SPA (single page application).
Avec spring quand on tape l'adresse du serveur, la page par défaut est index.html, il y a t'il moyen de changer cela pour login.html?
Ma page de connexion est login.html
Dans la méthode configure de ma classe qui étend WebSecurityConfigurerAdapter
Toute mes page ont besoin d'être authentifié excepté ma page de login.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable() .authorizeRequests() .anyRequest().authenticated(); http .formLogin() .loginPage("/login.html") .permitAll() .and() .logout() .permitAll().logoutSuccessUrl("/login.html"); http.exceptionHandling().authenticationEntryPoint(authenticationEntryPoint); http.formLogin().successHandler(authenticationSuccessHandler); http.formLogin().failureHandler(authenticationFailureHandler); }
Quand je fais un post de mon écran de connexion
J'obtiens
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 $('#loginform').submit(function (event) { event.preventDefault(); var data = 'username=' + $('#username').val() + '&password=' + $('#password').val(); $.ajax({ data: data, timeout: 1000, type: 'POST', url: '/login' }).done(function (data, textStatus, jqXHR) { window.location = "index.html"; }).fail(function (jqXHR, textStatus, errorThrown) { alert("fail"); }); });
http://localhost:8080/login 401 (Unauthorized)
une idée?
Partager