Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I hope this solution works in your case. You can use LdapTemplate for retrieving an attribute specified in CustomMapper i.e.InetOrgPersonContextMapper class.</p> <ol> <li><p>Create a bean of <a href="http://docs.spring.io/spring-ldap/docs/1.2.x/api/spring-ldap/org/springframework/ldap/core/LdapTemplate.html" rel="nofollow"><code>LdapTemplate</code></a> class </p> <p><code>&lt;bean id="ldapTemplate" class="com.springframework.ldap.core.LdapTemplate"&gt;</code> <br/> <code>&lt;constructor-arg ref="contextSource" /&gt;</code> <br/> <code>&lt;/bean&gt;</code></p> <p>Where contextSource is a reference to an instance of <a href="http://docs.spring.io/spring-ldap/site/apidocs/org/springframework/ldap/core/support/LdapContextSource.html" rel="nofollow">LdapContextSource</a></p></li> <li><p>Inject ldapTemplate bean into Controller by auto-wiring<br/> <code>@Autowire LdapTemplate ldapTemplate;</code></p></li> <li><p>Cast Principal instance to <a href="http://docs.spring.io/autorepo/docs/spring-security/3.0.x/apidocs/org/springframework/security/ldap/userdetails/LdapUserDetailsImpl.html" rel="nofollow"><code>LdapUserDetailsImpl</code></a> <br/> <code>LdapUserDetailsImpl ldapUserDetails = (LdapUserDetailsImpl) p;</code></p></li> <li><p>Retrieve User DN<br/> <code>String dn=</code> <a href="http://docs.spring.io/autorepo/docs/spring-security/3.0.x/apidocs/org/springframework/security/ldap/userdetails/LdapUserDetailsImpl.html#getDn%28%29" rel="nofollow"><code>ldapUserDetail.getDn()</code></a></p></li> <li><p>Using a method <a href="http://docs.spring.io/spring-ldap/docs/1.2.x/api/spring-ldap/org/springframework/ldap/core/LdapTemplate.html#lookup%28java.lang.String,%20org.springframework.ldap.core.ContextMapper%29" rel="nofollow"><code>Object lookup(String,ContextMapper)</code></a> of ldapTemplate instance to get Mapped (mapped by mapper) object i.e. <code>InetOrgPerson</code> <br/> <code>InetOrgPerson person=ldapTemplate.lookup(dn,new InetOrgPersonContextMapper());</code></p></li> <li><p>Enjoy!</p></li> </ol> <p><strong>References:</strong><br/> <a href="https://today.java.net/pub/a/today/2006/04/18/ldaptemplate-java-ldap-made-simple.html#searches" rel="nofollow">https://today.java.net/pub/a/today/2006/04/18/ldaptemplate-java-ldap-made-simple.html#searches</a><br/> <a href="http://docs.spring.io/spring-ldap/docs/current/reference/htmlsingle/" rel="nofollow">http://docs.spring.io/spring-ldap/docs/current/reference/htmlsingle/</a> </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload