spring ldap security without xml -


How does this document configure spring-protection LDAP:

  3.4.5 Spring Bean Configuration & lt; Bean id = "references" class = "org.springframework.security.ldap.DefaultSpringSecurityContextSource" & gt; & Lt; Constructor-arg value = "ldap: // monkeymachine: 389 / dc = springframework, dc = org" /> & Lt; Property name = "userDn" value = "cn = manager, dc = spring framework, dc = org" /> & Lt; Property Name = "Password" Value = "Password" /> & Lt; / Bean & gt; & Lt; Bean id = "ldapAuthProvider" class = "org.springframework.security.ldap.authentication.LdapAuthenticationProvider" & gt; & Lt; Manufacturer-Arg & gt; & Lt; Bean class = "org.springframework.security.ldap.authentication.BindAuthenticator" & gt; & Lt; Constructor-arg ref = "contextSource" /> & Lt; Property Name = "userDnPatterns" & gt; & Lt; List & gt; & Lt; Price & gt; Uid = {0}, ou = people & lt; / Value & gt; & Lt; / List & gt; & Lt; / Property & gt; & Lt; / Bean & gt; & Lt; / Creator-arg & gt; & Lt; Manufacturer-Arg & gt; & Lt; Bean class = "org.springframework.security.ldap.userdetails.DefaultLdapAuthoritiesPopulator" & gt; & Lt; Constructor-arg ref = "contextSource" /> & Lt; Constructor-arg value = "ou = groups" /> & Lt; Property Name = "Group Attribute" value = "Where" /> & Lt; / Bean & gt; & Lt; / Creator-arg & gt; & Lt; / Bean & gt;  

How can we get it without XML? Here we have a sample that uses a local LDIF file:

I have modified SecurityConfig.java as follows:

  public void registerGlobalAuthentication (AuthenticationManagerBuilder Auth) throws an exception {DefaultSpringSecurityContextSource ContextSource = New DefaultSpringSecurityContextSource (ldap_url); ContextSource.setUrl (ldap_user); ContextSource.setPassword (ldap_password); DefaultLadapAuthoritiesPopulator ldapAuthoritiesPopulator = New DefaultLdapAuthoritiesPopulator (reference resources, "ou = groups"); LdapAuthoritiesPopulator.setGroupRoleAttribute ("Where"); LdapAuthenticationProviderConfigurer & LT; AuthenticationManagerBuilder & gt; LdapAuthenticationProviderConfigurer = auth.ldapAuthentication (); LdapAuthenticationProviderConfigurer .userDnPatterns ("uid = {0}, ou = people") .groupSearchBase ("ou = group") .contextSource () .ldapAuthoritiesPopulator (ldapAuthoritiesPopulator); }}  

But when I login using the web form, I get this error:

  java.lang.NullPointerException at java. Use.Hashtable & Lt; Init & gt; (Hashtable.java296) org.springframework.ldap.core.support.AbstractContextSource.getAuthenticatedEnv (AbstractContextSource.java:499) org.springframework.ldap.core.support.AbstractContextSource.doGetContext (at AbstractContextSource.java: 114) org on .springframework.ldap.core.support.AbstractContextSource.getContext (AbstractContextSource.java:110) on org.springframework.security.ldap.authentication.BindAuthenticator.bindWithDn (BindAuthenticator.java:112)  
< P> Is there any such document to explain the achievement of Spring XML without it?

You need to call

  contextSource.afterPropertiesSet () < / Code> 

If you are using a class outside an application context (see source and see Javadock for Spring LDAP for more information). Either it or you can make it a @ bean and call the spring method and start it for you.

In addition to

  contextSource setUrl (ldap_user);  

does not look correct, should it be setUserDn ?


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -