春 3.1 トムキャット 6.*
LDAP で認証する Spring 3.1 webapp の作成に取り組んでいます。
私が作成した JNDI スタイルの Java プログラム (以下に引用) を使用して、LDAP 資格情報 (ユーザー名、パスワード、LDAP URL、検索パターン) をテストしました。そのプログラムは機能し、LDAP サーバーで暗号化されていると思われるパスワードを含むすべてのユーザー属性をダンプしました。
Spring 3.1 で同じ資格情報を使用してログインしようとすると、「Bad Credentials」というエラー メッセージが表示されます。
ログに次のメッセージが表示されました。
DEBUG [org.springframework.security.authentication.ProviderManager:authenticate] (ProviderManager.java:152) - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider
DEBUG [org.springframework.security.ldap.authentication.AbstractLdapAuthenticationProvider:authenticate] (AbstractLdapAuthenticationProvider.java:51) - Processing authentication request for user: John.A.Smith
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:bindWithDn] (BindAuthenticator.java:108) - Attempting to bind as uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.DefaultSpringSecurityContextSource$1:setupEnvironment] (DefaultSpringSecurityContextSource.java:76) - Removing pooling flag for user uid=John.A.Smith,ou=People,o=acme.com,o=acme.com
DEBUG [org.springframework.security.ldap.authentication.BindAuthenticator:handleBindException] (BindAuthenticator.java:152) - Failed to bind as uid=John.A.Smith,ou=People,o=acme.gov: org.springframework.ldap.AuthenticationException: [LDAP: error code 32 - No Such Object]; nested exception is javax.naming.AuthenticationException: [LDAP: error code 32 - No Such Object]
DEBUG [org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter:unsuccessfulAuthentication] (AbstractAuthenticationProcessingFilter.java:340) - Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials
*-security.xml で、タグを使用してパスワードの比較とエンコードを実行しようとしましたが、役に立ちませんでした。md4,md5,plaintext,sha,sha-256,{ssha},{sha} を使用してみましたが、役に立ちませんでした。
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People,o=noaa.gov" >
<s:password-compare hash="md5">
<s:password-encoder hash="md5"/>
</s:password-compare>
</s:ldap-authentication-provider>
</s:authentication-manager>
私のネットワーク グループは、大きくて遅い、官僚的な組織です。彼らに連絡せずに、彼らが使用しているエンコーディングを知る方法はありますか?
私がチェックアウトできることのアイデアはありますか?
これは、私の最後の試行時の *-security.xml であり、接続できた Java LDAP デモです。
ありがとう。
私の *-security.xml ファイル:
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<s:http auto-config="true" use-expressions="true">
**<s:intercept-url pattern="/welcome*" access="isAuthenticated()" />**
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:ldap-server url = "ldap://ldap-itc.sam.acme.com:636/o=acme.com"/>
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People,o=noaa.gov" />
</s:authentication-manager>
</beans>
以下は、同じ資格情報で動作する JNDI スタイルの LDAP Java プログラムです。
import javax.naming.*;
import javax.naming.directory.*;
import java.util.*;
import java.sql.*;
public class LDAPDEMO {
public static void main(String args[]) {
String lcf = "com.sun.jndi.ldap.LdapCtxFactory";
String ldapurl = "ldap://ldap-itc.sam.acme.com:636/o=acme.com";
String loginid = "John.A.Smith";
String password = "passowordforjohn";
DirContext ctx = null;
Hashtable env = new Hashtable();
Attributes attr = null;
Attributes resultsAttrs = null;
SearchResult result = null;
NamingEnumeration results = null;
int iResults = 0;
env.put(Context.INITIAL_CONTEXT_FACTORY, lcf);
env.put(Context.PROVIDER_URL, ldapurl);
env.put(Context.SECURITY_PROTOCOL, "ssl");
env.put(Context.SECURITY_AUTHENTICATION, "simple");
env.put(Context.SECURITY_PRINCIPAL, "uid=" + loginid + ",ou=People,o=acme.com");
env.put(Context.SECURITY_CREDENTIALS, password);
try {
ctx = new InitialDirContext(env);
attr = new BasicAttributes(true);
attr.put(new BasicAttribute("uid",loginid));
results = ctx.search("ou=People",attr);
while (results.hasMore()) {
result = (SearchResult)results.next();
resultsAttrs = result.getAttributes();
for (NamingEnumeration enumAttributes = resultsAttrs.getAll(); enumAttributes.hasMore();) {
Attribute a = (Attribute)enumAttributes.next();
System.out.println("attribute: " + a.getID() + " : " + a.get().toString());
}// end for loop
iResults++;
}// end while loop
System.out.println("iResults == " + iResults);
}// end try
catch (Exception e) {
e.printStackTrace();
}
}// end function main()
}// end class LDAPDEMO
解決
Luke Taylor からのこのコメントは、構成を機能させるのに役立ちました。
LDAP サーバー URL に「o=acme.com」があり、ユーザー DN パターンにも「o=acme.com」を使用しているという点で、構成が間違っています。
DN パターンから「o=acme.com」を削除すると、LDAP が機能しました。私はSpring 3.1とLDAPが初めてなので、もともと「o=acme.com」をLDAP URLとDNパターンの両方に入れていました。これは、LDAPのJava JNDIバージョンで行われた/行われた方法に似ています私が置き換えているレガシーコードに基づいて書いたデモ。
これが私の *-security.xml の最終的な動作バージョンです
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:s="http://www.springframework.org/schema/security"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<s:http auto-config="true" use-expressions="true">
**<s:intercept-url pattern="/welcome*" access="isAuthenticated()" />**
<s:form-login login-page="/login" default-target-url="/welcome"
authentication-failure-url="/loginfailed" />
<s:logout logout-success-url="/logout" />
</s:http>
<s:ldap-server url = "ldap://ldap-itc.sam.acme.com:636/o=acme.com"/>
<s:authentication-manager>
<s:ldap-authentication-provider user-dn-pattern="uid={0},ou=People" />
</s:authentication-manager>
</beans>
彼の他のコメントを調べて、パスワードのエンコードを元に戻すことができるかどうか、または必要があるかどうかを確認します。