我目前正在使用Spring Security 3.0實現/配置Java Web應用程序的LDAP身份驗證。我將Microsoft AD LDS用作LDAP服務器,並選擇了Spring的BindAuthenticator。 我發現,只有經過身份驗證的用戶是該分區的Readers角色的成員時,身份驗證才起作用。 BindAuthenticator嘗試在身份驗證後讀取用戶的屬性,這在從目錄服務中檢索權限的情況下似乎是合理的。爲什麼Spring Security的BindAuthenticator需要讀取用戶權限?
作爲LDAP和AD的新手,當應用程序集成到現有AD結構中時,這是一種可接受的做法嗎? 可以微調給予用戶dns只讀屬性的讀取權限,而不是將它們添加到讀取器組中?
感謝 托馬斯
編輯2010年3月8日: 這是我落得這樣做: 我複製Spring的認證者(整個班級),併爲如下方法bindWithDn()。差異標記爲DIFF。
private DirContextOperations bindWithDn(String userDn, String username, String password) {
BaseLdapPathContextSource ctxSource = (BaseLdapPathContextSource) getContextSource();
DistinguishedName fullDn = new DistinguishedName(userDn);
fullDn.prepend(ctxSource.getBaseLdapPath());
logger.debug("Attempting to bind as " + fullDn);
DirContext ctx = null;
try {
ctx = getContextSource().getContext(fullDn.toString(), password);
// Check for password policy control
PasswordPolicyControl ppolicy = PasswordPolicyControlExtractor.extractControl(ctx);
// *DIFF* Attributes attrs = ctx.getAttributes(userDn, getUserAttributes());
DirContextAdapter result = new DirContextAdapter(null, new DistinguishedName(userDn), // *DIFF*
ctxSource.getBaseLdapPath());
if (ppolicy != null) {
result.setAttributeValue(ppolicy.getID(), ppolicy);
}
return result;
} catch (NamingException e) {
// This will be thrown if an invalid user name is used and the method may
// be called multiple times to try different names, so we trap the exception
// unless a subclass wishes to implement more specialized behaviour.
if ((e instanceof org.springframework.ldap.AuthenticationException)
|| (e instanceof org.springframework.ldap.OperationNotSupportedException)) {
handleBindException(userDn, username, e);
} else {
throw e;
}
// *DIFF* } catch (javax.naming.NamingException e) {
// *DIFF* throw LdapUtils.convertLdapException(e);
} finally {
LdapUtils.closeContext(ctx);
}
return null;
}
解決方案我去了 - 幾乎重複了Spring Security的BindAuthenticator並刪除了讀取用戶屬性的行。我正在使用一個自定義的AuthoritiesPopulator,所以沒有問題。 – Thomas 2010-05-17 00:28:59