春3.1 のTomcat 6 *春3.1 LDAP認証プロセス:「クレデンシャルが不正」MSG資格情報が良好である
私はLDAPによる認証、春3.1 Webアプリケーションを作ることに取り組んでいます。
私が書いたJNDIスタイルのJavaプログラム(以下に引用)を使用してLDAP資格証明(ユーザー名、パスワード、LDAP URL、検索パターン)をテストしました。そのプログラムは、LDAPサーバー上で暗号化されているように見えるパスワードを含むユーザーの属性をすべてダンプしました。
Spring 3.1で同じ資格情報でログインしようとすると、「Bad Credentials」というエラーメッセージが表示されます。
私は、ログにこのメッセージを得た:私はパスワード比較とエンコーディングを実現するためにタグを使用してみましたが、それは助けにはならなかった私の*の-security.xmlで
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
を。私は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>
私のネットワーキンググループは、大きく、遅く、官僚的な組織です。彼らが使用しているエンコーディングを、もしあれば、彼らに連絡せずに伝える方法はありますか?
私がチェックアウトできるものはありますか?
これが私の最後の試みと私は
おかげで接続することができましたJavaのLDAPのデモのように私*の-security.xmlです。
マイ* -security.xmlファイル:
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
ソリューション:
ここ<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プログラムです
ルーク・テイラーからのこのコメントは、私は私の設定作業を取得助け:
あなたの設定は、あなたがLDAP サーバーのURLに「O = acme.com」を持っているし、また、「使用しているという点で間違っていますユーザーDNパターンで「o = acme.com」と入力します。
私は "o = acme.com"をDNパターンから取り出し、LDAPが機能しました。私は当初、LDAP URLとDNパターンの両方に "o = acme.com"を入れました。なぜなら私はSpring 3.1とLDAPには新しく、これはJava JNDIバージョンのLDAPデモ私は置き換えているレガシーコードに基づいて書きました。
ここにmy * -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>
は、私は彼の他のコメントを探検し、私は戻って私がする必要がある、あるいは場合は、パスワードのエンコードを置くことができるかどうかを確認するつもりです。
別のメモ。サーバがどのアルゴリズムを使用しているかわからないので、実際には複数のサーバを使用している可能性があるので、パスワードエンコーディングを元に戻すことはできません。パスワードをハッシュすることは、パスワードデータベースを読みにくくすることによってパスワードデータベースを保護することです。クライアント認証をより安全にすることではありません(これについては多くの議論があります)。あなたのアプリからLDAPサーバーへのネットワークの盗聴を防止したい場合は、おそらくSSL接続を使用するのが最も簡単な方法です。 –