Skip to content

Commit b21f941

Browse files
Merge branch '6.1.x' into 6.2.x
Closes gh-14536
2 parents 8cd8eed + 4e5780a commit b21f941

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

cas/src/main/java/org/springframework/security/cas/web/CasAuthenticationFilter.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -303,6 +303,18 @@ public final void setServiceProperties(final ServiceProperties serviceProperties
303303
this.authenticateAllArtifacts = serviceProperties.isAuthenticateAllArtifacts();
304304
}
305305

306+
@Override
307+
public void setSecurityContextRepository(SecurityContextRepository securityContextRepository) {
308+
super.setSecurityContextRepository(securityContextRepository);
309+
this.securityContextRepository = securityContextRepository;
310+
}
311+
312+
@Override
313+
public void setSecurityContextHolderStrategy(SecurityContextHolderStrategy securityContextHolderStrategy) {
314+
super.setSecurityContextHolderStrategy(securityContextHolderStrategy);
315+
this.securityContextHolderStrategy = securityContextHolderStrategy;
316+
}
317+
306318
/**
307319
* Indicates if the request is elgible to process a service ticket. This method exists
308320
* for readability.

cas/src/test/java/org/springframework/security/cas/web/CasAuthenticationFilterTests.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2023 the original author or authors.
2+
* Copyright 2002-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,7 +16,10 @@
1616

1717
package org.springframework.security.cas.web;
1818

19+
import java.io.IOException;
20+
1921
import jakarta.servlet.FilterChain;
22+
import jakarta.servlet.ServletException;
2023
import org.apereo.cas.client.proxy.ProxyGrantingTicketStorage;
2124
import org.junit.jupiter.api.AfterEach;
2225
import org.junit.jupiter.api.Test;
@@ -34,6 +37,8 @@
3437
import org.springframework.security.core.authority.AuthorityUtils;
3538
import org.springframework.security.core.context.SecurityContext;
3639
import org.springframework.security.core.context.SecurityContextHolder;
40+
import org.springframework.security.core.context.SecurityContextHolderStrategy;
41+
import org.springframework.security.core.context.SecurityContextImpl;
3742
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
3843
import org.springframework.security.web.context.SecurityContextRepository;
3944
import org.springframework.test.util.ReflectionTestUtils;
@@ -219,4 +224,25 @@ public void successfulAuthenticationWhenProxyRequestThenSavesSecurityContext() t
219224
verify(securityContextRepository).saveContext(any(SecurityContext.class), eq(request), eq(response));
220225
}
221226

227+
@Test
228+
void successfulAuthenticationWhenSecurityContextRepositorySetThenUses() throws ServletException, IOException {
229+
SecurityContextRepository securityContextRepository = mock(SecurityContextRepository.class);
230+
CasAuthenticationFilter filter = new CasAuthenticationFilter();
231+
filter.setSecurityContextRepository(securityContextRepository);
232+
filter.successfulAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse(),
233+
new MockFilterChain(), mock(Authentication.class));
234+
verify(securityContextRepository).saveContext(any(SecurityContext.class), any(), any());
235+
}
236+
237+
@Test
238+
void successfulAuthenticationWhenSecurityContextHolderStrategySetThenUses() throws ServletException, IOException {
239+
SecurityContextHolderStrategy securityContextRepository = mock(SecurityContextHolderStrategy.class);
240+
given(securityContextRepository.createEmptyContext()).willReturn(new SecurityContextImpl());
241+
CasAuthenticationFilter filter = new CasAuthenticationFilter();
242+
filter.setSecurityContextHolderStrategy(securityContextRepository);
243+
filter.successfulAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse(),
244+
new MockFilterChain(), mock(Authentication.class));
245+
verify(securityContextRepository).setContext(any(SecurityContext.class));
246+
}
247+
222248
}

0 commit comments

Comments
 (0)