|
@@ -1,5 +1,5 @@
|
|
/*
|
|
/*
|
|
- * Copyright 2002-2024 the original author or authors.
|
|
|
|
|
|
+ * Copyright 2002-2025 the original author or authors.
|
|
*
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* you may not use this file except in compliance with the License.
|
|
@@ -33,6 +33,7 @@ import org.springframework.security.web.authentication.preauth.PreAuthenticatedA
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken;
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails;
|
|
import org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails;
|
|
import org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.SubjectDnX509PrincipalExtractor;
|
|
|
|
+import org.springframework.security.web.authentication.preauth.x509.SubjectX500PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
|
|
import org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor;
|
|
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
|
|
import org.springframework.security.web.context.RequestAttributeSecurityContextRepository;
|
|
@@ -74,6 +75,7 @@ import org.springframework.security.web.context.RequestAttributeSecurityContextR
|
|
*
|
|
*
|
|
* @author Rob Winch
|
|
* @author Rob Winch
|
|
* @author Ngoc Nhan
|
|
* @author Ngoc Nhan
|
|
|
|
+ * @author Max Batischev
|
|
* @since 3.2
|
|
* @since 3.2
|
|
*/
|
|
*/
|
|
public final class X509Configurer<H extends HttpSecurityBuilder<H>>
|
|
public final class X509Configurer<H extends HttpSecurityBuilder<H>>
|
|
@@ -161,14 +163,38 @@ public final class X509Configurer<H extends HttpSecurityBuilder<H>>
|
|
* @param subjectPrincipalRegex the regex to extract the user principal from the
|
|
* @param subjectPrincipalRegex the regex to extract the user principal from the
|
|
* certificate (i.e. "CN=(.*?)(?:,|$)").
|
|
* certificate (i.e. "CN=(.*?)(?:,|$)").
|
|
* @return the {@link X509Configurer} for further customizations
|
|
* @return the {@link X509Configurer} for further customizations
|
|
|
|
+ * @deprecated Please use {{@link #extractPrincipalNameFromEmail(boolean)}} instead
|
|
*/
|
|
*/
|
|
|
|
+ @Deprecated
|
|
public X509Configurer<H> subjectPrincipalRegex(String subjectPrincipalRegex) {
|
|
public X509Configurer<H> subjectPrincipalRegex(String subjectPrincipalRegex) {
|
|
|
|
+ if (this.x509PrincipalExtractor instanceof SubjectX500PrincipalExtractor) {
|
|
|
|
+ throw new IllegalStateException(
|
|
|
|
+ "Cannot use subjectPrincipalRegex and extractPrincipalNameFromEmail together. "
|
|
|
|
+ + "Please use one or the other.");
|
|
|
|
+ }
|
|
SubjectDnX509PrincipalExtractor principalExtractor = new SubjectDnX509PrincipalExtractor();
|
|
SubjectDnX509PrincipalExtractor principalExtractor = new SubjectDnX509PrincipalExtractor();
|
|
principalExtractor.setSubjectDnRegex(subjectPrincipalRegex);
|
|
principalExtractor.setSubjectDnRegex(subjectPrincipalRegex);
|
|
this.x509PrincipalExtractor = principalExtractor;
|
|
this.x509PrincipalExtractor = principalExtractor;
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * If true then DN will be extracted from EMAIlADDRESS, defaults to {@code false}
|
|
|
|
+ * @param extractPrincipalNameFromEmail whether to extract DN from EMAIlADDRESS
|
|
|
|
+ * @since 7.0
|
|
|
|
+ */
|
|
|
|
+ public X509Configurer<H> extractPrincipalNameFromEmail(boolean extractPrincipalNameFromEmail) {
|
|
|
|
+ if (this.x509PrincipalExtractor instanceof SubjectDnX509PrincipalExtractor) {
|
|
|
|
+ throw new IllegalStateException(
|
|
|
|
+ "Cannot use subjectPrincipalRegex and extractPrincipalNameFromEmail together. "
|
|
|
|
+ + "Please use one or the other.");
|
|
|
|
+ }
|
|
|
|
+ SubjectX500PrincipalExtractor extractor = new SubjectX500PrincipalExtractor();
|
|
|
|
+ extractor.setExtractPrincipalNameFromEmail(extractPrincipalNameFromEmail);
|
|
|
|
+ this.x509PrincipalExtractor = extractor;
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void init(H http) {
|
|
public void init(H http) {
|
|
PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
|
|
PreAuthenticatedAuthenticationProvider authenticationProvider = new PreAuthenticatedAuthenticationProvider();
|