|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2016 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2021 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -628,6 +628,22 @@ public class HttpSessionSecurityContextRepositoryTests {
|
|
assertThat(session).isNull();
|
|
assertThat(session).isNull();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // gh-8947
|
|
|
|
+ @Test
|
|
|
|
+ public void saveContextWhenSecurityContextAuthenticationUpdatedToNullThenSkipped() {
|
|
|
|
+ HttpSessionSecurityContextRepository repo = new HttpSessionSecurityContextRepository();
|
|
|
|
+ MockHttpServletRequest request = new MockHttpServletRequest();
|
|
|
|
+ MockHttpServletResponse response = new MockHttpServletResponse();
|
|
|
|
+ HttpRequestResponseHolder holder = new HttpRequestResponseHolder(request, response);
|
|
|
|
+ SomeOtherTransientAuthentication authentication = new SomeOtherTransientAuthentication();
|
|
|
|
+ repo.loadContext(holder);
|
|
|
|
+ SecurityContext context = mock(SecurityContext.class);
|
|
|
|
+ given(context.getAuthentication()).willReturn(authentication).willReturn(null);
|
|
|
|
+ repo.saveContext(context, holder.getRequest(), holder.getResponse());
|
|
|
|
+ MockHttpSession session = (MockHttpSession) request.getSession(false);
|
|
|
|
+ assertThat(session).isNull();
|
|
|
|
+ }
|
|
|
|
+
|
|
private SecurityContext createSecurityContext(UserDetails userDetails) {
|
|
private SecurityContext createSecurityContext(UserDetails userDetails) {
|
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails,
|
|
UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userDetails,
|
|
userDetails.getPassword(), userDetails.getAuthorities());
|
|
userDetails.getPassword(), userDetails.getAuthorities());
|