java - 在 Shiro 中为 JNDILdapRealm 配置授权

标签 java active-directory ldap jndi shiro

我的问题实际上就是这个问题:Shiro JndiLdapRealm authorization against LDAP

总而言之,Shiro documentation状态:

If you wish to perform authorization based on an LDAP schema, you must subclass this one (JNDILdapRealm) and override that method (doGetAuthorizationInfo) to reflect your organization's data model.

我对公认的解决方案感到困惑,因为 searchBase 是未定义的,它似乎是 ActiveDirectoryRealm 的一部分,而不是 JndiLdapRealm。 getRoleNamesForGroups 也是未定义的,但我假设在我的映射中组名将是角色名。

我正在尝试获得映射 ldap 组的授权 -> Forumsys's Test Ldap Server 的 shiro 角色,然后返回 doGetAuthorizationInfo 中的那些。我用来配置我的子类 LdapRealm(它扩展了 JndiLdapRealm,并且用于身份验证)的代码如下:

LdapRealm ldapRealm = new LdapRealm();
ldapRealm.setUserDnTemplate("uid={0},dc=example,dc=com");
JndiLdapContextFactory cf1 = new JndiLdapContextFactory();
cf1.setUrl("ldap://ldap.forumsys.com:389");
ldapRealm.setContextFactory(cf1);

有没有人有功能授权代码应该是什么样子的例子?还是对另一个可行的问题的已接受答案进行简单修改?

或者,有没有办法让 Forumsys 的测试服务器改为与 ActiveDirectoryRealm 一起工作(据我所知,它实现了授权)?

最佳答案

因此,我想这个问题的答案是:授权将取决于 ldap 服务器如何存储角色,以及您希望角色如何被感知。 Jxplorer有助于了解结构是什么。

至于让它与 forumsys 一起工作,搜索库应该是“dc=example,dc=com”而不是检查“memberOf”,它应该检查“ou”

关于java - 在 Shiro 中为 JNDILdapRealm 配置授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31009567/

相关文章:

java - 如何将GUI类和scanner类结合起来?

permissions - 带有外部用户的 LDAP/Active Directory

powershell - 如何在自己的代码中提升已经运行的 session

Python - 如何从 ldap 查询中删除作为列表接收的字符?

php ldap_search() : Search: Operations error

python - 在没有 LDAP 库的情况下使用 Python 搜索 LDAP

java - 第一次使用 jHipster,浏览器在 grunt 服务后挂起

java - 我将如何匹配此 Java servlet 中数据库中的用户名和密码。 JDBC 和 Servlet

java - 关闭当前应用程序,打开另一个应用程序

active-directory - 我可以使用 ASPNetIdentity 和 ActiveDirectory 吗?