Skip to content

Commit 9527a4b

Browse files
committed
Merge branch '7.0.x'
2 parents 2ada3f0 + 77fe9e8 commit 9527a4b

4 files changed

Lines changed: 125 additions & 0 deletions

File tree

config/src/test/java/org/springframework/security/config/http/HttpHeadersConfigTests.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,17 @@
2828
import org.junit.jupiter.api.Test;
2929
import org.junit.jupiter.api.extension.ExtendWith;
3030

31+
import org.springframework.beans.BeansException;
3132
import org.springframework.beans.factory.BeanCreationException;
3233
import org.springframework.beans.factory.annotation.Autowired;
34+
import org.springframework.beans.factory.config.BeanPostProcessor;
3335
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
3436
import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException;
3537
import org.springframework.security.config.test.SpringTestContext;
3638
import org.springframework.security.config.test.SpringTestContextExtension;
3739
import org.springframework.security.core.Authentication;
3840
import org.springframework.security.web.authentication.session.SessionLimit;
41+
import org.springframework.security.web.header.HeaderWriterFilter;
3942
import org.springframework.test.web.servlet.MockMvc;
4043
import org.springframework.test.web.servlet.ResultMatcher;
4144
import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder;
@@ -150,6 +153,16 @@ public void requestWhenHeadersElementUsedThenResponseContainsAllSecureHeaders()
150153
// @formatter:on
151154
}
152155

156+
@Test
157+
public void requestWhenHeadersEagerlyConfiguredThenHeadersAreWritten() throws Exception {
158+
this.spring.configLocations(this.xml("HeadersEagerlyConfigured")).autowire();
159+
// @formatter:off
160+
this.mvc.perform(get("/").secure(true))
161+
.andExpect(status().isOk())
162+
.andExpect(includesDefaults());
163+
// @formatter:on
164+
}
165+
153166
@Test
154167
public void requestWhenFrameOptionsConfiguredThenIncludesHeader() throws Exception {
155168
Map<String, String> headers = new HashMap<>(defaultHeaders);
@@ -955,6 +968,18 @@ public String ok() {
955968

956969
}
957970

971+
public static class EagerHeadersBeanPostProcessor implements BeanPostProcessor {
972+
973+
@Override
974+
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
975+
if (bean instanceof HeaderWriterFilter headerWriterFilter) {
976+
headerWriterFilter.setShouldWriteHeadersEagerly(true);
977+
}
978+
return bean;
979+
}
980+
981+
}
982+
958983
public static class CustomSessionLimit implements SessionLimit {
959984

960985
@Override
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2004-present the original author or authors.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ https://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<b:beans xmlns:b="http://www.springframework.org/schema/beans"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xmlns="http://www.springframework.org/schema/security"
21+
xsi:schemaLocation="
22+
http://www.springframework.org/schema/security
23+
https://www.springframework.org/schema/security/spring-security.xsd
24+
http://www.springframework.org/schema/beans
25+
https://www.springframework.org/schema/beans/spring-beans.xsd">
26+
27+
<http auto-config="true">
28+
<headers/>
29+
<intercept-url pattern="/**" access="permitAll"/>
30+
</http>
31+
32+
<b:bean class="org.springframework.security.config.http.HttpHeadersConfigTests.EagerHeadersBeanPostProcessor"/>
33+
34+
<b:bean name="simple" class="org.springframework.security.config.http.HttpHeadersConfigTests.SimpleController"/>
35+
36+
<b:import resource="userservice.xml"/>
37+
</b:beans>

oauth2/oauth2-core/src/main/java/org/springframework/security/oauth2/core/oidc/user/DefaultOidcUser.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.Serial;
2020
import java.util.Collection;
2121
import java.util.Map;
22+
import java.util.Objects;
2223

2324
import org.jspecify.annotations.Nullable;
2425

@@ -116,4 +117,38 @@ public OidcIdToken getIdToken() {
116117
return this.userInfo;
117118
}
118119

120+
@Override
121+
public boolean equals(Object obj) {
122+
if (this == obj) {
123+
return true;
124+
}
125+
if (obj == null || this.getClass() != obj.getClass()) {
126+
return false;
127+
}
128+
DefaultOidcUser that = (DefaultOidcUser) obj;
129+
if (!this.getName().equals(that.getName())) {
130+
return false;
131+
}
132+
if (!this.getAuthorities().equals(that.getAuthorities())) {
133+
return false;
134+
}
135+
if (this.getIdToken().getIssuer() == null || that.getIdToken().getIssuer() == null) {
136+
return false;
137+
}
138+
return Objects.equals(this.getIdToken().getIssuer().toExternalForm(),
139+
that.getIdToken().getIssuer().toExternalForm())
140+
&& Objects.equals(this.getIdToken().getSubject(), that.getIdToken().getSubject());
141+
}
142+
143+
@Override
144+
public int hashCode() {
145+
int result = this.getName().hashCode();
146+
result = 31 * result + this.getAuthorities().hashCode();
147+
result = 31 * result + ((this.getIdToken().getIssuer() != null)
148+
? this.getIdToken().getIssuer().toExternalForm().hashCode() : 0);
149+
result = 31 * result
150+
+ ((this.getIdToken().getSubject() != null) ? this.getIdToken().getSubject().hashCode() : 0);
151+
return result;
152+
}
153+
119154
}

oauth2/oauth2-core/src/test/java/org/springframework/security/oauth2/core/oidc/user/DefaultOidcUserTests.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.security.oauth2.core.oidc.user;
1818

1919
import java.time.Instant;
20+
import java.time.temporal.ChronoUnit;
2021
import java.util.Collections;
2122
import java.util.HashMap;
2223
import java.util.Map;
@@ -147,4 +148,31 @@ public void constructorWhenAllParametersProvidedAndValidThenCreated() {
147148
StandardClaimNames.NAME, StandardClaimNames.EMAIL);
148149
}
149150

151+
// gh-18622
152+
@Test
153+
public void equalsWhenOidcUserPrincipalSameThenTrue() {
154+
String issuer = "https://example.com";
155+
String subject = "subject-1";
156+
157+
// @formatter:off
158+
OidcIdToken idToken1 = OidcIdToken.withTokenValue("id-token-value-1")
159+
.issuer(issuer)
160+
.subject(subject)
161+
.issuedAt(Instant.now())
162+
.expiresAt(Instant.now().plus(30, ChronoUnit.MINUTES))
163+
.build();
164+
165+
OidcIdToken idToken2 = OidcIdToken.withTokenValue("id-token-value-2")
166+
.issuer(issuer)
167+
.subject(subject)
168+
.issuedAt(Instant.now())
169+
.expiresAt(Instant.now().plus(30, ChronoUnit.MINUTES))
170+
.build();
171+
// @formatter:on
172+
173+
DefaultOidcUser user1 = new DefaultOidcUser(AUTHORITIES, idToken1, USER_INFO);
174+
DefaultOidcUser user2 = new DefaultOidcUser(AUTHORITIES, idToken2, USER_INFO);
175+
assertThat(user1).isEqualTo(user2);
176+
}
177+
150178
}

0 commit comments

Comments
 (0)