使用spring boot 配合 spring security做权限验证登录的时候出现了2个疑惑。
登录的表单中的两个input标签(账号和密码)的name标签可以随意填吗?后台是怎样的得到name值的。
登录的时候发现用户账户大小写不敏感。
这是后台配置文件:
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
http.authorizeRequests()
.antMatchers("/css/**").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login.html")
.defaultSuccessUrl("/index.html",true)
.permitAll()
.and()
.logout()
.logoutUrl("/user/logout")
.invalidateHttpSession(true)
.clearAuthentication(true)
.logoutSuccessUrl("/login.html").permitAll();
}
@Autowired
public void configGlobal(AuthenticationManagerBuilder auth) throws Exception{
//这里是怎样获取表单字段的?大小写不敏感?
auth.inMemoryAuthentication().withUser("user").password("1").roles("USER");
auth.inMemoryAuthentication().withUser("admin").password("1").roles("ADMIN");
}
}
这是前端登录页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8"/>
<title>登录</title>
<link rel="stylesheet" type="text/css" th:href="@{css/login.css}" />
</head>
<body>
<div class="login-div">
<form class="login-form" th:action="@{/login.html}" method="post">
<label for="account"> 用户:</label>
<input id="account" type="text" name="username" /> <br/>
<label for="password">密码:</label>
<input id="password" type="password" name="password" /> <br/>
<button type="submit">登 录</button>
</form>
</div>
</body>
</html>
请问这是为什么呢?
在 spring security 4.x 中,name不能随便取名

列表项目
内存中存储的用户名是会全部转小写的,判断时也是会转为全小写的,参考源码:

前台传到后台时是没有忽略大小写的