Após o primeiro login em
http://localhost:8083/login o botão de logout funciona corretamente e a tela retorna para o http://localhost:8083/login
ao tentar realizar um novo login o sistema apresenta a url http://localhost:8083/
e o erro
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback. Tue Apr 19 13:40:53 VET 2022 There was an unexpected error (type=Not Found, status=404). No message available
O que foi implementado:
html
LoginController.java
package br.com.alura.mvc.mudi.controller;
import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping;
@Controller public class LoginController { @GetMapping @RequestMapping ("/login")
public String login() {
return "login";
}
}
WebSecurityController.java
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.userdetails.User; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.provisioning.InMemoryUserDetailsManager;
@Configuration @EnableWebSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter{ //AUTORIZAÇÃO @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() .anyRequest().authenticated() .and() .formLogin(form -> form .loginPage("/login") .permitAll() //https://docs.spring.io/spring-security/site/docs/5.3.13.RELEASE/reference/html5/#servlet-authentication-form ) //a chamada de logout é tratada aqui .logout(logout -> logout.logoutUrl("/logout"));
}
//AUTENTICAÇÃO
@Bean
@Override
public UserDetailsService userDetailsService() {
UserDetails user =
User.withDefaultPasswordEncoder()
//não é considerado seguro no modo de produção
.username("joao")
.password("joao")
.roles("ADM")
.build();
return new InMemoryUserDetailsManager(user);
}
}
O que pode estar ocorrendo?