我正在尝试通过InvalidAttributeValueException
实例确定LDAP错误代码19(密码策略错误)的原因是什么,因此我将能够在UI中显示信息性错误消息。
我正在使用的当前LDAP服务是openLDAP(作为应用程序中的嵌入式LDAP),它提供了非常好的信息,足以显示(即"[LDAP: error code 19 - Password fails quality checking policy]"
& "[LDAP: error code 19 - Password is in history of old passwords]"
)
但现在我想支持Active Directory&其他LDAP提供程序(将是外部的),以及我在rfc2251和其他各种来源中看到的 - 每个实现都有自己的异常消息,唯一的标准是错误代码19映射到InvalidAttributeValueException
而不是针对特定问题。
是否有解决方案(甚至是部分解决方案)来区分错误代码19的不同原因?
在给定InvalidAttributeValueException
实例的情况下,是否有办法查询LDAP以获得该问题的答案?
由于
答案 0 :(得分:2)
我上面的评论适用于通用LDAP API,但我忘了一些重要的东西。您需要调查http://tools.ietf.org/html/draft-behera-ldap-password-policy-10中指定的请求和响应控件。这在OpenLDAP中有效,但我不能说它是否受Active Directory支持。我有支持它的Java JNDI代码,欢迎您使用。 PasswordPolicyResponseControl可以返回以下内容:
/** Warning codes. */
public enum Warning
{
/** Password expiration warning.*/
timeBeforeExpiration,
/** Grace logins warning.*/
graceAuthNsRemaining,
none;
}
/** Error codes. */
public enum Error
{
/** The password has expired.*/
passwordExpired,
/**
* The account has been locked, either by an administrator
* or as a result of too many failed login attempts.
*/
accountLocked,
/**
* The password has been reset by an administrator and must be changed immediately.
*/
changeAfterReset,
/**
* The password policy does not permit the user to change his password.
*/
passwordModNotAllowed,
/**
* The password policy requires the old password to be supplied
* when changing passwords.
* This indicates a programming error in the client.
*/
mustSupplyOldPassword,
/**
* The new password has failed the quality check.
*/
insufficientPasswordQuality,
/**
* The new password is too short.
*/
passwordTooShort,
/**
* The current password is too new to change yet.
*/
passwordTooYoung,
/**
* The password policy specifies keeping a password history
* and the new password is already in it.
*/
passwordInHistory,
/**
* Error parsing the response control.
* This indicates a programming error either in this
* class or in the LDAP server.
*/
unparseableResponseControl,
/**
* No additional information.
* This can be seen e.g. when the user simply logs
* in with the wrong password.
*/
none;
};
答案 1 :(得分:0)
查看specs of the given exception,您可以找到以下内容:
InvalidAttributeValueException(String explanation)
exception.getExplanation()
,它给出了构造函数的值。
因为构造函数将值作为String而不是枚举,所以在编写不同的解决方案时,可能无法尝试获取每个编码器为此值设置的值列表。所以,正如你所发现的那样,每个人都会写出他们认为合适的东西:所有东西都不同,从而写出不同的东西。
这就是我能说的规格。