java - 从我的数据库中检索权限始终为空
问题描述
我遇到了一个问题,一切都正常工作,例如角色和身份验证。但是,我的开发已经停止,因为我无法获得帐户的权限。权限总是返回 null,我不知道为什么。
DefaultSecurityManager defaultSecurityManager = new DefaultSecurityManager();
ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
authenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
defaultSecurityManager.setAuthenticator(authenticator);
ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();
authorizer.setPermissionResolver(new WildcardPermissionResolver());
defaultSecurityManager.setAuthorizer(authorizer);
JdbcRealm realm = new JdbcRealm();
realm.setDataSource(DatabaseUtil.DATA_SOURCE);
realm.setAuthenticationQuery("SELECT password FROM account WHERE username = ?");
realm.setUserRolesQuery("SELECT accountRole FROM account WHERE username = ?");
realm.setPermissionsQuery("SELECT permissions FROM account WHERE username = ?");
realm.setPermissionsLookupEnabled(true);
realm.setCredentialsMatcher(new PasswordMatcher());
defaultSecurityManager.setRealm(realm);
SecurityUtils.setSecurityManager(defaultSecurityManager);
解决方案
推荐阅读
- python - 为什么 dateFormatter 会调整日期?
- java - 对 Apache mina sshd 服务器执行 ssh 命令
- android - 从可移动相对布局内的 URL 设置图像
- uwp - 如何通过 API 提交 UWP 应用程序
- python - Python:gevent 和 libfaketime
- gitlab-ci-runner - 作业日志中很长的行在 repos 中表现不同
- postgresql - 代表表所有者创建分区
- javascript - 如何从函数中返回变量
- javascript - 从 javascript 延迟加载的图像未在 chromium/chrome 中显示
- r - 创建一个变量,它是另一个变量的第五个值,如果第五个周期没有值,则取最接近的