【问题标题】:Differentiating the causes of InvalidAttributeValueException区分 InvalidAttributeValueException 的原因
【发布时间】:2012-02-28 08:17:11
【问题描述】:

我正在尝试通过 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 以获取该问题的答案?

谢谢

【问题讨论】:

  • 从未见过这样的方法。您在 RFC 2251 中找到的内容确实回答了您的问题。
  • 我不认为自 1997 年以来没有人找到解决此问题的方法。必须有一些标准方法通过 JNDI 查询 LDAP 以查看密码更改失败的原因,显示一般消息就像“密码未通过质量检查”一样,由于在历史列表中而被拒绝的密码是邪恶且无法使用的。
  • 如果有“一般消息”,它将在 RFC 中指定。
  • @EJP 你不明白我在评论最后一部分的意思,但我明白了要点。我扩展了我对 LDAP 的了解,显然我想要实现的功能根本无关紧要。请发布答案,以便我可以奖励您。谢谢。
  • 正确,我没看懂,因为它没有意义。如果密码在历史列表中,您会收到一些这样的消息。如果质量检查失败,同上。您不会收到与历史列表问题相关的“质量检查”消息。

标签: java ldap jndi spring-ldap


【解决方案1】:

我上面的 cmets 适用于通用 LDAP API,但我忘记了一些重要的东西。您需要调查https://datatracker.ietf.org/doc/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;
};

【讨论】:

    【解决方案2】:

    查看specs of the given exception,您可以找到以下内容:

    • 构造函数变体中给出了因实现而异的原因

    InvalidAttributeValueException(String explanation)

    • 它有一个调用它的方法:

    exception.getExplanation()

    它给出了与构造函数一起放入的值。

    由于构造函数将值作为字符串而不是枚举,因此在编写不同的解决方案时,可能无法尝试获取每个编码器对该值赋予的值的列表。所以,正如你所发现的,每个人都会写他们认为合适的东西:所有的东西都不同,因此写的东西也不同。

    这就是我可以说的规格。

    【讨论】:

    • 异常文档一目了然。我想看看是否有人知道查询 LDAP 以查看导致异常的原因。但无论如何谢谢:)
    猜你喜欢
    • 1970-01-01
    • 2012-06-19
    • 2013-04-24
    • 2020-05-27
    • 1970-01-01
    • 2022-05-19
    • 2011-07-12
    • 1970-01-01
    • 2013-10-29
    相关资源
    最近更新 更多