[英]403 Error for Custom Login Page Spring Security
每當我嘗試使用 Spring Security 登錄到我的 spring 引導應用程序的主頁時,都會收到 403 錯誤。 每當我使用 spring 安全的默認登錄頁面時,登錄都不會引發 403 錯誤。
下面是我的配置方法。
@Override
protected void configure(HttpSecurity http) throws Exception
{
http.authorizeRequests()
.antMatchers("/css/**").permitAll()
.antMatchers().hasAnyRole("ADMIN","USER")
.antMatchers("/").permitAll().and().formLogin().loginPage("/login");
}
下面是我的文件結構的圖片:
下面是我的 Controller。
@Controller
public class AuthenticationController
{
/*
Get request to allow us to see the login page. This page is
stores in the static folder.
*/
@GetMapping("/login")
public String login()
{
return "login";
}
@GetMapping("/")
public String index()
{
return "index";
}
}
數據庫結構: http://prntscr.com/svya5d
登錄.html
<!DOCTYPE html>
<html xmlns:th="www.thymeleaf.org">
<!-- We need ThymeLeaf. This provides a rendering engine to allow Spring boot to know that there are templates for it to render -->
<head>
</head>
<body>
<form method="POST">
<div class="form-row">
<div class="name">Username</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="text" name="userID">
</div>
</div>
</div>
<div class="form-row">
<div class="name">Password</div>
<div class="value">
<div class="input-group">
<input class="input--style-5" type="password" name="userPW">
</div>
</div>
</div>
<div>
<button class="btn btn--radius-2 btn--red" type="submit">Login</button>
</div>
<a class="myLinkLog" href="register">Create an account</a>
</form>
</html>
您需要設置表單操作並使用正確的輸入名稱。 這是一個最小的例子:
<form th:action="@{/login}" method="post">
<input type="text" name="username" />
<input type="password" name="password" />
<button type="submit" th:text="#{login}"></button>
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.