验证我已经实现这种方式我的用户从我的数据库连接和检索:春季安全:使用数据库
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Autowired
DataSource dataSource;
@Autowired
public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception {
auth.jdbcAuthentication().dataSource(dataSource)
.usersByUsernameQuery(
"select username,password, enabled from users where username=?")
.authoritiesByUsernameQuery(
"select username, role from user_roles where username=?");
}
所以,我有我的用户与他们的角色。 在此示例代码中,user_roles列将为“ROLE_USER”或“ROLE_ADMIN”。 我想改变这个字段的布尔值,其中ROLE_ADMIN为0,ROLE_USER为1。
由于约束条件,我无法保留我的user_roles。
我该怎么做?
映射0到“ROLE_USER”和1“ROLE_ADMIN”请不要忘记当初的管理也是一个用户。 –
是否有一个Authorities标签可以同时获得ROLE_ADMIN和ROLE_USER授权? –
您可以检查PreAuthorize或Secured注释中的AND条件。 –