2012-03-12 14 views
2

LDAPを使用して自分のプロジェクトにアクセスしようとしています。 ユーザー名とパスワードの入力を要求されますが、正しい資格情報を入力すると、再度ポップアップが表示されます(資格情報が間違っているように見えますが、そうではありません)。ここで春のセキュリティLDAPとMD5がパスワードをハッシュ

は私のセキュリティのcontext.xmlです:

<?xml version="1.0" encoding="utf-8"?> 
<beans:beans xmlns="http://www.springframework.org/schema/security" 
      xmlns:beans="http://www.springframework.org/schema/beans" 
      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.xsd 
           http://www.springframework.org/schema/security 
           http://www.springframework.org/schema/security/spring-security.xsd"> 

    <ldap-server url="ldap://${ldap.host}:${ldap.port}/${ldap.root}" manager-dn="${ldap.manager.dn}" manager-password="${ldap.manager.password}" /> 

    <authentication-manager> 
    <ldap-authentication-provider group-search-base="${ldap.group.search.base}" user-search-filter="(uid={0})" user-search-base="${ldap.user.search.base}" /> 
    </authentication-manager> 

    <http use-expressions="true"> 
    <intercept-url pattern="/**" /> 
    <http-basic /> 
    </http> 

</beans:beans> 

パスワードは、{MD5}ハッシュ... として格納されていると私は、JSR 250 APIを使用しています。

EDIT:この@TobyHobson がorg.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 38; cvc-complex-type.2.4.a: Invalid content was found starting with element 'password-encoder'. One of '{"http://www.springframework.org/schema/security":password-compare}' is expected.

EDIT2になり:password-encoder周りpassword-compareを入れ @TobyHobsonはコンパイルするようだが、それはまだ私の正しい資格情報を拒否します。

EDIT3:

DEBUG: org.springframework.beans.factory.support.DefaultListableBeanFactory - Returning cached instance of singleton bean 'sessionFactory' 
DEBUG: org.springframework.security.web.FilterChainProxy - /licenses/index.html at position 1 of 8 in additional filter chain; firing Filter: 'SecurityContextPersistenceFilter' 
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - HttpSession returned null object for SPRING_SECURITY_CONTEXT 
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - No SecurityContext was available from the HttpSession: [email protected] A new one will be created. 
DEBUG: org.springframework.security.web.FilterChainProxy - /licenses/index.html at position 2 of 8 in additional filter chain; firing Filter: 'BasicAuthenticationFilter' 
DEBUG: org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Basic Authentication Authorization header found for user 'demo_admin' 
DEBUG: org.springframework.security.authentication.ProviderManager - Authentication attempt using org.springframework.security.ldap.authentication.LdapAuthenticationProvider 
DEBUG: org.springframework.security.ldap.authentication.LdapAuthenticationProvider - Processing authentication request for user: demo_admin 
DEBUG: org.springframework.security.ldap.search.FilterBasedLdapUserSearch - Searching for user 'demo_admin', with user search [ searchFilter: '(uid={0})', searchBase: 'ou=people', scope: subtree, searchTimeLimit: 0, derefLinkFlag: false ] 
DEBUG: org.springframework.security.ldap.SpringSecurityLdapTemplate - Searching for entry under DN 'dc=ubuntu,dc=local', base = 'ou=people', filter = '(uid={0})' 
DEBUG: org.springframework.security.ldap.SpringSecurityLdapTemplate - Found DN: uid=demo_admin,ou=people 
DEBUG: org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator - Performing LDAP compare of password attribute 'userPassword' for user 'uid=demo_admin,ou=people' 
DEBUG: org.springframework.security.web.authentication.www.BasicAuthenticationFilter - Authentication request for failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials 
DEBUG: org.springframework.security.web.context.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession. 
DEBUG: org.springframework.security.web.context.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed 

EDIT4: はここに必要なログです私はそれがJSR 250 APIおよびグループ/役割とは何かを持っていると思います。 ここに私のLDIFです:

dn: ou=people,dc=ubuntu,dc=local 
objectClass: organizationalUnit 
ou: people 

dn: uid=demo_admin,ou=people,dc=ubuntu,dc=local 
userPassword: {MD5}fe01ce2a7fbac8fafaed7c982a04e229 
objectClass: posixAccount 
objectClass: account 
homeDirectory: null 
uid: demo_admin 
uidNumber: 1001 
gidNumber: 1000 
cn: Demo Admin 

dn: uid=demo_manager,ou=people,dc=ubuntu,dc=local 
userPassword: {MD5}fe01ce2a7fbac8fafaed7c982a04e229 
objectClass: posixAccount 
objectClass: account 
homeDirectory: null 
uid: demo_manager 
uidNumber: 2001 
gidNumber: 2000 
cn: Demo Manager 

dn: uid=demo_viewer,ou=people,dc=ubuntu,dc=local 
userPassword: {MD5}fe01ce2a7fbac8fafaed7c982a04e229 
objectClass: posixAccount 
objectClass: account 
homeDirectory: null 
uid: demo_viewer 
uidNumber: 3001 
gidNumber: 3000 
cn: Demo Viewer 

dn: ou=groups,dc=ubuntu,dc=local 
objectClass: organizationalUnit 
ou: groups 

dn: cn=Admins,ou=groups,dc=ubuntu,dc=local 
objectClass: posixGroup 
cn: Admins 
gidNumber: 1000 

dn: cn=Managers,ou=groups,dc=ubuntu,dc=local 
objectClass: posixGroup 
cn: Managers 
gidNumber: 2000 

dn: cn=Viewers,ou=groups,dc=ubuntu,dc=local 
objectClass: posixGroup 
cn: Viewers 
gidNumber: 3000 

私は私のコントローラで@RolesAllowed({ Role.ROLE_ADMIN, Role.ROLE_MANAGER, Role.ROLE_VIEWER })を使用し、これは私のabsract役割クラスです:あなたは、パスワードをハッシュするために春告げるためにあなたの認証プロバイダにpassword encoderを追加する必要が

public abstract class Role 
{ 
    public static final String ROLE_ADMIN = "Admins"; 
    public static final String ROLE_MANAGER = "Managers"; 
    public static final String ROLE_VIEWER = "Viewers"; 
} 
+0

あなたは「*パスワードは、{MD5}ハッシュ*として格納されている」ことを書きます。構成ファイルで、エンコードされたパスワードがバインド要求でディレクトリサーバーに送信されることを意味しますか? –

+0

パスワードはmd5ハッシュとして保存されます。資格情報が正しい場合、暗号化されたパスワードをサーバーに送信して、正常に戻るようにする必要があります。私は、サーバー側で品質チェックのようなものをしたくないのですが、これはログイン用です... – dtrunk

答えて

1

LDAPでバインドする前に例えば

<authentication-manager> 
    <ldap-authentication-provider group-search-base="${ldap.group.search.base}" user-search-filter="(uid={0})" user-search-base="${ldap.user.search.base}"> 
    <password-encoder hash="md5"/> 
    </ldap-authentication-provider> 
</authentication-manager> 

塩を使用する場合は、これも含める必要があります。

<password-encoder hash="md5"> 
    <salt-source user-property="username"/> 
</password-encoder> 
+1

注意:ディレクトリサーバーを使用してパスワードの品質とパスワードの履歴を確認している場合は、 - 不可逆パスワードは、サーバーが前述のチェックを実行することを不可能にします。 –

+0

これは正しくありません。標準のSpring Security MD5パスワードエンコーダは、LDAPハッシュまたはバインド認証と互換性がありません。 –

+0

私はこの1つでルークに延期します... –

0

バインド認証を使用するときに春のセキュリティは、パスワードをハッシュまたは方法のいずれかの知識を持ってする必要がないので、パスワードのチェックは、ディレクトリ内ではなく、春のセキュリティコード内で実行されるため、パスワードの符号化方式は、重要ではありませんそれは記憶される。それはディレクトリに平文として送られるので、もしあなたがそれを心配しているならば、ldaps接続を使うべきです。

LDAPの「比較」操作を使用して認証していた場合は、パスワードフィールドの同一のコピーをディレクトリに送信する必要があります。 {SHA}と{SSHA}を扱うLdapShaPasswordEncoderが存在しますが、現在の{MD5}ハッシュのサポートは現在のところありません。

ほとんどの場合、デバッグログとLDAPサーバーログのより詳細な情報から、セットアップが失敗する可能性があります。

+0

slapd.confの296にloglevelを入れてください。slapd.logに表示されるのは '<= bdb_equality_candidates:(uid)not indexed'です – dtrunk

+0

フルログインがあればslapdを実行すると、DN、パスワードなどのバインド要求のアンマーシャリングまですべてが表示されます。また、Spring Securityのデバッグログも確認してください。ユーザーが最初に見つからないことがあります。 –

1

春のセキュリティ構成ファイルでハッシングを定義する必要はなく、ハッシュ技術はLDAP自体で処理されます。あなたがしなければならない 一つだけの事は、このようなLDAPでMD5パスワードを記憶している....

   Attributes attrs = new BasicAttributes(); 
     BasicAttribute ocattr = new BasicAttribute("objectclass"); 
     ocattr.add("top"); 
     ocattr.add("person"); 
     ocattr.add("inetorgperson"); 
     ocattr.add("organizationalperson"); 
     attrs.put(ocattr); 
     attrs.put("sn",user.getName()); 
     attrs.put("userPassword","{MD5}"+user.getPassword()); 
関連する問題