[英]LDAP Authentication queries
在下方的代碼是他們嘗試獲取InitialDirContext以及LDAP服務器的所有詳細信息以及用戶名和密碼的代碼,如果該代碼引發基於異常的錯誤,並以此為基礎確定返回代碼。
private void doSimpleAuthentication() {
try {
String hostURL = "ldap://" + hostName + ":" + port + "/";
env.put(Context.PROVIDER_URL, hostURL);
env.put(Context.SECURITY_AUTHENTICATION, "simple");
String principal = userName + "@" + domain;
// First connect to LDAP Server using Directory Manager credentials
DirContext ctx = connectToDirServer(principal, password);
returnCode = VALID_USER;
if (warningPeriod >= 0) {
String filter = "(sAMAccountName=" + userName + ")";
SearchControls ctrl = new SearchControls();
ctrl.setSearchScope(SearchControls.SUBTREE_SCOPE);
NamingEnumeration results = ctx.search(baseDn, filter, ctrl);
if (results != null && results.hasMoreElements()) {
SearchResult result = (SearchResult) results.next();
String attPrincipal = (result).getName() + "," + baseDn;
if ((!isPwdNeverExpires(result)) && isPasswordNearingExpiry(ctx, attPrincipal)) {
returnCode = PASSWORD_NEARING_EXPIRY;
}
}
}
if (ctx != null) ctx.close();
} catch (CommunicationException e) {
errorMessage = e.getMessage();
errorStackTrace = AgsUtil.convertToString(e);
returnCode = SERVER_NOT_AVAILABLE;
} catch (Exception e) {
errorMessage = e.getMessage();
errorStackTrace = AgsUtil.convertToString(e);
returnCode = UNKNOWN_ERROR;
if (errorMessage.indexOf("525") != -1 || errorMessage.indexOf("successful bind must be completed") != -1) {
returnCode = USER_NOT_FOUND;
} else if (errorMessage.indexOf("52e") != -1) {
returnCode = INVALID_PASSWORD;
} else if (errorMessage.indexOf("701") != -1 || errorMessage.indexOf("532") != -1 || errorMessage.indexOf("773") != -1) {
returnCode = PASSWORD_EXPIRED;
} else if (errorMessage.indexOf("533") != -1) {
returnCode = USER_DISABLED;
} else if (errorMessage.indexOf("775") != -1) {
returnCode = USER_LOCKOUT;
} else if (errorMessage.indexOf("530") != -1) {
returnCode = LOGON_DENIED_AT_THIS_TIME;
}
}
}
public DirContext connectToDirServer(String distinguishedName, String password) throws Exception {
env.put(Context.SECURITY_PRINCIPAL, distinguishedName);
env.put(Context.SECURITY_CREDENTIALS, password);
return new InitialDirContext(env);
}
2.我在客戶處遇到一個問題,如果在LDAP(AD)中找不到該用戶,它將返回狀態代碼為“ INVALID_USERID_PASSWORD”,而不是“ USER_NOT_FOUND”。客戶要求我提供以下內容信息
針對應用程序到ldap服務器的查詢,或者換句話說,作為ldap查詢傳遞的請求字符串是什么。 請參閱以下有關LDAP查詢的信息。
您可以在此處引用示例的參考鏈接。
http://www.google.com/support/enterprise/static/postini/docs/admin/en/dss_admin/prep_ldap.html
如何進行,我找不到有關如何使用這些查詢的任何信息。 與上面的代碼。
當BIND請求中的條目不存在時,LDAP目錄服務器可能會用invalid password
的結果代碼響應。 它可以防止攻擊者知道條目是否存在。
您可能需要以有權利的人身份綁定。
我們在LDAP Wiki上有一個示例。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.