2016-07-07 6 views
1

BCryptで暗号化するまで、春のセキュリティでダイジェスト認証を実装しました。春のセキュリティ、BCrypt、および春のデータレストのダイジェスト認証

@Bean 
    public DigestAuthenticationEntryPoint digestEntryPoint() { 
     DigestAuthenticationEntryPoint digestAuthenticationEntryPoint = new DigestAuthenticationEntryPoint(); 
     digestAuthenticationEntryPoint.setKey("myKey"); 
     digestAuthenticationEntryPoint.setRealmName("Digest Realm"); 
     return digestAuthenticationEntryPoint; 
    } 

    @Bean 
    public DigestAuthenticationFilter digestAuthenticationFilter(
      DigestAuthenticationEntryPoint digestAuthenticationEntryPoint) { 
     DigestAuthenticationFilter digestAuthenticationFilter = new DigestAuthenticationFilter(); 
     digestAuthenticationFilter.setAuthenticationEntryPoint(digestEntryPoint()); 
//  digestAuthenticationFilter.setPasswordAlreadyEncoded(true); 
     digestAuthenticationFilter.setUserDetailsService(userDetailsServiceBean()); 
     return digestAuthenticationFilter; 
    } 

これらは私がダイジェストを有効に設定豆があり、それらを使用して:

@Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
     .exceptionHandling() 
      .authenticationEntryPoint(digestEntryPoint()) 
     .and() 
     .addFilter(digestAuthenticationFilter(digestEntryPoint())) 
     //.httpBasic() 
     //.and() 
     .antMatcher("/**") 
     .csrf() 
      .disable() 
      .authorizeRequests() 
      .anyRequest() 
      .authenticated() 
     .and() 
      .formLogin() 
      .permitAll() 
     .and() 
     .logout() 
      .deleteCookies("remove") 
      .invalidateHttpSession(true) 
      .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) 
      .logoutSuccessUrl("/login") 
      .permitAll(); 
    } 

問題は、サーバー側がMD5応答と一致していない自分自身の応答を生成していることです。 DigestAuthenticationFilter.java

if (!serverDigestMd5.equals(digestAuth.getResponse())) { 
      if (logger.isDebugEnabled()) { 
       logger.debug("Expected response: '" + serverDigestMd5 
         + "' but received: '" + digestAuth.getResponse() 
         + "'; is AuthenticationDao returning clear text passwords?"); 
      } 

      fail(request, 
        response, 
        new BadCredentialsException(messages.getMessage(
          "DigestAuthenticationFilter.incorrectResponse", 
          "Incorrect response"))); 
      return; 
     } 

で サーバー「serverDigestMd5は、」私は無塩パスワードを使用して応答を生成する方法をthatsの(郵便配達を使用して)が、クライアント側で、MD5ダイジェストを作成するためにハッシュされたパスワードを使用しています。私がクライアント側で塩漬けされたパスワードを使用する場合は動作しますが、これはあまりオプションではありません。 クライアント側で塩漬けされたパスワードを使用せずに動作させる方法はありますか?

+0

If私は正しくHTTPダイジェスト認証が常にMD5ベースであることを思い出します。どのように切り替えようとしているのかは分かりません。 –

+0

[デフォルトの認証プロバイダでSpring-Security PasswordEncoderを使用する]の複製がありますか?(http://stackoverflow.com/questions/27317368/using-spring-security-passwordencoder-with-default-authentication-provider) – holmis83

答えて

1

BCryptはダイジェスト認証では機能しません。ダイジェスト認証はプレーンテキストでパスワードにアクセスする必要があります(平文で保存するか、逆のアルゴリズム(Base64、MD5など)でエンコードする必要があります。それは、より安全であるようbcryptのは、元に戻すことはできません春のセキュリティのドキュメントの状態:。

形式のHEX(MD5(ユーザ名:レルム:パスワード))でパスワードをエンコードすることが可能であるDigestAuthenticationFilter.passwordAlreadyEncodedに設定されてしかし、他のパスワードエンコーディングはダイジェスト認証では機能しません。

関連する問題