2014-04-10 10 views
10

Tworzę nową aplikację internetową, która nie używa xml (bez web.xml i bez spring.xml). Mam prawie wszystko, ale nie mogę się dowiedzieć, jak zarejestrować SaltSource. Muszę zastąpić następujące elementy odpowiednikiem Java.Jak zarejestrować SaltSource w Java Config (bez xml)

<authentication-manager> 
    <authentication-provider user-service-ref="authService" > 
    <password-encoder hash="sha" ref="myPasswordEncoder"> 
    <salt-source user-property="salt"/> 
    </password-encoder> 
    </authentication-provider> 
</authentication-manager> 

Do tej pory mam to w Javie.

protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
    ReflectionSaltSource rss = new ReflectionSaltSource(); 
    rss.setUserPropertyToUse("salt"); 

    auth.userDetailsService(authService).passwordEncoder(new MyPasswordEncoder()); 
    // How do I set the saltSource down in DaoAuthenticationProvider 
} 

Więc jak mam zarejestrować SaltSource tak, że kończy się w DaoAuthenticationProvider (jak XML ma to miejsce w przeszłości)?

+0

Dostałem go do pracy, wykonując cię następujący: –

+1

protected void configure (AuthenticationManagerBuilder auth) throws Exception { \t ReflectionSaltSource rss = new ReflectionSaltSource(); \t rss.setUserPropertyToUse ("sól"); Dostawca: = nowy DaoAuthenticationProvider(); \t provider.setSaltSource (rss); \t provider.setUserDetailsService (authService); \t provider.setPasswordEncoder (new MyPasswordEncoder()); auth.authenticationProvider (dostawca); } –

Odpowiedz

11

mam do pracy, wykonując następujące czynności:

protected void configure(AuthenticationManagerBuilder auth) throws Exception { 
    ReflectionSaltSource rss = new ReflectionSaltSource(); 
    rss.setUserPropertyToUse("salt"); 
    DaoAuthenticationProvider provider = new DaoAuthenticationProvider(); 
    provider.setSaltSource(rss); 
    provider.setUserDetailsService(authService); 
    provider.setPasswordEncoder(new MyPasswordEncoder()); 
    auth.authenticationProvider(provider); 
} 
+0

Jeśli masz niestandardowe wiadomości Spring Security, nie zapomnij także wywołać 'provider.setMessageSource()'. –

Powiązane problemy