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

# Class LdapAuthenticationProviderConfigurer<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.ldap.LdapAuthenticationProviderConfigurer<B>

Type Parameters:
  `B` - the `ProviderManagerBuilder` type that this is configuring.

All Implemented Interfaces:
  `SecurityConfigurer<org.springframework.security.authentication.AuthenticationManager,B>`

public class LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuilder<B>> extends SecurityConfigurerAdapter<org.springframework.security.authentication.AuthenticationManager,B>
Configures LDAP `AuthenticationProvider` in the `ProviderManagerBuilder`.

Since:
  3.2

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`final class`
`LdapAuthenticationProviderConfigurer.ContextSourceBuilder`
Allows building a `BaseLdapPathContextSource` and optionally creating an embedded LDAP instance.
`final class`
`LdapAuthenticationProviderConfigurer.PasswordCompareConfigurer`
Sets up Password based comparison

## Constructor Summary

Constructors
Constructor
Description
`LdapAuthenticationProviderConfigurer()`

## Method Summary

Modifier and Type
Method
Description
`LdapAuthenticationProviderConfigurer<B>`
`authoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper grantedAuthoritiesMapper)`
Specifies the `GrantedAuthoritiesMapper`.
`void`
`configure(B builder)`
Configure the `SecurityBuilder` by setting the necessary properties on the `SecurityBuilder`.
`LdapAuthenticationProviderConfigurer<B>.ContextSourceBuilder`
`contextSource()`
Allows easily configuring of a `BaseLdapPathContextSource` with defaults pointing to an embedded LDAP server that is created.
`LdapAuthenticationProviderConfigurer<B>`
`contextSource(org.springframework.ldap.core.support.BaseLdapPathContextSource contextSource)`
Specifies the `BaseLdapPathContextSource` to be used.
`protected org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper`
`getAuthoritiesMapper()`
Gets the `GrantedAuthoritiesMapper` and defaults to `SimpleAuthorityMapper`.
`LdapAuthenticationProviderConfigurer<B>`
`groupRoleAttribute(String groupRoleAttribute)`
Specifies the attribute name which contains the role name.
`LdapAuthenticationProviderConfigurer<B>`
`groupSearchBase(String groupSearchBase)`
The search base for group membership searches.
`LdapAuthenticationProviderConfigurer<B>`
`groupSearchFilter(String groupSearchFilter)`
The LDAP filter to search for groups.
`LdapAuthenticationProviderConfigurer<B>`
`groupSearchSubtree(boolean groupSearchSubtree)`
If set to true, a subtree scope search will be performed for group membership.
`LdapAuthenticationProviderConfigurer<B>`
`ldapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator ldapAuthoritiesPopulator)`
Specifies the `LdapAuthoritiesPopulator`.
`LdapAuthenticationProviderConfigurer<B>.PasswordCompareConfigurer`
`passwordCompare()`
`LdapAuthenticationProviderConfigurer<B>`
`passwordEncoder(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)`
Specifies the `PasswordEncoder` to be used when authenticating with password comparison.
`LdapAuthenticationProviderConfigurer<B>`
`rolePrefix(String rolePrefix)`
A non-empty string prefix that will be added as a prefix to the existing roles.
`LdapAuthenticationProviderConfigurer<B>`
`userDetailsContextMapper(org.springframework.security.ldap.userdetails.UserDetailsContextMapper userDetailsContextMapper)`
Allows explicit customization of the loaded user object by specifying a UserDetailsContextMapper bean which will be called with the context information from the user's directory entry.
`LdapAuthenticationProviderConfigurer<B>`
`userDnPatterns(String... userDnPatterns)`
If your users are at a fixed location in the directory (i.e.
`LdapAuthenticationProviderConfigurer<B>`
`userSearchBase(String userSearchBase)`
Search base for user searches.
`LdapAuthenticationProviderConfigurer<B>`
`userSearchFilter(String userSearchFilter)`
The LDAP filter used to search for users (optional).
`LdapAuthenticationProviderConfigurer<B>`
`withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)`
Deprecated, for removal: This API element is subject to removal in a future version.
`LdapAuthenticationProviderConfigurer<B>`
`withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)`
Adds an `ObjectPostProcessor` for this class.

### 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

### LdapAuthenticationProviderConfigurer

public LdapAuthenticationProviderConfigurer()

## Method Details

### ldapAuthoritiesPopulator

public LdapAuthenticationProviderConfigurer<B> ldapAuthoritiesPopulator(org.springframework.security.ldap.userdetails.LdapAuthoritiesPopulator ldapAuthoritiesPopulator)
Specifies the `LdapAuthoritiesPopulator`.

Parameters:
  `ldapAuthoritiesPopulator` - the `LdapAuthoritiesPopulator` the default is `DefaultLdapAuthoritiesPopulator`
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### withObjectPostProcessor

public LdapAuthenticationProviderConfigurer<B> withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)
Adds an `ObjectPostProcessor` for this class.

Parameters:
  `objectPostProcessor` -
Returns:
  the `ChannelSecurityConfigurer` for further customizations

### withObjectPostProcessor

@Deprecated(since="6.4", forRemoval=true) public LdapAuthenticationProviderConfigurer<B> withObjectPostProcessor(ObjectPostProcessor<?> objectPostProcessor)
Deprecated, for removal: This API element is subject to removal in a future version.

### authoritiesMapper

public LdapAuthenticationProviderConfigurer<B> authoritiesMapper(org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper grantedAuthoritiesMapper)
Specifies the `GrantedAuthoritiesMapper`.

Parameters:
  `grantedAuthoritiesMapper` - the `GrantedAuthoritiesMapper` the default is `SimpleAuthorityMapper`
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations
Since:
  4.1.1

### getAuthoritiesMapper

protected org.springframework.security.core.authority.mapping.GrantedAuthoritiesMapper getAuthoritiesMapper() throws Exception
Gets the `GrantedAuthoritiesMapper` and defaults to `SimpleAuthorityMapper`.

Returns:
  the `GrantedAuthoritiesMapper`
Throws:
  `Exception` - if errors in `SimpleAuthorityMapper.afterPropertiesSet()`

### contextSource

public LdapAuthenticationProviderConfigurer<B> contextSource(org.springframework.ldap.core.support.BaseLdapPathContextSource contextSource)
Specifies the `BaseLdapPathContextSource` to be used. If not specified, an embedded LDAP server will be created using `contextSource()`.

Parameters:
  `contextSource` - the `BaseLdapPathContextSource` to use
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations
See Also:
  - `contextSource()`

### contextSource

public LdapAuthenticationProviderConfigurer<B>.ContextSourceBuilder contextSource()
Allows easily configuring of a `BaseLdapPathContextSource` with defaults pointing to an embedded LDAP server that is created.

Returns:
  the `LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuilder<B>>.ContextSourceBuilder` for further customizations

### passwordEncoder

public LdapAuthenticationProviderConfigurer<B> passwordEncoder(org.springframework.security.crypto.password.PasswordEncoder passwordEncoder)
Specifies the `PasswordEncoder` to be used when authenticating with password comparison.

Parameters:
  `passwordEncoder` - the `PasswordEncoder` to use
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customization

### userDnPatterns

public LdapAuthenticationProviderConfigurer<B> userDnPatterns(String... userDnPatterns)
If your users are at a fixed location in the directory (i.e. you can work out the DN directly from the username without doing a directory search), you can use this attribute to map directly to the DN. It maps directly to the userDnPatterns property of AbstractLdapAuthenticator. The value is a specific pattern used to build the user's DN, for example "uid={0},ou=people". The key "{0}" must be present and will be substituted with the username.

Parameters:
  `userDnPatterns` - the LDAP patterns for finding the usernames
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### userDetailsContextMapper

public LdapAuthenticationProviderConfigurer<B> userDetailsContextMapper(org.springframework.security.ldap.userdetails.UserDetailsContextMapper userDetailsContextMapper)
Allows explicit customization of the loaded user object by specifying a UserDetailsContextMapper bean which will be called with the context information from the user's directory entry.

Parameters:
  `userDetailsContextMapper` - the `UserDetailsContextMapper` to use
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations
See Also:
  - `PersonContextMapper`
  - `InetOrgPersonContextMapper`
  - `LdapUserDetailsMapper`

### groupRoleAttribute

public LdapAuthenticationProviderConfigurer<B> groupRoleAttribute(String groupRoleAttribute)
Specifies the attribute name which contains the role name. Default is "cn".

Parameters:
  `groupRoleAttribute` - the attribute name that maps a group to a role.
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### groupSearchBase

public LdapAuthenticationProviderConfigurer<B> groupSearchBase(String groupSearchBase)
The search base for group membership searches. Defaults to "".

Parameters:
  `groupSearchBase` -
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### groupSearchSubtree

public LdapAuthenticationProviderConfigurer<B> groupSearchSubtree(boolean groupSearchSubtree)
If set to true, a subtree scope search will be performed for group membership. If false a single-level search is used.

Parameters:
  `groupSearchSubtree` - set to true to enable searching of the entire tree below the `groupSearchBase`.
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### groupSearchFilter

public LdapAuthenticationProviderConfigurer<B> groupSearchFilter(String groupSearchFilter)
The LDAP filter to search for groups. Defaults to "(uniqueMember={0})". The substituted parameter is the DN of the user.

Parameters:
  `groupSearchFilter` - the LDAP filter to search for groups
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### rolePrefix

public LdapAuthenticationProviderConfigurer<B> rolePrefix(String rolePrefix)
A non-empty string prefix that will be added as a prefix to the existing roles. The default is "ROLE_".

Parameters:
  `rolePrefix` - the prefix to be added to the roles that are loaded.
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations
See Also:
  - `SimpleAuthorityMapper.setPrefix(String)`

### userSearchBase

public LdapAuthenticationProviderConfigurer<B> userSearchBase(String userSearchBase)
Search base for user searches. Defaults to "". Only used with `userSearchFilter(String)`.

Parameters:
  `userSearchBase` - search base for user searches
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### userSearchFilter

public LdapAuthenticationProviderConfigurer<B> userSearchFilter(String userSearchFilter)
The LDAP filter used to search for users (optional). For example "(uid={0})". The substituted parameter is the user's login name.

Parameters:
  `userSearchFilter` - the LDAP filter used to search for users
Returns:
  the `LdapAuthenticationProviderConfigurer` for further customizations

### configure

public void configure(B builder) throws Exception
Description copied from interface: `SecurityConfigurer`
Configure the `SecurityBuilder` by setting the necessary properties on the `SecurityBuilder`.

Specified by:
  `configure` in interface `SecurityConfigurer<org.springframework.security.authentication.AuthenticationManager,B extends ProviderManagerBuilder<B>>`
Overrides:
  `configure` in class `SecurityConfigurerAdapter<org.springframework.security.authentication.AuthenticationManager,B extends ProviderManagerBuilder<B>>`
Throws:
  `Exception`

### passwordCompare

public LdapAuthenticationProviderConfigurer<B>.PasswordCompareConfigurer passwordCompare()

Returns:
  the `LdapAuthenticationProviderConfigurer<B extends ProviderManagerBuilder<B>>.PasswordCompareConfigurer` for further customizations