【问题标题】:Querying LDAP Server Where LDAP Structure Not Known查询 LDAP 结构未知的 LDAP 服务器
【发布时间】:2012-11-19 10:40:35
【问题描述】:

我正在为我的公司使用 Spring 进行 Java 开发。我们正在开发一个具有本地 LDAP 服务器的应用程序。 LDAP 服务器将用于获取信息。但是,我们不希望应用程序的用户知道 LDAP 结构/模式。这是因为客户/用户将拥有自己的 LDAP 服务器和自己的 LDAP 结构/架构。

例如,客户/用户将通过用户界面获取信息,方法是提供用于连接 LDAP 服务器的 LDAP 服务器详细信息。连接后,他们将能够通过执行查询来获取信息。现在,他们将不知道有关 LDAP 结构的信息。将要编写的代码将通过执行用户查询来完成。如果查询运行,那么它将返回该信息,否则将给出异常。

我面临的问题是:

当你使用 Spring LDAP 时,有一个叫做 AttributesMapper 和 ContextMapper 的东西。为了使用它,我必须传入一个强类型对象。比如:

public class EmployeeAttributesMapper implements AttributesMapper {

public EmployeeAttributesMapper() {

}

/**
 * This method maps the Employee Entity to data stored in the LDAP Server through a Attribute.
 * @param attrs the name of the Attribute to get
 * @return the Employee Entity.
 */
public Object mapFromAttributes(Attributes attrs) throws NamingException {
    Employee employee = new Employee();
    employee.setFirstName((String) attrs.get("cn").get());
    return employee;
}
}

根据查询执行上述代码时,将仅获取有关 cn 属性的信息,而不获取其他信息。还有其他不需要强类型对象的东西吗?

我不知道该怎么办。

例如,搜索所有员工:

public List getAllEmployees() {
    return ldapTemplate.search("", "(objectclass=person)", new EmployeeContextMapper());
}

这将返回所有员工,但只设置 cn 属性。但是,在客户 LDAP 服务器上,它们可能没有名为 cn 的属性。

最好的方法是什么?我们编写的代码充当用户界面和客户 LDAP 服务器之间的代理。

【问题讨论】:

    标签: java spring ldap apacheds ldif


    【解决方案1】:

    最简单的答案是将属性的预期用途抽象为属性类型,即 OID 或别名。例如,将“姓名”映射到cn(公用名)属性别名,将“名字”映射到givenName 属性,将“姓氏”映射到sn 属性,等等。 IETF 有许多 RFC,它们描述了推荐用于 LDAP 目录服务器数据库的属性。 inetOrgPerson (RFC2798) 就是一个很好的例子。

    如果表示与实现正确分离,用户根本不需要知道数据来自 LDAP 目录服务器,更不用说属性名称是什么了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-05
      • 1970-01-01
      相关资源
      最近更新 更多