2012-02-14 13 views
1

LDAPサーバを使用して認証するためにapache shiroを設定しようとしています。私は非常にLDAPに精通していないので、私の無知を許してください!Apache shiro LDAP複数のOU

shiro.iniで、次のオプションを使用するには、(ユーザーが認証されます)[OK]を働いている:

 
ldapRealm.userDnTemplate = uid={0},ou=users,dc=mycompany,dc=com 

は、しかし、私たちは私たちの会社で複数の組織単位(OU)を持っています。どのようにouパラメータを複数の値にすることができますか?何かこれを使うことができますか

 
ldapRealm.userDnTemplate = uid={0},ou=*,dc=mycompany,dc=com 

ログインが成功するまですべての組織単位を試してみたいと思います。

何、このように異なるのOUた余分なLDAPレルムの追加について:

 
#ldapRealm1 
ldapRealm1 = org.apache.shiro.realm.ldap.JndiLdapRealm 
ldapRealm1.userDnTemplate = uid={0},ou=users1,dc=mycompany,dc=com 
ldapRealm1.contextFactory.url = ldap://test.com:389 
#ldapRealm2 
ldapRealm2 = org.apache.shiro.realm.ldap.JndiLdapRealm 
ldapRealm2.userDnTemplate = uid={0},ou=users2,dc=mycompany,dc=com 
ldapRealm2.contextFactory.url = ldap://test.com:389 
#ldapRealm3 
ldapRealm3 = org.apache.shiro.realm.ldap.JndiLdapRealm 
ldapRealm3.userDnTemplate = uid={0},ou=users3,dc=mycompany,dc=com 
ldapRealm3.contextFactory.url = ldap://test.com:389 

ウィルこの仕事を?

ログインページにドロップダウンを追加して、ユーザーが自分の組織単位を選択し、それをpmetmeterとしてldapRealmに渡すこともできますか?私はそれをどのように進めるべきですか?

TIA、 Serafeim

答えて

1

複数のレルムがうまく動作します。 AuthenticationTokenのサブインターフェイスを作成するだけで、ターゲットとする組織単位も指定する必要があります。

次に、LdapRealmのサブクラスを作成し、supports()メソッドをtrueに戻すように変更することができます.InterfaceTokenは、対象の組織単位を反映します。たとえば:あなたは複数の領域を持っている場合は

LdapAuthenticationToken extends AuthenticationToken { 
    String getOrganizationalUnit(); 
} 

LdapUsernamePasswordToken extends UsernamePasswordToken 
    implements LdapAuthenticationToken { 
    private String organizationalUnit; //add getter/setter 
} 

MyLdapRealm extends LdapRealm { 
    private String organizationalUnit; //add getter/setter 
    @Override 
    public boolean supports(AuthenticationToken token) { 
     return token != null && token instanceof LdapAuthenticationToken && 
      this.organizationalUnit.equals(
       ((LdapAuthenticationToken)token).getOrganizationalUnit()); 
    } 

    @Override 
    protected AuthenticationInfo doGetAuthenticatinoInfo(AuthenticationToken token) { 
     LdapAuthenticationToken ldapToken = (LdapAuthenticationToken)token; 
     //get the OU here, and do whatever you want with it. 
    } 
} 

は、それぞれがおそらく単一の共有接続プールほど効率的ではないかもしれない、独自のLDAP接続プールを持っていることに注意してください。

1つの接続プールを使用する場合は、1つのレルムを使用し、OrganizationalUnitに基づいて手動でクエリを作成する必要があります。 LdapAuthenticationTokenもこの場合に役立ちます。

関連する問題