|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2016 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
53 | 53 |
|
54 | 54 | import static org.assertj.core.api.Assertions.assertThat;
|
55 | 55 | import static org.mockito.ArgumentMatchers.anyBoolean;
|
| 56 | +import static org.mockito.BDDMockito.given; |
56 | 57 | import static org.mockito.Mockito.never;
|
57 | 58 | import static org.mockito.Mockito.reset;
|
58 | 59 | import static org.mockito.Mockito.verify;
|
@@ -719,6 +720,22 @@ public void saveContextWhenTransientAuthenticationWithCustomAnnotationThenSkippe
|
719 | 720 | assertThat(session).isNull();
|
720 | 721 | }
|
721 | 722 |
|
| 723 | + // gh-8947 |
| 724 | + @Test |
| 725 | + public void saveContextWhenSecurityContextAuthenticationUpdatedToNullThenSkipped() { |
| 726 | + HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository(); |
| 727 | + MockHttpServletRequest request = new MockHttpServletRequest(); |
| 728 | + MockHttpServletResponse response = new MockHttpServletResponse(); |
| 729 | + HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response); |
| 730 | + SomeOtherTransientAuthentication authentication = new SomeOtherTransientAuthentication(); |
| 731 | + repo.loadContext(holder); |
| 732 | + SecurityContext context = mock(SecurityContext.class); |
| 733 | + given(context.getAuthentication()).willReturn(authentication).willReturn(null); |
| 734 | + repo.saveContext(context, holder.getRequest(), holder.getResponse()); |
| 735 | + MockHttpSession session = (MockHttpSession) request.getSession(false); |
| 736 | + assertThat(session).isNull(); |
| 737 | + } |
| 738 | + |
722 | 739 | private SecurityContext createSecurityContext(UserDetails userDetails) {
|
723 | 740 | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails,
|
724 | 741 | userDetails.getPassword(), userDetails.getAuthorities());
|
|
0 commit comments