2
我想使自己的登錄表單。當我更改登錄頁面時,我無法打開它。谷歌瀏覽器告訴我,有太多的重定向到這個網頁...使用自己的登錄表單重定向過多 - Spring Security
我的代碼:
@RequestMapping(value="/login", method = RequestMethod.GET)
public ModelAndView loginPage() {
ModelAndView modelAndView = new ModelAndView("login");
return modelAndView;
}
@RequestMapping(value="/loginError", method = RequestMethod.GET)
public ModelAndView loginErrorPage() {
ModelAndView modelAndView = new ModelAndView("login");
modelAndView.addObject("error", "true");
modelAndView.addObject("msg", "invalid login credentials");
return modelAndView;
}
設置:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable().authorizeRequests()
.antMatchers("/**").access("hasRole('ROLE_USER')")
.and().formLogin().loginPage("/login").defaultSuccessUrl("/index").failureUrl("/loginError");
}
和登錄表單:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:if test="${error eq 'true'}">
${msg}
</c:if>
<form name='loginForm' action="<c:url value='j_spring_security_check' />"
method='POST'>
<table>
<tr>
<td>User Name:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td><input name="submit" type="submit"
value="submit" />
</td>
<td><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
</body>
</html>
你能告訴我問題在哪裏嗎?我學習了很多教程,但總是遇到同樣的問題。對於許多重定向...
順便說一句。的IntelliJ着決心:j_spring_security_chec