在LDAP中实现超时
我一直在处理我们使用LDAP获取用户详细信息的应用程序。 有时需要更多时间来获取用户详细信息。 我想在获取详细信息的方法上实现超时 ,以便在最坏的情况下我们可以避免在服务器中挂起事务。
这里我们使用LdapUtil
类,我们在其中配置了LdapTemplate
类来获取所需的详细信息。
我们如何在LDAP方法上实现超时? (在本例中为ldapTemplate.search(...)
方法)
public class LdapUtil { @Autowired(required = true) @Qualifier(value = "ldapTemplateApp") LdapTemplate ldapTemplate; public Set findProducts(String UserId) { final Set products = newHashSet(); // Lookup the user String usrFilter = String.format(USERID_FILTER, globalUserId); ldapTemplate.search("ou=Members", usrFilter, // note this line new NameClassPairCallbackHandler() { public void handleNameClassPair(NameClassPair nameClassPair) { SearchResult result = (SearchResult) nameClassPair; String user = result.getNameInNamespace(); String GrpFilter = String.format(GROUP_FILTER, user); List zonePrefixes = ldapTemplate.search("Zones", GrpFilter, // note this line new AttributesMapper() { public Object mapFromAttributes(Attributes attributes) throws NamingException { return substringBeforeLast((String) attributes.get("cn").get(), "-") + "-"; } }); } }); products.remove(null); return newHashSet(products); } }
我们有一个LDAP.xml ,其中配置了ldapTemplete
我几乎没有疑问:
-
我们如何实现LDAP方法的TIMEOUT以及如何配置它? (将在哪种LDAP框架超时设置中)
-
有没有办法在xml文件中配置它们,即LDAP.xml(在这种情况下)?
我找到了解决方案。 我在ldap.xml文件中添加了以下属性。 到目前为止它对我有用。
如果您对LDAP超时实施有任何疑问,请发布任何其他解决方案。
对于ActiveDirectoryLdapAuthenticationProvider
,使用ldap.xml文件的解决方案对我不起作用。 相反,我在类路径中添加了一个jndi.properties
文件,其中包含以下内容:
com.sun.jndi.ldap.connect.timeout=500