Skip to content

Commit 60ed360

Browse files
Make source code compatible with JDK 8
Closes spring-projectsgh-10695
1 parent 214cfe8 commit 60ed360

File tree

7 files changed

+31
-132
lines changed

7 files changed

+31
-132
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ subprojects {
105105
tasks.withType(JavaCompile) {
106106
options.encoding = "UTF-8"
107107
options.compilerArgs.add("-parameters")
108+
options.release = 8
108109
}
109110
}
110111

config/src/main/java/org/springframework/security/config/annotation/web/configurers/oauth2/server/resource/OAuth2ResourceServerConfigurer.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.util.Arrays;
2020
import java.util.Collections;
21+
import java.util.HashMap;
2122
import java.util.LinkedHashMap;
2223
import java.util.Map;
2324
import java.util.function.Supplier;
@@ -27,6 +28,7 @@
2728
import org.springframework.context.ApplicationContext;
2829
import org.springframework.core.convert.converter.Converter;
2930
import org.springframework.http.MediaType;
31+
import org.springframework.security.access.AccessDeniedException;
3032
import org.springframework.security.authentication.AbstractAuthenticationToken;
3133
import org.springframework.security.authentication.AuthenticationManager;
3234
import org.springframework.security.authentication.AuthenticationManagerResolver;
@@ -159,13 +161,18 @@ public final class OAuth2ResourceServerConfigurer<H extends HttpSecurityBuilder<
159161
private OpaqueTokenConfigurer opaqueTokenConfigurer;
160162

161163
private AccessDeniedHandler accessDeniedHandler = new DelegatingAccessDeniedHandler(
162-
new LinkedHashMap<>(Map.of(CsrfException.class, new AccessDeniedHandlerImpl())),
163-
new BearerTokenAccessDeniedHandler());
164+
new LinkedHashMap<>(createAccessDeniedHandlers()), new BearerTokenAccessDeniedHandler());
164165

165166
private AuthenticationEntryPoint authenticationEntryPoint = new BearerTokenAuthenticationEntryPoint();
166167

167168
private BearerTokenRequestMatcher requestMatcher = new BearerTokenRequestMatcher();
168169

170+
private static Map<Class<? extends AccessDeniedException>, AccessDeniedHandler> createAccessDeniedHandlers() {
171+
Map<Class<? extends AccessDeniedException>, AccessDeniedHandler> handlers = new HashMap<>();
172+
handlers.put(CsrfException.class, new AccessDeniedHandlerImpl());
173+
return handlers;
174+
}
175+
169176
public OAuth2ResourceServerConfigurer(ApplicationContext context) {
170177
Assert.notNull(context, "context cannot be null");
171178
this.context = context;

config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LoginConfigurer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,7 @@ private String version() {
297297
if (version != null) {
298298
return version;
299299
}
300-
return Version.class.getModule().getDescriptor().version().map(Object::toString)
301-
.orElseThrow(() -> new IllegalStateException("cannot determine OpenSAML version"));
300+
return Version.getVersion();
302301
}
303302

304303
private void registerDefaultAuthenticationProvider(B http) {

config/src/main/java/org/springframework/security/config/annotation/web/configurers/saml2/Saml2LogoutConfigurer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,7 @@ private String version() {
319319
if (version != null) {
320320
return version;
321321
}
322-
return Version.class.getModule().getDescriptor().version().map(Object::toString)
323-
.orElseThrow(() -> new IllegalStateException("cannot determine OpenSAML version"));
322+
return Version.getVersion();
324323
}
325324

326325
/**

config/src/test/java/org/springframework/security/config/annotation/web/configurers/NamespaceHttpX509Tests.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
import java.security.cert.CertificateFactory;
2222
import java.security.cert.X509Certificate;
2323

24+
import javax.security.auth.x500.X500Principal;
2425
import javax.servlet.http.HttpServletRequest;
2526

27+
import org.bouncycastle.asn1.x500.X500Name;
28+
import org.bouncycastle.asn1.x500.style.BCStyle;
2629
import org.junit.jupiter.api.Test;
2730
import org.junit.jupiter.api.extension.ExtendWith;
28-
import sun.security.x509.X500Name;
2931

3032
import org.springframework.beans.factory.annotation.Autowired;
3133
import org.springframework.context.annotation.Bean;
@@ -240,12 +242,8 @@ protected void configure(HttpSecurity http) throws Exception {
240242
}
241243

242244
private String extractCommonName(X509Certificate certificate) {
243-
try {
244-
return ((X500Name) certificate.getSubjectDN()).getCommonName();
245-
}
246-
catch (Exception ex) {
247-
throw new IllegalArgumentException(ex);
248-
}
245+
X500Principal principal = certificate.getSubjectX500Principal();
246+
return new X500Name(principal.getName()).getRDNs(BCStyle.CN)[0].getFirst().getValue().toString();
249247
}
250248

251249
}

core/src/test/java/org/springframework/security/core/SpringSecurityCoreVersionTests.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.lang.reflect.Field;
2020
import java.lang.reflect.Method;
21+
import java.lang.reflect.Modifier;
2122

2223
import org.apache.commons.logging.Log;
2324
import org.apache.commons.logging.LogFactory;
@@ -60,15 +61,24 @@ public class SpringSecurityCoreVersionTests {
6061

6162
@BeforeEach
6263
public void setup() throws Exception {
63-
Field logger = ReflectionUtils.findField(SpringSecurityCoreVersion.class, "logger");
64-
StaticFinalReflectionUtils.setField(logger, this.logger);
64+
setFinalStaticField(SpringSecurityCoreVersion.class, "logger", this.logger);
6565
}
6666

6767
@AfterEach
6868
public void cleanup() throws Exception {
6969
System.clearProperty(getDisableChecksProperty());
70-
Field logger = ReflectionUtils.findField(SpringSecurityCoreVersion.class, "logger");
71-
StaticFinalReflectionUtils.setField(logger, LogFactory.getLog(SpringSecurityCoreVersion.class));
70+
setFinalStaticField(SpringSecurityCoreVersion.class, "logger",
71+
LogFactory.getLog(SpringSecurityCoreVersion.class));
72+
}
73+
74+
private static void setFinalStaticField(Class<?> clazz, String fieldName, Object value)
75+
throws ReflectiveOperationException {
76+
Field field = clazz.getDeclaredField(fieldName);
77+
field.setAccessible(true);
78+
Field modifiers = Field.class.getDeclaredField("modifiers");
79+
modifiers.setAccessible(true);
80+
modifiers.setInt(field, field.getModifiers() & ~Modifier.FINAL);
81+
field.set(null, value);
7282
}
7383

7484
@Test

core/src/test/java/org/springframework/security/core/StaticFinalReflectionUtils.java

Lines changed: 0 additions & 115 deletions
This file was deleted.

0 commit comments

Comments
 (0)