Я использую JdbcRealm для аутентификации и авторизации Широ, которая работает отлично.Мой shiro.ini выглядит следующим образом:
[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
Когда пользовательская роль, скажем, «Ветвь», пытается получить доступ к URL-адресу, предназначенному для «Администратора», пользователь безопасно перенаправляется на «/unauthorized.xhtml'*».1004 *
Однако все изменилось, когда я решил перенести аутентификацию в Active Directory;shiro.ini выглядит следующим образом:
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-адресу» возникает ошибка:
[org.apache.shiro.authz.AuthorizationException: LDAP naming error while attempting to retrieve authorization for user [myusername]
Как безопасно выполнить авторизациюперенаправить на несанкционированный URL-адрес, как и раньше, без его взлома?Я даже пробовал это:
authz = org.apache.shiro.web.filter.authz.RolesAuthorizationFilter
authz.unauthorizedUrl = /unauthorized.xhtml
Но безуспешно.
Редактировать Коротко, как мы можем настроить shiro.ini для возврата http ответа 401/3 -(Несанкционированный / запрещенный) для необходимых случаев?