【问题标题】:spring boot ldap additional detailsspring boot ldap 附加细节
【发布时间】:2018-09-20 12:25:49
【问题描述】:

我有一个使用 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();
 }

我可以获取用户,但我需要用户管理器详细信息。

【问题讨论】:

    标签: spring spring-boot spring-security spring-ldap


    【解决方案1】:

    试试这个,您可以从 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-20
      • 2014-07-28
      • 2017-10-20
      • 2015-02-26
      • 2017-07-02
      • 2017-01-30
      • 2015-05-14
      • 2017-04-12
      相关资源
      最近更新 更多