7

spring-security を使用して、セットアップしたローカル ADAM インスタンスと通信する Java アプリを取得しようとしています。

ADAM を正常にインストールし、次のようにセットアップしました....

  • localhost:389 で実行されているインスタンス
  • ルートはO=Company
    • OU=Company Users(orgnizationalUnit) という子
      • CN=Mike Q(ユーザー)という孫
      • uid = mikepassword = welcome

次に、spring-security (バージョン 3.0.3、spring-framework 3.0.4、および spring-ldap 1.3.0) をセットアップしました。スプリングファイル

  <security:ldap-server id="contextSource" url="ldap://localhost:389/o=Company"/>

  <security:authentication-manager>
    <security:ldap-authentication-provider user-dn-pattern="uid={0},ou=Company Users"/>
  </security:authentication-manager>

  <bean class="com.xxx.test.TestAuthentication" lazy-init="false"/>

そしてTestAuthentication

public class TestAuthentication
{
    @Autowired
    private AuthenticationManager authenticationManager;

    public void initialise()
    {
        Authentication authentication = new UsernamePasswordAuthenticationToken( "mike", "welcome" );
        Authentication reponseAuthentication = authenticationManager.authenticate( authentication );
    }
}

これを実行すると、次のエラーが表示されます

Caused by: javax.naming.AuthenticationException: [LDAP: error code 49 - 8009030C: LdapErr: DSID-0C090336, comment: AcceptSecurityContext error, data 2030, vece]
at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3041)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2987)
at com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2789)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2703)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:293)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURL(LdapCtxFactory.java:175)
at com.sun.jndi.ldap.LdapCtxFactory.getUsingURLs(LdapCtxFactory.java:193)
at com.sun.jndi.ldap.LdapCtxFactory.getLdapCtxInstance(LdapCtxFactory.java:136)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:66)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:667)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
at javax.naming.InitialContext.init(InitialContext.java:223)
at javax.naming.ldap.InitialLdapContext.<init>(InitialLdapContext.java:134)
at org.springframework.ldap.core.support.LdapContextSource.getDirContextInstance(LdapContextSource.java:43)
at org.springframework.ldap.core.support.AbstractContextSource.createContext(AbstractContextSource.java:254)

誰かが私が間違っているところを指摘できれば、私は感謝します。この時点で、入力したユーザー/パスワードを LDAP を使用して認証したいだけで、それ以上に複雑なことはありません。

LDAP の世界に初めて足を踏み入れたので、いくつかの一般的な点にも興味があります。

  • LDAP は大文字と小文字を区別しますか?
  • スペースを避けるのが最善ですか?
  • LDAP クエリでパスワードをクリア テキストで送信しないようにするための一般的なユースケース/ベスト プラクティスは何ですか?
4

2 に答える 2

5

これを解決するのに十分な時間を費やしたので、ここに答えがあります。

エラー コード 2030 は、ユーザーの DN が無効であることを意味します。

いくつかの試行錯誤の後、ここで動作し、ユーザー検索を適切に行う構成を示します。(おそらくセキュリティ名前空間を使用してこれを書き直すことができますが、私がこれに取り組んでいる間、未加工の Bean 定義を使用する方が明確でした)。

  <bean id="contextSource"
        class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
    <constructor-arg value="ldap://localhost:389/cn=Sandbox,dc=ITOrg"/>
    <property name="userDn" value="cn=superuser,cn=People,cn=Sandbox,dc=ITOrg"/>
    <property name="password" value="xxxxxx"/>
  </bean>

  <bean id="ldapAuthProvider"
        class="org.springframework.security.ldap.authentication.LdapAuthenticationProvider">
    <constructor-arg>
      <bean class="org.springframework.security.ldap.authentication.BindAuthenticator">
        <constructor-arg ref="contextSource"/>
        <property name="userDnPatterns">
          <list>
            <value>cn={0},cn=People</value>
          </list>
        </property>
      </bean>
    </constructor-arg>
  </bean>

  <bean id="userSearch" class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
    <constructor-arg index="0" value="cn=People"/>
    <constructor-arg index="1" value="(cn={0})"/>
    <constructor-arg index="2" ref="contextSource"/>
  </bean>

重要なことは

<property name="userDn" value="cn=superuser,cn=People,cn=Sandbox,dc=ITOrg"/>

コンテキスト ソースで userDn を指定する場合は、FULL DN である必要があります (URL で指定されたベース (コンストラクター引数) を追加するだけではありません)。

BindAuthentication を使用する場合

<value>cn={0},cn=People</value>

この値は、コンテキスト ソースの baseDn の上のサフィックスです。

UserSearch の構成時

    <constructor-arg index="0" value="cn=People"/>
    <constructor-arg index="1" value="(cn={0})"/>

2番目の引数にあるとうまくいきませんでしたcn=Peopleが、これはうまくいくようです。ユーザーの属性を使用できることに注意してください。(uid={0})

Bean 定義を使用したコード例を次に示します...

    @Autowired
    private LdapUserSearch ldapUserSearch;

    @Autowired
    private AuthenticationProvider authenticationProvider;

    public void initialise()
    {
        DirContextOperations dirContextOperations = ldapUserSearch.searchForUser( "username" );

        Authentication authentication = authenticationProvider.authenticate( new UsernamePasswordAuthenticationToken( "username", "password" ) );    
    }

その他のランダムなヒント...

Error 52b - Invalid password


[LDAP: error code 32 - 0000208D: NameErr: DSID-031521D2, problem 2001 (NO_OBJECT), data 0, best match of: 'CN=Sandbox,DC=ITOrg'
     - This means the user is not in the administrator role (probably)

これがすべて他の誰かに役立つことを願っています。

于 2010-09-28T07:37:27.587 に答える