Я пытаюсь настроить пользовательскую аутентификацию внутри своего небольшого проекта.Я настроил свою базу данных (PostgreSQL) и попытался войти, используя данные из базы данных (логин admin, пароль admin, полномочия ROLE_ADMIN), но я получаю сообщение об ошибке при входе в систему (а затем приложение продолжает перенаправлять меня на страницу входа).Есть идеи, что я делаю не так?
Контроллер:
@RequestMapping(value = "/login", method = RequestMethod.GET)
public String loginPage(@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout,
Model model) {
String errorMessge = null;
if(error != null) {
errorMessge = "Username or Password is incorrect!";
}
if(logout != null) {
errorMessge = "You have been successfully logged out!";
}
model.addAttribute("errorMessge", errorMessge);
return "login";
}
WebSecurityConfig:
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery("select username, password, enabled from users where username=?")
.authoritiesByUsernameQuery("select username, authority from authorities where username=?");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/")
.permitAll()
.antMatchers("/userAccount")
.hasAnyRole("ADMIN", "ROLE_ADMIN", "USER", "ROLE_USER")
.and()
.formLogin()
.loginPage("/login")
.defaultSuccessUrl("/userAccount")
.failureUrl("/login?error=true")
.permitAll()
.and()
.logout()
.logoutSuccessUrl("/login?logout=true")
.invalidateHttpSession(true)
.permitAll()
.and()
.csrf()
.disable();
}
Сущность пользователя:
@Entity
@Table(name = "users")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name="id")
private int id;
@Column(name = "username")
private String username;
@Column(name = "password")
private String password;
@Column(name = "enabled")
private boolean enabled;
public User() {
}
public User(int id, String username, String password, boolean enabled) {
this.id = id;
this.username = username;
this.password = password;
this.enabled = enabled;
}
//getters and setters
}
Можетэто как-то связано со схемами баз данных или чем-то еще?