【发布时间】:2015-07-02 02:51:20
【问题描述】:
我正在尝试通过 Spring Boot 执行简单的 inMemoryAuthentication,但我收到“无效的用户名和密码”。在我提交登录表单后。同时,我无法在登录屏幕上看到任何静态内容。
package shell;
@SpringBootApplication
public class ShellApplication {
public static void main(String[] args) {
SpringApplication.run(ShellApplication.class, args);
}
}
package shell.mvc;
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/home").setViewName("home");
registry.addViewController("/").setViewName("home");
registry.addViewController("/hello").setViewName("hello");
registry.addViewController("/login").setViewName("login");
}
}
package shell.security;
@Configuration
@EnableWebMvcSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception{
http
.authorizeRequests()
.antMatchers("/","/home").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception{
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
<form th:action="@{/login}" method="post">
<input type="text" name="username"/>
<input type="password" name="Password"/>
<button type="submit">Login</button>
</form>
【问题讨论】:
标签: spring spring-mvc authentication login spring-security