0

ログインしたユーザーのパスワードを変更するために使用するポートレットがあります。ユーザーは、現在のパスワードと新しいパスワードを 2 回入力する必要があります。LoginService.checkPassword(String userId, char[] password) を呼び出して、既存のパスワードが正しいかどうかを判断します。このメソッドが true を返す場合、Puma プロファイルを介して現在のユーザーを取得し、PumaController.setAttributes(User user, Map attributes) 呼び出しを使用して更新された属性を設定することにより、パスワードが更新されます。次に、PumaProfile.reload メソッドを介して puma プロファイルがリロードされます (PumaController.reload() メソッドも使用してみました。

私が直面している問題は、 LoginService.checkPassword(String userId, char[] password) が現在のパスワードだけでなく、現在のパスワードと古いパスワードに対して true を返すことです。これがなぜなのか誰か知っていますか?

ldap では、wimdomain.xml にもあるように、パスワード フィールドは単一の属性フィールドであり、ログアウトしてログインしようとすると、(ご想像のとおり) 現在のパスワードでしかログインできません。

4

2 に答える 2

0

ポータルのバグであることがわかりました。すぐに使用できるプロファイル編集ポートレットを使用しても、同じ問題が発生します。

于 2013-05-24T11:29:53.477 に答える
0

Websphere Portal ユーザーのパスワードを確認する ユーザーのパスワードを確認するには、次の 2 つの方法があります。

1) 「UserRegistry」を使用する

public static boolean checkUserAuthenticatedLDAP(String userId, String password) {
    try {
        Context ctx = new InitialContext();
        com.ibm.websphere.security.UserRegistry reg =
            (com.ibm.websphere.security.UserRegistry) ctx.lookup("UserRegistry");

        String res = reg.checkPassword(userId, password);

        return res != null;
    } catch (Exception ex) {
        return false;
    }
}

2) 「LoginContext」を使用する

/**
 * This method validates the user based on the user id and password
 * attributes, If the user id or password is not valid then throws Exception.
 *
 * @param userId
 * @param password
 * @return boolean
 * @throws Exception
 */
public boolean checkUserAuthenticated(String userId, String password) throws Exception {
    javax.security.auth.login.LoginContext loginContext = null;

    Subject subject = null;

    try {
        loginContext = new javax.security.auth.login.LoginContext("WSLogin",
            new com.ibm.websphere.security.auth.callback.WSCallbackHandlerImpl(userId, password));
    } catch (javax.security.auth.login.LoginException e) {
        throw new Exception("Cannot create LoginContext", e);
    }

    try {
        loginContext.login();

        subject = loginContext.getSubject();
    } catch (com.ibm.websphere.security.auth.WSLoginFailedException e) {
        throw new Exception("Password is incorrect", e);
    } catch (Exception e) {
        throw new Exception("Unknown username", e);
    }

    if (subject == null)
        throw new Exception("Password is incorrect");

    return true;
}
于 2014-02-04T07:18:24.987 に答える