アレックス:
私は、DBから一部のユーザーを取得し、それら当局を与えることを試みます。それらは私のユーザクラスフィールドです。
private String username;
private String email;
private String password;
private String role;
私は、文字列の役割で当局を与えたいです。私はこれを試してみました:
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication()
.withUser("user1").password(passwordEncoder().encode("user1Pass"))
.authorities("ROLE_USER");
}
しかし、私は、DBからユーザーを取得し、configureGlobal方法でそれらを使用する方法がわかりません。
chaoluo:
あなたは使用することができJdbcUserDetailsManager
DBからユーザーをロードするために
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication()
.dataSource({datasource})
.usersByUsernameQuery("select username,password,1 "+ "from xxx " + "where username = ?")
.authoritiesByUsernameQuery("select username, role "+ "from xxx " + "where username = ?")
}
usersByUsernameQuery手段で1が有効になっています。