public class RegexDelegatingUserDetailsService
extends java.lang.Object
implements org.springframework.security.core.userdetails.UserDetailsService
UserDetailsService
implementation, allowing for a regular
expression to be used to extract the username from the value passed into
loadUserByUsername(String)
.
For example, if the usernames provided for authentication have the format
"john.smith@example.com", but the usernames stored in the system are without the domain
("john.smith"), this class can be used to extract the username without the domain and
pass it to the delegate UserDetailsService
.
Sample XML configuration:
<bean id="userDetailsService" class="com.appiancorp.suiteapi.common.spring.security.RegexDelegatingUserDetailsService">
<constructor-arg ref="myUserDetailsService"/>
<constructor-arg value="(.+)@(.+)"/>
<constructor-arg value="1"/>
</bean>
<bean id="myUserDetailsService" class="com.example.security.auth.MyUserDetailsService"/>
Constructor and Description |
---|
RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService,
java.util.regex.Pattern pattern,
int targetGroup)
Creates a new instance with the given properties.
|
RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService,
java.lang.String regex,
int targetGroup)
Creates a new instance with the given properties.
|
RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService,
java.lang.String regex,
int regexFlags,
int targetGroup)
Creates a new instance with the given properties.
|
Modifier and Type | Method and Description |
---|---|
protected org.springframework.security.core.userdetails.UserDetailsService |
getDelegateService() |
protected java.util.regex.Pattern |
getPattern() |
protected int |
getTargetGroup() |
org.springframework.security.core.userdetails.UserDetails |
loadUserByUsername(java.lang.String username)
Loads the user data for the given username, using the following logic:
Attempts to match the given username against the configured regular expression.
|
java.lang.String |
toString() |
public RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService, java.lang.String regex, int targetGroup)
delegateService
- The delegate UserDetailsService
which will be invoked to get
the user data.regex
- The regular expression which will used to extract the username. A Pattern
object is created from the expression using Pattern.compile(String)
.targetGroup
- The group
within the regular expression that
should be used to extract the username.public RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService, java.lang.String regex, int regexFlags, int targetGroup)
RegexDelegatingUserDetailsService(UserDetailsService, String, int)
with the
additional regexFlags
parameter, which is used to create the Pattern
object from the regular expression using Pattern.compile(String, int)
.public RegexDelegatingUserDetailsService(org.springframework.security.core.userdetails.UserDetailsService delegateService, java.util.regex.Pattern pattern, int targetGroup)
delegateService
- The delegate UserDetailsService
which will be invoked to get
the user data.pattern
- The compiled representation of a regular expression which will used to extract
the username.targetGroup
- The group
within the regular expression that
should be used to extract the username.public org.springframework.security.core.userdetails.UserDetails loadUserByUsername(java.lang.String username) throws org.springframework.security.core.userdetails.UsernameNotFoundException
group
. This value is passed
as to the configured delegate UserDetailsService
to actually load the user data.
UserDetailsService
as is.
loadUserByUsername
in interface org.springframework.security.core.userdetails.UserDetailsService
org.springframework.security.core.userdetails.UsernameNotFoundException
protected org.springframework.security.core.userdetails.UserDetailsService getDelegateService()
protected java.util.regex.Pattern getPattern()
protected int getTargetGroup()
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2003-2024 Appian Corporation. All Rights Reserved.