|
16 | 16 |
|
17 | 17 | package org.springframework.security.authentication.dao;
|
18 | 18 |
|
| 19 | +import java.util.ArrayList; |
| 20 | +import java.util.Collection; |
| 21 | + |
19 | 22 | import org.apache.commons.logging.Log;
|
20 | 23 | import org.apache.commons.logging.LogFactory;
|
21 | 24 |
|
|
33 | 36 | import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
34 | 37 | import org.springframework.security.core.Authentication;
|
35 | 38 | import org.springframework.security.core.AuthenticationException;
|
| 39 | +import org.springframework.security.core.GrantedAuthority; |
36 | 40 | import org.springframework.security.core.SpringSecurityMessageSource;
|
37 | 41 | import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
38 | 42 | import org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper;
|
@@ -200,12 +204,11 @@ protected Authentication createSuccessAuthentication(Object principal, Authentic
|
200 | 204 | // so subsequent attempts are successful even with encoded passwords.
|
201 | 205 | // Also ensure we return the original getDetails(), so that future
|
202 | 206 | // authentication events after cache expiry contain the details
|
203 |
| - UsernamePasswordAuthenticationToken result = UsernamePasswordAuthenticationToken |
204 |
| - .authenticated(principal, authentication.getCredentials(), |
205 |
| - this.authoritiesMapper.mapAuthorities(user.getAuthorities())) |
206 |
| - .toBuilder() |
207 |
| - .authorities((a) -> a.add(new SimpleGrantedAuthority(AUTHORITY))) |
208 |
| - .build(); |
| 207 | + Collection<GrantedAuthority> authorities = new ArrayList<>( |
| 208 | + this.authoritiesMapper.mapAuthorities(user.getAuthorities())); |
| 209 | + authorities.add(new SimpleGrantedAuthority(AUTHORITY)); |
| 210 | + UsernamePasswordAuthenticationToken result = UsernamePasswordAuthenticationToken.authenticated(principal, |
| 211 | + authentication.getCredentials(), authorities); |
209 | 212 | result.setDetails(authentication.getDetails());
|
210 | 213 | this.logger.debug("Authenticated user");
|
211 | 214 | return result;
|
|
0 commit comments