在 Shiro 中为 JNDILdapRealm 配置授权

Configuring authorization for JNDILdapRealm in 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 角色,然后是 return 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"