Я пытаюсь выполнить простую inMemoryAuthentication через Spring Boot, но получаю «Неверное имя пользователя и пароль». после отправки формы входа. В то же время я не вижу какого-либо статического содержимого на экране входа в систему.Образец SpringBoot не аутентифицирован
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>