org.springframework.security.config.annotation.authentication.configurers.provisioning
Class JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>

java.lang.Object
  extended by org.springframework.security.config.annotation.SecurityConfigurerAdapter<AuthenticationManager,B>
      extended by org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsAwareConfigurer<B,U>
          extended by org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer<B,C,UserDetailsManager>
              extended by org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer<B,JdbcUserDetailsManagerConfigurer<B>>
                  extended by org.springframework.security.config.annotation.authentication.configurers.provisioning.JdbcUserDetailsManagerConfigurer<B>
Type Parameters:
B - the type of the ProviderManagerBuilder that is being configured
All Implemented Interfaces:
SecurityConfigurer<AuthenticationManager,B>

public class JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>
extends UserDetailsManagerConfigurer<B,JdbcUserDetailsManagerConfigurer<B>>

Configures an AuthenticationManagerBuilder 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
JdbcUserDetailsManagerConfigurer()
           
JdbcUserDetailsManagerConfigurer(JdbcUserDetailsManager manager)
           
 
Method Summary
 JdbcUserDetailsManagerConfigurer<B> authoritiesByUsernameQuery(String query)
          Sets the query to be used for finding a user's authorities by their username.
 JdbcUserDetailsManagerConfigurer<B> dataSource(DataSource dataSource)
          Populates the DataSource to be used.
protected  DatabasePopulator getDatabasePopulator()
           
 JdbcUserDetailsManager getUserDetailsService()
          Gets the UserDetailsService that is used with the DaoAuthenticationProvider
 JdbcUserDetailsManagerConfigurer<B> groupAuthoritiesByUsername(String query)
          An SQL statement to query user's group authorities given a username.
protected  void initUserDetailsService()
          Populates the users that have been added.
 C passwordEncoder(PasswordEncoder passwordEncoder)
          Allows specifying the PasswordEncoder to use with the DaoAuthenticationProvider.
 C passwordEncoder(PasswordEncoder passwordEncoder)
          Allows specifying the PasswordEncoder to use with the DaoAuthenticationProvider.
 JdbcUserDetailsManagerConfigurer<B> rolePrefix(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 the UserCache to use
 JdbcUserDetailsManagerConfigurer<B> usersByUsernameQuery(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.
 C withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)
          Adds an ObjectPostProcessor for this class.
 
Methods inherited from class org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer
withUser
 
Methods inherited from class org.springframework.security.config.annotation.authentication.configurers.userdetails.UserDetailsServiceConfigurer
configure
 
Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter
addObjectPostProcessor, and, getBuilder, init, postProcess, setBuilder
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcUserDetailsManagerConfigurer

public JdbcUserDetailsManagerConfigurer(JdbcUserDetailsManager manager)

JdbcUserDetailsManagerConfigurer

public JdbcUserDetailsManagerConfigurer()
Method Detail

dataSource

public JdbcUserDetailsManagerConfigurer<B> dataSource(DataSource dataSource)
                                                                                 throws Exception
Populates the DataSource to be used. This is the only required attribute.

Parameters:
dataSource - the DataSource to be used. Cannot be null.
Returns:
Throws:
Exception

usersByUsernameQuery

public JdbcUserDetailsManagerConfigurer<B> usersByUsernameQuery(String query)
                                                                                           throws Exception
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 JdbcUserDetailsManagerRegistry used for additional customizations
Throws:
Exception

authoritiesByUsernameQuery

public JdbcUserDetailsManagerConfigurer<B> authoritiesByUsernameQuery(String query)
                                                                                                 throws Exception
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 JdbcUserDetailsManagerRegistry used for additional customizations
Throws:
Exception

groupAuthoritiesByUsername

public JdbcUserDetailsManagerConfigurer<B> groupAuthoritiesByUsername(String query)
                                                                                                 throws Exception
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 JdbcUserDetailsManagerRegistry used for additional customizations
Throws:
Exception

rolePrefix

public JdbcUserDetailsManagerConfigurer<B> rolePrefix(String rolePrefix)
                                                                                 throws Exception
A non-empty string prefix that will be added to role strings loaded from persistent storage (default is "").

Parameters:
rolePrefix -
Returns:
Throws:
Exception

userCache

public JdbcUserDetailsManagerConfigurer<B> userCache(UserCache userCache)
                                                                                throws Exception
Defines the UserCache to use

Parameters:
userCache - the UserCache to use
Returns:
the JdbcUserDetailsManagerConfigurer for further customizations
Throws:
Exception

initUserDetailsService

protected void initUserDetailsService()
                               throws Exception
Description copied from class: UserDetailsManagerConfigurer
Populates the users that have been added.

Overrides:
initUserDetailsService in class UserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>,JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>>
Throws:
Exception

getUserDetailsService

public JdbcUserDetailsManager getUserDetailsService()
Gets the UserDetailsService that is used with the DaoAuthenticationProvider

Returns:
the UserDetailsService that is used with the DaoAuthenticationProvider

withDefaultSchema

public JdbcUserDetailsManagerConfigurer<B> withDefaultSchema()
Populates the default schema that allows users and authorities to be stored.

Returns:
The JdbcUserDetailsManagerRegistry used for additional customizations

getDatabasePopulator

protected DatabasePopulator getDatabasePopulator()

withObjectPostProcessor

public C withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)
Adds an ObjectPostProcessor for this class.

Parameters:
objectPostProcessor -
Returns:
the AbstractDaoAuthenticationConfigurer for further customizations

passwordEncoder

public C passwordEncoder(PasswordEncoder passwordEncoder)
Allows specifying the PasswordEncoder to use with the DaoAuthenticationProvider. The default is is to use plain text.

Parameters:
passwordEncoder - The PasswordEncoder to use.
Returns:

passwordEncoder

public C passwordEncoder(PasswordEncoder passwordEncoder)
Allows specifying the PasswordEncoder to use with the DaoAuthenticationProvider. The default is is to use plain text.

Parameters:
passwordEncoder - The PasswordEncoder to use.
Returns:
the SecurityConfigurer for further customizations