Я использую весеннюю безопасность 3.2.5 для аутентификации пользователей. после того, как я укажу имя пользователя и пароль на странице входа, он не перенаправляется на страницу, указанную в методе defaultSuccessUrl, и просто перезагружает страницу входа.Весенняя безопасность не перенаправляется после успешного входа в систему
следующий мой код, пожалуйста, дайте мне знать, что в этом плохого.
@Configuration
@EnableWebMvcSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
private DataSource dataSource;
@Override
public void configure(WebSecurity webSecurity) throws Exception{
webSecurity
.ignoring()
.antMatchers("/resources/**")
.antMatchers(HttpMethod.POST, "/login");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest()
.authenticated()
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/")
.failureUrl("/login?error=true")
//.usernameParameter("username").passwordParameter("password")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login")
.permitAll()
.and()
.csrf();
}
@Override
protected void configure(AuthenticationManagerBuilder auth)
throws Exception {
auth.jdbcAuthentication().dataSource(dataSource).usersByUsernameQuery(
"SELECT user_id, password, 'true' as enabled FROM scl_user_info WHERE user_id = ?");
}
}
login.jsp
<form action="<c:url value="/j_spring_security_check" />" method="POST">
<input type="text" class="form-control" placeholder="Username" name="j_username"/>
<input type="password" class="form-control" placeholder="Password" name="j_password"/>
<input type="checkbox" />
<span class="lbl"> Remember Me</span>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<button type="submit" class="width-35 pull-right btn btn-sm btn-primary">
<i class="ace-icon fa fa-key"></i>
<span class="bigger-110">Login</span>
</button>
</form>
HomeController
@Controller
public class HomeController {
@RequestMapping("/")
public String defaultPage() {
return "home";
}
@RequestMapping("/login")
public String login(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {
return "login";
}
}
столбцы таблицы
идентификатор, user_id, пароль
Включить ведение журнала отладки, чтобы посмотреть, что происходит. – holmis83
ничего не отображается в журнале, я мог видеть, что только страница загружается после отправки. – Prasad