Após toda configuração quando faço o login tenho o erro: org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported
minha configuração
http.authorizeRequests()
.antMatchers("/assets/**",
"/fonts/**",
"/global/**",
"/imagens/**",
"/auth/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/auth/form")
.failureUrl("/auth/login?error=true")
.usernameParameter("j_username")
.passwordParameter("j_passsword")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/auth/login?logout=true")
.invalidateHttpSession(true)
.deleteCookies("JSESSIONID")
.and()
.exceptionHandling().accessDeniedPage("/auth/denied");
Controller de acesso:
@Controller
@RequestMapping(value = "auth")
public class LoginController {
@RequestMapping(value = "/form", method = RequestMethod.GET)
public String loginPage(){
return "login";
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(
@RequestParam(value = "error", required = false) boolean error,
@RequestParam(value = "error", required = false) boolean logout, ModelMap model
){
System.out.println("===========");
if(error){
model.addAttribute("error", "Login inválido, senha ou nome do usuário não confere.");
return new ModelAndView("login", model);
}
if(logout){
model.addAttribute("logout", "Deslogado com sucesso");
return new ModelAndView("login", model);
}
return new ModelAndView("redirect:/");
}
@RequestMapping(value = "/denied", method = RequestMethod.GET)
public ModelAndView acessoNegado(){
return new ModelAndView("error", "mensagem", "Acesso negado");
}
}
jsp
<c:url value="/auth/login" var="loginUrl"/>
<form method="POST" action="${loginUrl }">
<c:if test="${error != null}">
${error}
</c:if>
<c:if test="${logout != null}">
${logout}
</c:if>
<!-- <div class="form-group">
<label class="sr-only" for="inputName">Nome</label>
<input type="text" class="form-control" id="inputName" name="j_username" placeholder="Name">
</div> -->
<div class="form-group">
<label class="sr-only" for="inputEmail">Email</label>
<input type="email" class="form-control" id="inputEmail" name="j_username" placeholder="Email">
</div>
<div class="form-group">
<label class="sr-only" for="inputPassword">Senha</label>
<input type="password" class="form-control" id="inputPassword" name="j_password"
placeholder="Password">
</div>
<div class="form-group clearfix">
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token }"/>
<div class="checkbox-custom checkbox-inline checkbox-primary float-left">
<input type="checkbox" id="inputCheckbox" name="remember">
<label for="inputCheckbox">Lembrar</label>
</div>
<a class="float-right" href="forgot-password.html">Esqueci minha senha!</a>
</div>
<button type="submit" class="btn btn-primary btn-block">Enviar</button>
</form>