私の要件は、Webアプリケーションにアクセスできるようにユーザのログイン(ユーザ名&パスワード)を認証することです。admin/managerアカウントを使用しないSpring LDAP認証
boolean isCredentialsValid = false;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");
env.put(Context.PROVIDER_URL, ldapUrl);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, username);
env.put(Context.SECURITY_CREDENTIALS, password);
try {
DirContext ctx = new InitialDirContext(env);
ctx.close();
isCredentialsValid = true;
} catch (Exception e) {
e.printStackTrace();
}
System.out.println(isCredentialsValid);
が、これは直接春に実装することができる:
は、Javaを使用して、私は、ユーザーの提供ログインを使用して認証することができましたか? BindAuthenticatorやPasswordComparisonAuthenticatorのように?私はこの設定を使用しようとしました:
<bean id="contextSource"
class="org.springframework.security.ldap.DefaultSpringSecurityContextSource">
<constructor-arg value="IP of LDAP Server:389" />
</bean>
<bean id="ldapAuthenticator"
class="org.springframework.security.providers.ldap.authenticator.BindAuthenticator">
<constructor-arg ref="contextSource"/>
<property name="userDNPatterns" >
<list>
<value>uid={0}, dc=company,dc=com</value>
</list>
</property>
</bean>
<bean id="userSearch"
class="org.springframework.security.ldap.search.FilterBasedLdapUserSearch">
<constructor-arg index="0" value="ou=people" />
<constructor-arg index="1" value="(uid={0})" />
<constructor-arg index="2" ref="contextSource" />
<property name="searchSubtree" value="true" />
</bean>
しかし私はUncategorizedLdapExceptionをエンコーディングしています。
これまでのSpring LDAPで読んだことから、管理者アカウントを提供せずに直接ユーザーのログインを認証することはできません。
ご協力いただきありがとうございます。
これはスタックトレースです:
未分類の例外は、LDAP処理中に発生しました。ネストされた例外はjavax.naming.NamingExceptionです:[LDAP:エラーコード1 - 000004DC:LdapErr:DSID - 0C0906DC、コメント:この操作を実行するには、接続で正常なバインドを完了する必要があります、データ0、v1db0];残りの名前は 'uid = [email protected]'です。ネストされた例外はorg.springframework.ldap.UncategorizedLdapExceptionです:LDAP処理中に未分類の例外が発生しました。ネストされた例外はjavax.naming.NamingExceptionです:[LDAP:エラーコード1 - 000004DC:LdapErr:DSID - 0C0906DC、コメント:この操作を実行するには、接続で正常なバインドを完了する必要があります、データ0、v1db0];残りの名前は 'uid = [email protected]'
Stacktraceしてください。 –
@nico_ekitoスタックトレースを追加しました。ありがとう – Brenard