Je crée une application Web d'entreprise, j'ai créé ma page de connexion personnalisée, mais d'une manière ou d'une autre, seule la page de connexion de sécurité de printemps arrive à la place de ma page de connexion personnalisée. Voici ma classe de configuration de sécurité.
Veuillez aider.
@Configuration @EnableWebSecurity public class SecurityConfiguration extends WebSecurityConfigurerAdapter { @Autowired public void configureGlobalSecurity(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().withUser("test").password("pwd123") .roles("USER", "ADMIN"); } @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/login").permitAll() .antMatchers("/", "/*todo*/**").access("hasRole('USER')").and() .formLogin(); http.csrf().disable(); }
3 Réponses :
Vous devez spécifier l'URL de votre page de connexion personnalisée.
@Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests() .antMatchers("/login").permitAll() .antMatchers("/", "/*todo*/**").access("hasRole('USER')").and() .formLogin() // put the relative URL to your custom login here .loginPage("/login") .permitAll(); http.csrf().disable(); }
J'espère que cela vous aidera.
Regardez tout bien, c'est du travail pour moi:
@Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .antMatchers("/todo/**").hasRole("USER") .antMatchers("/", "/home").permitAll() .antMatchers("/login").permitAll() .anyRequest().authenticated() .and() .formLogin() .loginPage("/login") .defaultSuccessUrl("/home") .permitAll() .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) .logoutSuccessUrl("/home") .permitAll() .and() .exceptionHandling().accessDeniedPage("/403"); }
Voici un Projet Spring Boot .
@Override
protected void configure (HttpSecurity http) lève l'exception {
http.csrf (). disable ();
http.authorizeRequests (). antMatchers ("/ login"). permitAll ()
.anyRequest (). authenticated (). et ()
.formLogin ()
.loginPage ("/ login")
.defaultSuccessUrl ("/ home")
.failureUrl ("/ login? error = true")
.permitAll ()
.et()
.Se déconnecter()
.logoutSuccessUrl ("/ login? logout = true")
.invalidateHttpSession (vrai)
.deleteCookies ("JSESSIONID")
.permitAll ();
}
Référence: https://devkonline.com / tutoriels / content / SPRING-SECURITY-5-CUSTOM-FORM-LOGIN-THYMELEAF