我有一个配置了LDAP的应用程序,它工作得很好。但是现在我需要提取用户管理器的详细信息。我无法获得详细信息,请查找详细信息
@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();
}
我能够获取用户,但我需要用户经理详细信息。
试试这个,你可以从类InetOrgPerson !获取所有经过身份验证的用户详细信息! 由于你的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