我正在尝试使用Spring Security登录,但是它不起作用。我得到页面刷新,但没有任何反应。
例如,我要转到不允许的页面,而Sping给f
提供了我无法使用登录表单的地方。
WebSecurityConfig.class
e$
login.mustache
login.mustache
路径@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Bean
@Override
public UserDetailsService userDetailsService() {
UserDetails user =
User.withDefaultPasswordEncoder()
.username("u")
.password("1")
.roles("USER")
.build();
return new InMemoryUserDetailsManager(user);
}
}
也已在配置中注册
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Spring Security Example </title>
</head>
<body>
Login page
<form action="/login" method="post">
<div><label> User Name : <input type="text" name="username"/> </label></div>
<div><label> Password: <input type="password" name="password"/> </label></div>
<div><input type="submit" value="Sign In"/></div>
</form>
<a href="/registration">Add new user</a>
</body>
</html>