|
18 | 18 |
|
19 | 19 | import java.util.HashMap; |
20 | 20 | import java.util.Map; |
| 21 | +import java.util.concurrent.atomic.AtomicInteger; |
21 | 22 |
|
22 | 23 | import org.apereo.cas.client.validation.Assertion; |
23 | 24 | import org.apereo.cas.client.validation.AssertionImpl; |
|
31 | 32 | import org.springframework.security.cas.ServiceProperties; |
32 | 33 | import org.springframework.security.cas.web.authentication.ServiceAuthenticationDetails; |
33 | 34 | import org.springframework.security.core.Authentication; |
| 35 | +import org.springframework.security.core.AuthenticationException; |
34 | 36 | import org.springframework.security.core.authority.AuthorityUtils; |
35 | 37 | import org.springframework.security.core.authority.SimpleGrantedAuthority; |
36 | 38 | import org.springframework.security.core.userdetails.AuthenticationUserDetailsService; |
37 | 39 | import org.springframework.security.core.userdetails.User; |
38 | 40 | import org.springframework.security.core.userdetails.UserDetails; |
| 41 | +import org.springframework.security.core.userdetails.UserDetailsChecker; |
39 | 42 | import org.springframework.security.core.userdetails.UsernameNotFoundException; |
40 | 43 | import org.springframework.security.web.authentication.WebAuthenticationDetails; |
41 | 44 |
|
|
55 | 58 | * |
56 | 59 | * @author Ben Alex |
57 | 60 | * @author Scott Battaglia |
| 61 | + * @author Kim Youngwoong |
58 | 62 | */ |
59 | 63 | @SuppressWarnings("unchecked") |
60 | 64 | public class CasAuthenticationProviderTests { |
@@ -320,6 +324,29 @@ public void supportsRequiredTokens() { |
320 | 324 | assertThat(cap.supports(CasAuthenticationToken.class)).isTrue(); |
321 | 325 | } |
322 | 326 |
|
| 327 | + @Test |
| 328 | + public void testSetUserDetailsChecker() throws AuthenticationException { |
| 329 | + CasAuthenticationProvider cap = new CasAuthenticationProvider(); |
| 330 | + cap.setAuthenticationUserDetailsService(new MockAuthoritiesPopulator()); |
| 331 | + cap.setKey("qwerty"); |
| 332 | + cap.setTicketValidator(new MockTicketValidator(true)); |
| 333 | + cap.setServiceProperties(makeServiceProperties()); |
| 334 | + cap.afterPropertiesSet(); |
| 335 | + CasServiceTicketAuthenticationToken token = CasServiceTicketAuthenticationToken.stateful("ST-123"); |
| 336 | + |
| 337 | + AtomicInteger checkCount = new AtomicInteger(0); |
| 338 | + UserDetailsChecker userDetailsChecker = new UserDetailsChecker() { |
| 339 | + @Override |
| 340 | + public void check(UserDetails user) { |
| 341 | + checkCount.incrementAndGet(); |
| 342 | + } |
| 343 | + }; |
| 344 | + cap.setUserDetailsChecker(userDetailsChecker); |
| 345 | + cap.authenticate(token); |
| 346 | + |
| 347 | + assertThat(checkCount.get()).isEqualTo(1); |
| 348 | + } |
| 349 | + |
323 | 350 | private class MockAuthoritiesPopulator implements AuthenticationUserDetailsService { |
324 | 351 |
|
325 | 352 | @Override |
|
0 commit comments