Class JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>
- java.lang.Object
-
- org.springframework.security.config.annotation.SecurityConfigurerAdapter<AuthenticationManager,B>
-
- org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsAwareConfigurer<B,U>
-
- org.springframework.security.config.annotation.authentication.configurers.userdetails.AbstractDaoAuthenticationConfigurer<B,C,U>
-
- org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer<B,C,UserDetailsManager>
-
- org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer<B,JdbcUserDetailsManagerConfigurer<B>>
-
- org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer<B>
-
- Type Parameters:
B
- the type of theProviderManagerBuilder
that is being configured
- All Implemented Interfaces:
SecurityConfigurer<AuthenticationManager,B>
public class JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>> extends UserDetailsManagerConfigurer<B,JdbcUserDetailsManagerConfigurer<B>>
Configures anAuthenticationManagerBuilder
to have JDBC authentication. It also allows easily adding users to the database used for authentication and setting up the schema.The only required method is the
dataSource(javax.sql.DataSource)
all other methods have reasonable defaults.- Since:
- 3.2
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer
UserDetailsManagerConfigurer.UserDetailsBuilder
-
-
Constructor Summary
Constructors Constructor Description JdbcUserDetailsManagerConfigurer()
JdbcUserDetailsManagerConfigurer(JdbcUserDetailsManager manager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description JdbcUserDetailsManagerConfigurer<B>
authoritiesByUsernameQuery(java.lang.String query)
Sets the query to be used for finding a user's authorities by their username.JdbcUserDetailsManagerConfigurer<B>
dataSource(javax.sql.DataSource dataSource)
Populates theDataSource
to be used.protected org.springframework.jdbc.datasource.init.DatabasePopulator
getDatabasePopulator()
JdbcUserDetailsManager
getUserDetailsService()
Gets theUserDetailsService
that is used with theDaoAuthenticationProvider
JdbcUserDetailsManagerConfigurer<B>
groupAuthoritiesByUsername(java.lang.String query)
An SQL statement to query user's group authorities given a username.protected void
initUserDetailsService()
Populates the users that have been added.JdbcUserDetailsManagerConfigurer<B>
rolePrefix(java.lang.String rolePrefix)
A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "").JdbcUserDetailsManagerConfigurer<B>
userCache(UserCache userCache)
Defines theUserCache
to useJdbcUserDetailsManagerConfigurer<B>
usersByUsernameQuery(java.lang.String query)
Sets the query to be used for finding a user by their username.JdbcUserDetailsManagerConfigurer<B>
withDefaultSchema()
Populates the default schema that allows users and authorities to be stored.-
Methods inherited from class org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer
withUser, withUser, withUser
-
Methods inherited from class org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer
configure
-
Methods inherited from class org.springframework.security.config.annotation.authentication.configurers.userdetails.AbstractDaoAuthenticationConfigurer
passwordEncoder, userDetailsPasswordManager, withObjectPostProcessor
-
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, init, postProcess, setBuilder
-
-
-
-
Constructor Detail
-
JdbcUserDetailsManagerConfigurer
public JdbcUserDetailsManagerConfigurer(JdbcUserDetailsManager manager)
-
JdbcUserDetailsManagerConfigurer
public JdbcUserDetailsManagerConfigurer()
-
-
Method Detail
-
dataSource
public JdbcUserDetailsManagerConfigurer<B> dataSource(javax.sql.DataSource dataSource)
Populates theDataSource
to be used. This is the only required attribute.- Parameters:
dataSource
- theDataSource
to be used. Cannot be null.- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
usersByUsernameQuery
public JdbcUserDetailsManagerConfigurer<B> usersByUsernameQuery(java.lang.String query)
Sets the query to be used for finding a user by their username. For example:select username,password,enabled from users where username = ?
- Parameters:
query
- The query to use for selecting the username, password, and if the user is enabled by username. Must contain a single parameter for the username.- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
authoritiesByUsernameQuery
public JdbcUserDetailsManagerConfigurer<B> authoritiesByUsernameQuery(java.lang.String query)
Sets the query to be used for finding a user's authorities by their username. For example:select username,authority from authorities where username = ?
- Parameters:
query
- The query to use for selecting the username, authority by username. Must contain a single parameter for the username.- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
groupAuthoritiesByUsername
public JdbcUserDetailsManagerConfigurer<B> groupAuthoritiesByUsername(java.lang.String query)
An SQL statement to query user's group authorities given a username. For example:select g.id, g.group_name, ga.authority from groups g, group_members gm, group_authorities ga where gm.username = ? and g.id = ga.group_id and g.id = gm.group_id
- Parameters:
query
- The query to use for selecting the authorities by group. Must contain a single parameter for the username.- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
rolePrefix
public JdbcUserDetailsManagerConfigurer<B> rolePrefix(java.lang.String rolePrefix)
A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "").- Parameters:
rolePrefix
-- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
userCache
public JdbcUserDetailsManagerConfigurer<B> userCache(UserCache userCache)
Defines theUserCache
to use- Parameters:
userCache
- theUserCache
to use- Returns:
- the
JdbcUserDetailsManagerConfigurer
for further customizations
-
initUserDetailsService
protected void initUserDetailsService() throws java.lang.Exception
Description copied from class:UserDetailsManagerConfigurer
Populates the users that have been added.- Overrides:
initUserDetailsService
in classUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>,JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>>
- Throws:
java.lang.Exception
-
getUserDetailsService
public JdbcUserDetailsManager getUserDetailsService()
Description copied from class:AbstractDaoAuthenticationConfigurer
Gets theUserDetailsService
that is used with theDaoAuthenticationProvider
- Overrides:
getUserDetailsService
in classAbstractDaoAuthenticationConfigurer<B extends ProviderManagerBuilder<B>,JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>,UserDetailsManager>
- Returns:
- the
UserDetailsService
that is used with theDaoAuthenticationProvider
-
withDefaultSchema
public JdbcUserDetailsManagerConfigurer<B> withDefaultSchema()
Populates the default schema that allows users and authorities to be stored.- Returns:
- The
JdbcUserDetailsManagerConfigurer
used for additional customizations
-
getDatabasePopulator
protected org.springframework.jdbc.datasource.init.DatabasePopulator getDatabasePopulator()
-
-