Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You don't autowire the <code>SaltSource</code> when adding user. The <code>SaltSource</code> is an abstraction used by Spring to provide the source of the salt for <strong>password checking only</strong>.</p> <p>To create a properly encoded password hash You just past the salt itself to the <code>PasswordEncoder</code> - the value of <code>username</code> property, not the <code>SaltSource</code>:</p> <pre><code>private PasswordEncoder encoder = new Md5PasswordEncoder(); public User createUser(String username, String plainTextPassword) { User u = new User(); u.setUsername(username); u.setPassword(encoder.encodePassword(plainTextPassword, username)); getEntityManager().persist(u); // optional return u; } </code></pre> <hr> <p>Moreover the autowire of <code>SaltSource</code> won't work until it's defined as an inner bean. You could define the <code>ReflectionSaltSource</code> as top level bean and pass it's ID to the <code>password-encoder</code>, i.e.:</p> <pre><code>&lt;bean id="saltSource" class="org.springframework.security.authentication.dao.ReflectionSaltSource" p:userPropertyToUse="username" /&gt; &lt;bean id="passwordEncoder" class="org.springframework.security.authentication.encoding.Md5PasswordEncoder" /&gt; &lt;bean id="daoAuthenticationProvider" class="org.springframework.security.authentication.dao.DaoAuthenticationProvider" p:passwordEncoder-ref="passwordEncoder" p:saltSource-ref="saltSource" p:userDetailsService-ref="userDetailsService" /&gt; &lt;authentication-manager&gt; &lt;authentication-provider ref="daoAuthenticationProvider" /&gt; &lt;/authentication-manager&gt; </code></pre> <p>And then:</p> <pre><code>@Autowired private PasswordEncoder passwordEncoder; @Autowired private SaltSource saltSource; public CustomUserDetails createUser(String username, String plainTextPassword) { CustomUserDetails u = new CustomUserDetails(); u.setUsername(username); u.setPassword(passwordEncoder.encodePassword( plainTextPassword, saltSource.getSalt(u))); getEntityNamager().persist(u); // optional return u; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload