Class X509Configurer<H extends HttpSecurityBuilder<H>>
- java.lang.Object
-
- org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,B>
-
- org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer<X509Configurer<H>,H>
-
- org.springframework.security.config.annotation.web.configurers.X509Configurer<H>
-
- All Implemented Interfaces:
SecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H>
public final class X509Configurer<H extends HttpSecurityBuilder<H>> extends AbstractHttpConfigurer<X509Configurer<H>,H>
Adds X509 based pre authentication to an application. Since validating the certificate happens when the client connects, the requesting and validation of the client certificate should be performed by the container. Spring Security will then use the certificate to look up theAuthenticationfor the user.Security Filters
The following Filters are populated
X509AuthenticationFilter
Shared Objects Created
The following shared objects are created
AuthenticationEntryPointis populated with anHttp403ForbiddenEntryPoint- A
PreAuthenticatedAuthenticationProvideris populated intoHttpSecurity.authenticationProvider(org.springframework.security.authentication.AuthenticationProvider)
Shared Objects Used
The following shared objects are used:
- A
UserDetailsServiceshared object is used if noAuthenticationUserDetailsServiceis specified
- Since:
- 3.2
-
-
Constructor Summary
Constructors Constructor Description X509Configurer()Creates a new instance
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description X509Configurer<H>authenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails> authenticationDetailsSource)Specifies theAuthenticationDetailsSourceX509Configurer<H>authenticationUserDetailsService(org.springframework.security.core.userdetails.AuthenticationUserDetailsService<org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken> authenticationUserDetailsService)Specifies theAuthenticationUserDetailsServiceto use.voidconfigure(H http)Configure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.voidinit(H http)Initialize theSecurityBuilder.X509Configurer<H>subjectPrincipalRegex(java.lang.String subjectPrincipalRegex)Specifies the regex to extract the principal from the certificate.X509Configurer<H>userDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService)Shortcut for invokingauthenticationUserDetailsService(AuthenticationUserDetailsService)with aUserDetailsByNameServiceWrapper.X509Configurer<H>x509AuthenticationFilter(org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter x509AuthenticationFilter)Allows specifying the entireX509AuthenticationFilter.X509Configurer<H>x509PrincipalExtractor(org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor x509PrincipalExtractor)Specifies theX509PrincipalExtractor-
Methods inherited from class org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer
disable, withObjectPostProcessor
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, postProcess, setBuilder
-
-
-
-
Constructor Detail
-
X509Configurer
public X509Configurer()
Creates a new instance- See Also:
HttpSecurity.x509()
-
-
Method Detail
-
x509AuthenticationFilter
public X509Configurer<H> x509AuthenticationFilter(org.springframework.security.web.authentication.preauth.x509.X509AuthenticationFilter x509AuthenticationFilter)
Allows specifying the entireX509AuthenticationFilter. If this is specified, the properties onX509Configurerwill not be populated on theX509AuthenticationFilter.- Parameters:
x509AuthenticationFilter- theX509AuthenticationFilterto use- Returns:
- the
X509Configurerfor further customizations
-
x509PrincipalExtractor
public X509Configurer<H> x509PrincipalExtractor(org.springframework.security.web.authentication.preauth.x509.X509PrincipalExtractor x509PrincipalExtractor)
Specifies theX509PrincipalExtractor- Parameters:
x509PrincipalExtractor- theX509PrincipalExtractorto use- Returns:
- the
X509Configurerto use
-
authenticationDetailsSource
public X509Configurer<H> authenticationDetailsSource(org.springframework.security.authentication.AuthenticationDetailsSource<javax.servlet.http.HttpServletRequest,org.springframework.security.web.authentication.preauth.PreAuthenticatedGrantedAuthoritiesWebAuthenticationDetails> authenticationDetailsSource)
Specifies theAuthenticationDetailsSource- Parameters:
authenticationDetailsSource- theAuthenticationDetailsSourceto use- Returns:
- the
X509Configurerto use
-
userDetailsService
public X509Configurer<H> userDetailsService(org.springframework.security.core.userdetails.UserDetailsService userDetailsService)
Shortcut for invokingauthenticationUserDetailsService(AuthenticationUserDetailsService)with aUserDetailsByNameServiceWrapper.- Parameters:
userDetailsService- theUserDetailsServiceto use- Returns:
- the
X509Configurerfor further customizations
-
authenticationUserDetailsService
public X509Configurer<H> authenticationUserDetailsService(org.springframework.security.core.userdetails.AuthenticationUserDetailsService<org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken> authenticationUserDetailsService)
Specifies theAuthenticationUserDetailsServiceto use. If not specified, then theUserDetailsServicebean will be used by default.- Parameters:
authenticationUserDetailsService- theAuthenticationUserDetailsServiceto use- Returns:
- the
X509Configurerfor further customizations
-
subjectPrincipalRegex
public X509Configurer<H> subjectPrincipalRegex(java.lang.String subjectPrincipalRegex)
Specifies the regex to extract the principal from the certificate. If not specified, the default expression fromSubjectDnX509PrincipalExtractoris used.- Parameters:
subjectPrincipalRegex- the regex to extract the user principal from the certificate (i.e. "CN=(.*?)(?:,|$)").- Returns:
- the
X509Configurerfor further customizations
-
init
public void init(H http)
Description copied from interface:SecurityConfigurerInitialize theSecurityBuilder. Here only shared state should be created and modified, but not properties on theSecurityBuilderused for building the object. This ensures that theSecurityConfigurer.configure(SecurityBuilder)method uses the correct shared objects when building. Configurers should be applied here.- Specified by:
initin interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
initin classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
configure
public void configure(H http)
Description copied from interface:SecurityConfigurerConfigure theSecurityBuilderby setting the necessary properties on theSecurityBuilder.- Specified by:
configurein interfaceSecurityConfigurer<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>- Overrides:
configurein classSecurityConfigurerAdapter<org.springframework.security.web.DefaultSecurityFilterChain,H extends HttpSecurityBuilder<H>>
-
-