首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Shiro RolesAuthorizationFilter在shiro.ini中的应用

Shiro RolesAuthorizationFilter在shiro.ini中的应用
EN

Stack Overflow用户
提问于 2019-02-16 09:19:47
回答 1查看 326关注 0票数 0

我一直在使用JdbcRealm进行shiro身份验证和授权,它一直运行得很好。我的shiro.ini看起来是这样的:

代码语言:javascript
复制
[main]
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
logout = org.apache.shiro.web.filter.authc.LogoutFilter
authc.loginUrl = /login.xhtml
authc.successUrl = /index.xhtml
logout.redirectUrl = /login.xhtml

jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.authenticationQuery = select password from useraccount where active = true and username LIKE ?
jdbcRealm.userRolesQuery = select rolename from role where id in(select roleid from userrole where useraccountid = (select id from useraccount where username LIKE ?) and active = true) and active = true

ds = org.postgresql.jdbc2.optional.SimpleDataSource
ds.serverName = dbhost:5432
ds.user = db_user
ds.password = db_pass
ds.databaseName = db_name
jdbcRealm.dataSource = $ds
#.
#.
#.
jdbcRealm.credentialsMatcher = $passwordMatcher

[users]

[urls]
#.
#.
#.
/admin** = authc, roles[Admin]

/activity.xhtml = authc
/item.xhtml = authc, roles[Branch]
/unauthorized.xhtml = authc

当用户角色说‘分支’试图访问一个用于'Admin‘的url时,用户被安全地重定向到’/unAuthized.xhtml‘。

但是,当我决定将身份验证移到Active时,情况发生了变化;shiro.ini如下所示:

代码语言:javascript
复制
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.userRolesQuery = select rolename from role where id in(select roleid from userrole where useraccountid = (select id from useraccount where username LIKE ?) and active = true) and active = true
jdbcRealm.dataSource = $ds

ADRealm = org.apache.shiro.realm.activedirectory.ActiveDirectoryRealm
ADRealm.url = ldap://xxx.xxx.xxx.xxx:389
ADRealm.searchBase = "OU=Company Name,DC=domain,DC=local"
ADRealm.systemUsername= myuser
ADRealm.systemPassword= mypass
ADRealm.principalSuffix= @domain.local

securityManager.realms = $jdbcRealm,$ADRealm

身份验证是正常的,但是尝试访问“未经授权的url”会导致错误中断:

代码语言:javascript
复制
[org.apache.shiro.authz.AuthorizationException: LDAP naming error while attempting to retrieve authorization for user [myusername]

如何使授权像以前一样安全地重定向到未经授权的url,而不破坏它?我甚至试过这个:

代码语言:javascript
复制
authz = org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
authz.unauthorizedUrl = /unauthorized.xhtml

但没有成功。

编辑-简而言之,我们如何配置shiro.ini返回http响应401/3 -(未经授权/禁止)在必要的情况下?

EN

回答 1

Stack Overflow用户

发布于 2019-02-19 15:36:14

如果您试图在401 s中重用您的403页,那么您的/unauthorized.xhtml = authc配置就会阻止它。

您可能可以使用:/unauthorized.xhtml = anon (假设此页面不需要用户上下文)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54721608

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档