|  | 
| 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. | 
| @@ -628,6 +628,22 @@ public void saveContextWhenTransientAuthenticationWithCustomAnnotationThenSkippe | 
| 628 | 628 | 		assertThat(session).isNull(); | 
| 629 | 629 | 	} | 
| 630 | 630 | 
 | 
|  | 631 | +	// gh-8947 | 
|  | 632 | +	@Test | 
|  | 633 | +	public void saveContextWhenSecurityContextAuthenticationUpdatedToNullThenSkipped() { | 
|  | 634 | +		HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository(); | 
|  | 635 | +		MockHttpServletRequest request = new MockHttpServletRequest(); | 
|  | 636 | +		MockHttpServletResponse response = new MockHttpServletResponse(); | 
|  | 637 | +		HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response); | 
|  | 638 | +		SomeOtherTransientAuthentication authentication = new SomeOtherTransientAuthentication(); | 
|  | 639 | +		repo.loadContext(holder); | 
|  | 640 | +		SecurityContext context = mock(SecurityContext.class); | 
|  | 641 | +		given(context.getAuthentication()).willReturn(authentication).willReturn(null); | 
|  | 642 | +		repo.saveContext(context, holder.getRequest(), holder.getResponse()); | 
|  | 643 | +		MockHttpSession session = (MockHttpSession) request.getSession(false); | 
|  | 644 | +		assertThat(session).isNull(); | 
|  | 645 | +	} | 
|  | 646 | + | 
| 631 | 647 | 	private SecurityContext createSecurityContext(UserDetails userDetails) { | 
| 632 | 648 | 		UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails, | 
| 633 | 649 | 				userDetails.getPassword(), userDetails.getAuthorities()); | 
|  | 
0 commit comments