Spring boot - security java config - LDAP -
i trying set ldap authentication through java config. code auth.getobject inside method init returns null , unable set authentication manager , no exception seen. there wrong in config? how can authentication manager object?
@configuration public class ldapauthenticationconfig extends globalauthenticationconfigureradapter { /** environment. */ private environment environment; @bean(name="ldapauthmanager") public authenticationmanager getauthmanager(){ return authenticationmanager; } private authenticationmanager authenticationmanager; @override public void init(authenticationmanagerbuilder auth) throws exception { auth.ldapauthentication() .usersearchfilter( "(&(samaccountname={0})(objectclass=organizationalperson))") .usersearchbase("ou="+environment.getproperty("ldap.user-search-base.name")) .groupsearchfilter("(member={0})") .groupsearchbase("ou=global-groups").grouproleattribute("cn") .contextsource().url(environment.getproperty("ldap.url")) .managerdn(environment.getproperty("ldap.conn.user")) .managerpassword(environment.getproperty("ldap.conn.pwd")); setauthenticationmanager(auth.getobject()); } public authenticationmanager getauthenticationmanager() { return authenticationmanager; } public void setauthenticationmanager( authenticationmanager authenticationmanager) { this.authenticationmanager = authenticationmanager; } @autowired public void setenvironment(environment environment) { this.environment = environment; } }
try add complete url ldap server "ldap.url" port , searchbase, eg: ldap://**server name**:**port**/**o=usersearchbase**
it worked me. reasen .port()
, .usersearchbase()
didn't work build correct url.
hope helps.
Comments
Post a Comment