1
votes

I have an application configured with LDAP and it works perfectly fine. But now I would need to pull details of users manager. I am not able to get the details please find the details

   @Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws 
 Exception {

    auth
        .ldapAuthentication()
        .userSearchBase("dc=ab,dc=test,dc=com")
        .userSearchFilter("TestName={0}")
        .groupSearchBase("ou=Groups,dc=ab,dc=test,dc=com")
        .groupSearchFilter("member={1}")
        .groupRoleAttribute("cn")
        .userDetailsContextMapper(userContextMapper())
        .contextSource(contextSource());
}

@Bean
public LdapContextSource contextSource() {
    LdapContextSource contextSource= new LdapContextSource();
    contextSource.setUrl("ldap:test");
    contextSource.setUserDn("CN=,OU=Accounts,DC=ab,DC=test,DC=com");
    contextSource.setPassword();
    return contextSource;
}
  @Bean
  public InetOrgPersonContextMapper userContextMapper() {
    return new InetOrgPersonContextMapper();
 }

I am able to fetch user but I need users manager details.

1

1 Answers

0
votes

Try this, you can get all authenticated user details from the class InetOrgPerson ! due to the implementation of your bean userContextMapper.

public void printDetails() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
                InetOrgPerson person = (InetOrgPerson)(authentication.getPrincipal());

                System.out.println(person.getUsername());
                System.out.println(person.getGivenName());
                System.out.println(person.getHomePhone());

}

    // various methods are implemented in the inetOrgPerson class to getting more ldap informations