Skip to content

Attributes to return on LDAP bind can only be configured with ObjectPostProcessor with Java configuration #4309

Closed
@sebtacke

Description

@sebtacke

Summary

Although the default search configuration for the user search on LDAP bind is supposed to return all attributes of the user the operational attributes are not included in the search result (may be LDAP server implementation specific. OpenDJ does not include them).
As the attributes returned by the user search are not exposed in the LdapAuthenticationProviderConfigurer, they can only be configured by creating a new user search object and setting in the BindLdapAuthenticator using an ObjectPostProcessor.

Actual Behavior

ObjectPostProcessor is required to set returned attributes in user search for LDAP authentication.

Expected Behavior

LdapAuthenticationProviderConfigurer provides a method to set the returned attributes for the user search.

Configuration

With default returned attribute:

    @Autowired
    protected void configureGlobal(final AuthenticationManagerBuilder auth) throws Exception {
        auth
                .ldapAuthentication()
                .userSearchBase(AuthenticationConfig.LDAP_USR_BASE)
                .userSearchFilter("(|(mail={0})(cn={0}))")
                .groupSearchBase("dc=groups,dc=ID")
                .groupSearchFilter("member={0}")
                .userDetailsContextMapper(new LdapIdentityProvider(contextSource))
                .contextSource(contextSource);
    }

With customized returned attributes:

    @Autowired
    protected void configureGlobal(final AuthenticationManagerBuilder auth)
            throws Exception {
        auth
                .ldapAuthentication()
                .groupSearchBase("dc=groups,dc=ID")
                .groupSearchFilter("member={0}")
                .userDetailsContextMapper(new LdapIdentityProvider(contextSource))
                .contextSource(contextSource)
                .withObjectPostProcessor(new ObjectPostProcessor<BindAuthenticator>() {

                    @Override
                    public BindAuthenticator postProcess(BindAuthenticator object) {
                        object.setUserAttributes(User.attributes()); // This line is probably unnecessary.
                        final FilterBasedLdapUserSearch ldapUserSearch =
                                new FilterBasedLdapUserSearch(AuthenticationConfig.LDAP_USR_BASE,
                                        "(|(mail={0})(cn={0}))", contextSource);
                        ldapUserSearch.setReturningAttributes(User.attributes());
                        object.setUserSearch(ldapUserSearch);
                        return object;
                    }
                });
    }

Version

org.springframework.security:spring-security-config:4.1.4.RELEASE
org.springframework.security:spring-security-core:4.1.4.RELEASE
org.springframework.security:spring-security-ldap:4.1.4.RELEASE

Sample

Metadata

Metadata

Assignees

Labels

in: ldapAn issue in spring-security-ldapstatus: invalidAn issue that we don't feel is valid

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions