Skip to content

Commit 4e5780a

Browse files
Fix setters not working for CasAuthenticationFilter
The setSecurityContextRepository and setSecurityContextHolderStrategy only works for the parent class. This commit overrides the method and make sure that we set the objects in the super class and the CasAuthenticationFilter. Closes gh-14529
1 parent 9fb2f73 commit 4e5780a

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

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

Lines changed: 7 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.
@@ -298,6 +298,12 @@ public final void setServiceProperties(final ServiceProperties serviceProperties
298298
this.authenticateAllArtifacts = serviceProperties.isAuthenticateAllArtifacts();
299299
}
300300

301+
@Override
302+
public void setSecurityContextRepository(SecurityContextRepository securityContextRepository) {
303+
super.setSecurityContextRepository(securityContextRepository);
304+
this.securityContextRepository = securityContextRepository;
305+
}
306+
301307
/**
302308
* Indicates if the request is elgible to process a service ticket. This method exists
303309
* for readability.

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

Lines changed: 14 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;
@@ -219,4 +222,14 @@ public void successfulAuthenticationWhenProxyRequestThenSavesSecurityContext() t
219222
verify(securityContextRepository).saveContext(any(SecurityContext.class), eq(request), eq(response));
220223
}
221224

225+
@Test
226+
void successfulAuthenticationWhenSecurityContextRepositorySetThenUses() throws ServletException, IOException {
227+
SecurityContextRepository securityContextRepository = mock(SecurityContextRepository.class);
228+
CasAuthenticationFilter filter = new CasAuthenticationFilter();
229+
filter.setSecurityContextRepository(securityContextRepository);
230+
filter.successfulAuthentication(new MockHttpServletRequest(), new MockHttpServletResponse(),
231+
new MockFilterChain(), mock(Authentication.class));
232+
verify(securityContextRepository).saveContext(any(SecurityContext.class), any(), any());
233+
}
234+
222235
}

0 commit comments

Comments
 (0)