【问题标题】:How to implement UserPasswordException on Liferay 7.4如何在 Liferay 7.4 上实现 UserPasswordException
【发布时间】:2022-07-20 23:47:27
【问题描述】:

我需要实现此代码,但它已被弃用,我如何为 liferay 7.4 更改它?它目前在 liferay 6.2 中,我们正在迁移到 7.4,我已经考虑过了,但我不明白这个类的变化。有人可以帮帮我吗?

                    errorKey = "changepassword.error";
                    SessionErrors.add(actionRequest, e.getClass(), e);
                    //TODO
                    switch (upe.getMessage()){
                    case UserPasswordException.PASSWORD_ALREADY_USED:
                        errorKey = "that-password-has-already-been-used-please-enter-in-a-different-password";
                        break;
                    case UserPasswordException.PASSWORD_CONTAINS_TRIVIAL_WORDS:
                        errorKey = "that-password-uses-common-words-please-enter-in-a-password-that-is-harder-to-guess-i-e-contains-a-mix-of-numbers-and-letters";
                        break;
                    case UserPasswordException.PASSWORD_INVALID:
                        errorKey = "that-password-is-invalid-please-enter-in-a-different-password";
                        break;
                    case UserPasswordException.PASSWORD_LENGTH:
                        errorKey = "that-password-is-too-short-or-too-long-please-make-sure-your-password-is-between-x-and-512-characters";
                        break;
                    case UserPasswordException.PASSWORD_NOT_CHANGEABLE:
                        errorKey = "passwords-may-not-be-changed-under-the-current-password-policy";
                        break;
                    case UserPasswordException.PASSWORD_SAME_AS_CURRENT:
                        errorKey = "your-new-password-cannot-be-the-same-as-your-old-password-please-enter-in-a-different-password";
                        break;
                    case UserPasswordException.PASSWORD_TOO_TRIVIAL:
                        errorKey = "that-password-is-too-trivial";
                        break;
                    case UserPasswordException.PASSWORD_TOO_YOUNG:
                        errorKey = "you-cannot-change-your-password-yet-please-wait-at-least-x-before-changing-your-password-again";
                        break;
                    case UserPasswordException.PASSWORDS_DO_NOT_MATCH:
                        errorKey = "the-passwords-you-entered-do-not-match-each-other-please-re-enter-your-password";
                        break;

                    }

【问题讨论】:

  • 你想达到什么目的?这段代码在哪里?哪个 API 已弃用?

标签: java liferay


【解决方案1】:

liferay 7 中更改了用户消息错误的逻辑,错误类型不再出现在异常消息中。 UserPasswordException 中有内部异常,每个都给出错误类型

if (upe instanceof UserPasswordException.MustNotBeEqualToCurrent) {   
       errorKey = "that-password-has-already-been-used-please-enter-in-a-different-password";    
}

有关所有异常的列表,请参见源类 https://github.com/liferay/liferay-portal/blob/7.4.x/portal-kernel/src/com/liferay/portal/kernel/exception/UserPasswordException.java

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-07
    • 1970-01-01
    • 2022-07-12
    • 2011-01-20
    • 2021-12-17
    • 2021-10-20
    • 2023-01-24
    • 2020-05-22
    相关资源
    最近更新 更多