Package org.springframework.security.config.annotation.authentication.configurers.provisioning

# Class JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>

java.lang.Object
org.springframework.security.config.annotation.SecurityConfigurerAdapter<org.springframework.security.authentication.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,org.springframework.security.provisioning.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 the `ProviderManagerBuilder` that is being configured

All Implemented Interfaces:
  `SecurityConfigurer<org.springframework.security.authentication.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

Constructors
Constructor
Description
`JdbcUserDetailsManagerConfigurer()`
`JdbcUserDetailsManagerConfigurer(org.springframework.security.provisioning.JdbcUserDetailsManager manager)`

## Method Summary

Modifier and Type
Method
Description
`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 org.springframework.jdbc.datasource.init.DatabasePopulator`
`getDatabasePopulator()`
`org.springframework.security.provisioning.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.
`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(org.springframework.security.core.userdetails.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.

### 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, withObjectPostProcessor`

### Methods inherited from class org.springframework.security.config.annotation.SecurityConfigurerAdapter

`addObjectPostProcessor, 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 Details

### JdbcUserDetailsManagerConfigurer

public JdbcUserDetailsManagerConfigurer(org.springframework.security.provisioning.JdbcUserDetailsManager manager)

### JdbcUserDetailsManagerConfigurer

public JdbcUserDetailsManagerConfigurer()

## Method Details

### dataSource

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

Parameters:
  `dataSource` - the `DataSource` to be used. Cannot be null.
Returns:
  The `JdbcUserDetailsManagerConfigurer` used for additional customizations

### usersByUsernameQuery

public JdbcUserDetailsManagerConfigurer<B> usersByUsernameQuery(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(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(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(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(org.springframework.security.core.userdetails.UserCache userCache)
Defines the `UserCache` to use

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

### 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 org.springframework.security.provisioning.JdbcUserDetailsManager getUserDetailsService()
Description copied from class: `AbstractDaoAuthenticationConfigurer`
Gets the `UserDetailsService` that is used with the `DaoAuthenticationProvider`

Overrides:
  `getUserDetailsService` in class `AbstractDaoAuthenticationConfigurer<B extends ProviderManagerBuilder<B>,JdbcUserDetailsManagerConfigurer<B extends ProviderManagerBuilder<B>>,org.springframework.security.provisioning.UserDetailsManager>`
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 `JdbcUserDetailsManagerConfigurer` used for additional customizations

### getDatabasePopulator

protected org.springframework.jdbc.datasource.init.DatabasePopulator getDatabasePopulator()