-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Build modules using Java 8 #10817
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Build modules using Java 8 #10817
Changes from all commits
71a6b74
9a72461
63dc3de
61794ba
85d9359
4fbf9dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
* Copyright 2002-2021 the original author or authors. | ||
* Copyright 2002-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
|
@@ -47,8 +47,6 @@ | |
import org.springframework.security.saml2.provider.service.web.authentication.logout.HttpSessionLogoutRequestRepository; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml3LogoutRequestResolver; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml3LogoutResponseResolver; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestResolver; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestFilter; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestRepository; | ||
import org.springframework.security.saml2.provider.service.web.authentication.logout.Saml2LogoutRequestResolver; | ||
|
@@ -67,6 +65,8 @@ | |
import org.springframework.security.web.util.matcher.AndRequestMatcher; | ||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher; | ||
import org.springframework.security.web.util.matcher.RequestMatcher; | ||
import org.springframework.util.ClassUtils; | ||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Adds SAML 2.0 logout support. | ||
|
@@ -113,6 +113,8 @@ | |
public final class Saml2LogoutConfigurer<H extends HttpSecurityBuilder<H>> | ||
extends AbstractHttpConfigurer<Saml2LogoutConfigurer<H>, H> { | ||
|
||
private static final String OPEN_SAML_4_VERSION = "4"; | ||
|
||
private ApplicationContext context; | ||
|
||
private RelyingPartyRegistrationRepository relyingPartyRegistrationRepository; | ||
|
@@ -304,6 +306,19 @@ private Saml2LogoutResponseResolver createSaml2LogoutResponseResolver( | |
return this.logoutResponseConfigurer.logoutResponseResolver(relyingPartyRegistrationResolver); | ||
} | ||
|
||
private String version() { | ||
String version = Version.getVersion(); | ||
if (StringUtils.hasText(version)) { | ||
return version; | ||
} | ||
boolean openSaml4ClassPresent = ClassUtils | ||
.isPresent("org.opensaml.core.xml.persist.impl.PassthroughSourceStrategy", null); | ||
if (openSaml4ClassPresent) { | ||
return OPEN_SAML_4_VERSION; | ||
} | ||
throw new IllegalStateException("cannot determine OpenSAML version"); | ||
} | ||
|
||
private <C> C getBeanOrNull(Class<C> clazz) { | ||
if (this.context == null) { | ||
return null; | ||
|
@@ -314,14 +329,6 @@ private <C> C getBeanOrNull(Class<C> clazz) { | |
return this.context.getBean(clazz); | ||
} | ||
|
||
private String version() { | ||
String version = Version.getVersion(); | ||
if (version != null) { | ||
return version; | ||
} | ||
return Version.getVersion(); | ||
} | ||
|
||
/** | ||
* A configurer for SAML 2.0 LogoutRequest components | ||
*/ | ||
|
@@ -402,7 +409,7 @@ private Saml2LogoutRequestResolver logoutRequestResolver( | |
return this.logoutRequestResolver; | ||
} | ||
if (version().startsWith("4")) { | ||
return new OpenSaml4LogoutRequestResolver(relyingPartyRegistrationResolver); | ||
return OpenSaml4LogoutSupportFactory.getLogoutRequestResolver(relyingPartyRegistrationResolver); | ||
} | ||
return new OpenSaml3LogoutRequestResolver(relyingPartyRegistrationResolver); | ||
} | ||
|
@@ -470,13 +477,13 @@ private Saml2LogoutResponseValidator logoutResponseValidator() { | |
|
||
private Saml2LogoutResponseResolver logoutResponseResolver( | ||
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver) { | ||
if (this.logoutResponseResolver == null) { | ||
if (version().startsWith("4")) { | ||
return new OpenSaml4LogoutResponseResolver(relyingPartyRegistrationResolver); | ||
} | ||
return new OpenSaml3LogoutResponseResolver(relyingPartyRegistrationResolver); | ||
if (this.logoutResponseResolver != null) { | ||
return this.logoutResponseResolver; | ||
} | ||
return this.logoutResponseResolver; | ||
if (version().startsWith("4")) { | ||
return OpenSaml4LogoutSupportFactory.getLogoutResponseResolver(relyingPartyRegistrationResolver); | ||
} | ||
return new OpenSaml3LogoutResponseResolver(relyingPartyRegistrationResolver); | ||
} | ||
|
||
} | ||
|
@@ -519,4 +526,38 @@ public void logout(HttpServletRequest request, HttpServletResponse response, Aut | |
|
||
} | ||
|
||
private static class OpenSaml4LogoutSupportFactory { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this class still necessary? I think it was necessary when it was acting as a classpath guard. However, since you are using reflection now, I don't think this class offers this same benefit. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those classes make the code cleaner by moving the try-catch from the reflective operations to another method |
||
|
||
private static Saml2LogoutResponseResolver getLogoutResponseResolver( | ||
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver) { | ||
try { | ||
Class<?> logoutResponseResolver = ClassUtils.forName( | ||
"org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutResponseResolver", | ||
OpenSaml4LogoutSupportFactory.class.getClassLoader()); | ||
return (Saml2LogoutResponseResolver) logoutResponseResolver | ||
.getDeclaredConstructor(RelyingPartyRegistrationResolver.class) | ||
.newInstance(relyingPartyRegistrationResolver); | ||
} | ||
catch (ReflectiveOperationException ex) { | ||
throw new IllegalStateException("Could not instantiate OpenSaml4LogoutResponseResolver", ex); | ||
} | ||
} | ||
|
||
private static Saml2LogoutRequestResolver getLogoutRequestResolver( | ||
RelyingPartyRegistrationResolver relyingPartyRegistrationResolver) { | ||
try { | ||
Class<?> logoutRequestResolver = ClassUtils.forName( | ||
"org.springframework.security.saml2.provider.service.web.authentication.logout.OpenSaml4LogoutRequestResolver", | ||
OpenSaml4LogoutSupportFactory.class.getClassLoader()); | ||
return (Saml2LogoutRequestResolver) logoutRequestResolver | ||
.getDeclaredConstructor(RelyingPartyRegistrationResolver.class) | ||
.newInstance(relyingPartyRegistrationResolver); | ||
} | ||
catch (ReflectiveOperationException ex) { | ||
throw new IllegalStateException("Could not instantiate OpenSaml4LogoutRequestResolver", ex); | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,11 @@ | |
import java.security.cert.CertificateFactory; | ||
import java.security.cert.X509Certificate; | ||
|
||
import javax.security.auth.x500.X500Principal; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.bouncycastle.asn1.x500.X500Name; | ||
import org.bouncycastle.asn1.x500.style.BCStyle; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import sun.security.x509.X500Name; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify how these changes pertain to the PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those changes came from the revert that I did to the old commit, where we weren't using toolchain to build the modules |
||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
|
@@ -242,8 +240,12 @@ protected void configure(HttpSecurity http) throws Exception { | |
} | ||
|
||
private String extractCommonName(X509Certificate certificate) { | ||
X500Principal principal = certificate.getSubjectX500Principal(); | ||
return new X500Name(principal.getName()).getRDNs(BCStyle.CN)[0].getFirst().getValue().toString(); | ||
try { | ||
return ((X500Name) certificate.getSubjectDN()).getCommonName(); | ||
} | ||
catch (Exception ex) { | ||
throw new IllegalArgumentException(ex); | ||
} | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it true that we don't want to run these tests against JDK 8? It seems to me that we want to run the tests twice: Once for JDK 8 and once for JDK 11.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to run they using JDK 11 only because they are using OpenSAML4 classes