Login with UsernamePasswordAuthenticationToken and PasswordEncoder
<p>I did not encode my password until now and therefore the code at bottom worked fine. 
Now the password is encoded with PasswordEncoder at signup, therefore the hashed password is in database - as it should be.     </p>

<p>My question now would be how to do it now with <strong>UsernamePasswordAuthenticationToken</strong>. If I pass i the encoded password the login failes? Is there another class where I can put in the encoded password?</p>

<pre><code>final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(usernameOrEmailAddress, password);
</code></pre>

<p>Here is my login methode:</p>

<pre><code>@RequestMapping(value = "/login", method = { RequestMethod.POST }, consumes = "application/json;charset=utf-8")
public UserTransferObject login(final @RequestBody LoginData loginData) throws BusinessException {

    final String usernameOrEmailAddress = loginData.getUsername();
    final String password = loginData.getPassword();

    // passwordEncoded does not work here
    final UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(usernameOrEmailAddress, password);
    try {
        final Authentication authentication = this.authenticationManager.authenticate(token);
        SecurityContextHolder.getContext().setAuthentication(authentication);
    } catch (Exception e) {
        final String message = messageByLocaleService.getMessage("login.error"); // key declared in frontend project
        throw new BusinessException(message, "400", e.getCause());
    }

    final UserDetails userDetails = this.userDetailsService.loadUserByUsername(usernameOrEmailAddress);
</code></pre>

<p>Here I get the problem, die AuthenticationManager can not authenticate when I user encoded password - I get a BadCredentialsException exception: </p>

<pre><code>final Authentication authentication = this.authenticationManager.authenticate(token);
</code></pre>

<p><strong>[EDIT]</strong></p>

<p>I recognized that I have another problem. In method <strong>login</strong> username and plain password came in and then I calculate the hash and salt with <strong>PasswordEncoder</strong>. Than <strong>authenticationManager.authenticate</strong> loads user from database but in database the user have another hashed password because the salt was different at creation time 
Actually my approach to solve this would be to disable the salt but then the security is wearer. I would be thankful for any hint solving this.</p>