我正在使用Spring爲我公司開發Java。我們正在開發一個我們擁有本地LDAP服務器的應用程序。 LDAP服務器將用於獲取信息。但是,我們不希望應用程序的用戶知道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服務器之間的代理。