2017-09-13 24 views
0

私はOSA上でopenldapを実行しています(ただし、本番環境に移行する際にはIPOSを実行するCentOSに移行します)。Openldap Springインテグレーション:不正な資格情報

単一のホームコントローラ、スプリングセキュリティ、ldapスタータ以外は何も備えていない簡単なスプリングブートアプリケーション。次のようにポンポンの依存関係は、以下のとおりです。

<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-web</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-security</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.ldap</groupId> 
    <artifactId>spring-ldap-core</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-ldap</artifactId> 
</dependency> 
<dependency> 
    <groupId>com.unboundid</groupId> 
    <artifactId>unboundid-ldapsdk</artifactId> 
</dependency> 
<dependency> 
    <groupId>org.springframework.boot</groupId> 
    <artifactId>spring-boot-starter-test</artifactId> 
    <scope>test</scope> 
</dependency> 
<dependency> 
    <groupId>org.springframework.security</groupId> 
    <artifactId>spring-security-test</artifactId> 
    <scope>test</scope> 
</dependency> 

だけでなく、次のように私以上の依存関係は、コンフィギュレーションクラスがある:

@Configuration 
public class WebSecurityConfig extends WebSecurityConfigurerAdapter { 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http.authorizeRequests() 
      .anyRequest().fullyAuthenticated() 
      .and().formLogin(); 
    } 

    @Override 
    public void configure(AuthenticationManagerBuilder auth) throws Exception { 
     auth.ldapAuthentication() 
      .userDnPatterns("uid={0},ou=users") 
      .groupSearchBase("ou=groups") 
      .contextSource(contextSource()) 
      .passwordCompare() 
      .passwordEncoder(new LdapShaPasswordEncoder()) 
      .passwordAttribute("userPassword");  
    } 

    @Bean 
    public DefaultSpringSecurityContextSource contextSource() { 
      return new DefaultSpringSecurityContextSource(Arrays.asList("ldap://localhost:389/"), "dc=m,dc=com"); 
    } 
} 

マイLDAPディレクトリには、それは次のように持っている、非常に簡単です:

# m.com 
dn: dc=m,dc=com 
objectClass: dcObject 
objectClass: organization 
o: M 
dc: m 

# users, m.com 
dn: ou=users,dc=m,dc=com 
objectClass: organizationalUnit 
ou: users 

# taylorj, users, m.com 
dn: uid=taylorj,ou=users,dc=m,dc=com 
objectClass: top 
objectClass: account 
objectClass: posixAccount 
cn: Jonathan Taylor 
uid: taylorj 
uidNumber: 1 
gidNumber: 1 
homeDirectory: /home/taylorj 
userPassword:: e1NTSEF9UVNVNDBOdlh1bkJqNkhGeVUwekVVYXlNb2RidTErekg= 

私は春のアプリケーションを実行すると、それはLDAPへの接続を行い、私はLDAPサーバーに入ってくるreuestsを見ることができます、私はそれがOKを検索し、 rPassword属性は、しかし、LDAPはエラーコード5(LDAP_COMPARE_FALSE)を返し、春に私は次の例外を参照してください。

2017-09-13 15:52:13.315 DEBUG 92002 --- [nio-8132-exec-3] o.s.s.l.a.LdapAuthenticationProvider  : Processing authentication request for user: taylorj 
2017-09-13 15:52:13.317 DEBUG 92002 --- [nio-8132-exec-3] o.a.c.loader.WebappClassLoaderBase  :  findResources(jndi.properties) 
2017-09-13 15:52:13.330 DEBUG 92002 --- [nio-8132-exec-3] o.s.l.c.support.AbstractContextSource : Got Ldap context on server 'ldap://localhost:389/dc=m,dc=com' 
2017-09-13 15:52:13.339 DEBUG 92002 --- [nio-8132-exec-3] .s.s.l.a.PasswordComparisonAuthenticator : Performing LDAP compare of password attribute 'userPassword' for user 'uid=taylorj,ou=users' 
2017-09-13 15:52:13.340 DEBUG 92002 --- [nio-8132-exec-3] o.s.l.c.support.AbstractContextSource : Got Ldap context on server 'ldap://localhost:389/dc=m,dc=com' 
2017-09-13 15:52:13.342 DEBUG 92002 --- [nio-8132-exec-3] o.s.b.f.s.DefaultListableBeanFactory  : Returning cached instance of singleton bean 'delegatingApplicationListener' 
2017-09-13 15:52:13.342 DEBUG 92002 --- [nio-8132-exec-3] w.a.UsernamePasswordAuthenticationFilter : Authentication request failed: org.springframework.security.authentication.BadCredentialsException: Bad credentials 

org.springframework.security.authentication.BadCredentialsException: Bad credentials 
    at org.springframework.security.ldap.authentication.PasswordComparisonAuthenticator.authenticate(PasswordComparisonAuthenticator.java:114) ~[spring-security-ldap-4.2.3.RELEASE.jar:4.2.3.RELEASE] 

いくつかの並べ替えのようだと私は私が間違ってやって本当にわからないんだけどパスワードの比較が失敗する原因となっています。

アイデア?

UPDATE

私は、スプリングバックが提供するLDIFに戻って、それがうまく働きました。挫折した私は次に、春のLDIFによって提供されたユーザーベンのパスワードを変更するために以下を実行した

ldappasswd -x -D "cn = admin、dc = m、dc = com" -W -S "uid = OU =人、DC =メートル、dc = comの」

このコマンドを実行した後、私のログインはもはや春が提供するLDIFを見てみると

働かない:

dn: uid=ben,ou=people,dc=m,dc=com 
objectclass: top 
objectclass: person 
objectclass: organizationalPerson 
objectclass: inetOrgPerson 
cn: Ben Alex 
sn: Alex 
uid: ben 
userPassword: {SHA}nFCebWjxfaLbHHG1Qk5UU4trbvQ= 

それはそう設定されます私はldappasswdを実行すると、SHAとしてのパスワードを返しますが、これはSalted SHA {SSHA}として終わります。限り、ドキュメントから見ることができる限り、スプリング実装はSHAとSSHAの両方を処理する必要があります。

まだ何が起こっているのかまだ分かりません。

答えて

0

春のセキュリティにはバグがあります。

org.springframework.security.ldap.authentication。 PasswordComparisonAuthenticator setPasswordEncoder方法の

初期ライン:パスワードエンコーダがタイプPasswordEncoderであれば、この中

public void setPasswordEncoder(Object passwordEncoder) { 
    if (passwordEncoder instanceof PasswordEncoder) { 
     this.usePasswordAttrCompare = false; 
     setPasswordEncoder((PasswordEncoder) passwordEncoder); 
     return; 
    } 

それはusePasswordAttrCompareに偽設定します。この問題は、このフラグがに設定されていると、になり、パスワードを比較するためにLDAPが取得されることになります。パスワードはSSHAとして保存されているので、SpringはSHA Saltを事前に知る方法がないので、明らかに一致しないSHA1バージョンのパスワードを送信するだけです。isPasswordValidは、比較のために平文パスワードとハッシュされたパスワードの両方を取ることができ、従って、一方、認証に

()

else if (isLdapPasswordCompare(user, ldapTemplate, password)) { 
     return user; 
} 

によりLdapShaPasswordEncoderが実装されている方法には、エンコード機能は、単に平文パスワードを取り塩を抽出することによってSSHA変異体を計算する。

は私が変更され、次のようにsetPasswordEncoder機能を(私は戻って、いくつかの点で適切にそれを行います):私たちは常にisPasswordValidメソッドにフォールバックしますLdapShaPasswordEncoderを持っている場合は

if (passwordEncoder instanceof PasswordEncoder) { 
    if(passwordEncoder instanceof org.springframework.security.authentication.encoding.LdapShaPasswordEncoder) { 
     this.usePasswordAttrCompare = true; 
    } else { 
     this.usePasswordAttrCompare = false; 
    } 
    setPasswordEncoder((PasswordEncoder) passwordEncoder); 
    return; 
} 

ました平文、SHAおよびSSHAのパスワードを扱います。

spring-securityを再構築して、新しいjarに対して自分のコードを再構築すると、正常に動作します。さあ、それをやり遂げ、それをSpringにプルするためのより良い方法を見つけてください。

関連する問題