Shiro JdbcRealm授权的表模式?

sme*_*eeb 4 java authorization jdbcrealm shiro

我希望我的应用程序使用Apache Shiro进行身份验证和授权.我想从简单开始,并让关系数据库成为这两者的数据源.这意味着我需要使用JdbcRealm.

在阅读文档之后,我不清楚任何"用户表"需要什么表模式,包括将用户链接到其权限/角色的任何表.

所以我问:使用Shiro JdbcRealm,我如何/在哪里将用户链接到他们各自的权限/角色?

它不能在shiro.ini文件中,因为它是静态配置文件,并且不可能连接到存储用户信息的JDBC数据源.

Cri*_*eco 6

JdbcRealm不依赖于特定的表模式:它使用了一些默认查询,你可以重写(可以通过继承或通过特定的setter方法手段),以使其适应您的需求.

javadoc中所述,您可以使用默认查询作为构建自己的架构的基础.有一个看看,你可以开始创建三个基本表:users,user_rolesroles_permissions.

protected static final String DEFAULT_AUTHENTICATION_QUERY = "select password from users where username = ?";

/**
* The default query used to retrieve account data for the user when {@link #saltStyle} is COLUMN.
*/
protected static final String DEFAULT_SALTED_AUTHENTICATION_QUERY = "select password, password_salt from users where username = ?";

/**
* The default query used to retrieve the roles that apply to a user.
*/
protected static final String DEFAULT_USER_ROLES_QUERY = "select role_name from user_roles where username = ?";

/**
* The default query used to retrieve permissions that apply to a particular role.
*/
protected static final String DEFAULT_PERMISSIONS_QUERY = "select permission from roles_permissions where role_name = ?";
Run Code Online (Sandbox Code Playgroud)