1

WIF と ADFS 2.0 を使用して MVC3 Web アプリケーションを構築しています。私がやりたいことは、ユーザーにパスワード変更機能を提供することです。ユーザーは、この Web アプリケーションから AD パスワードを変更します。私は開発段階にあるため、開発用コンピューター (ドメイン外) から AD パスワードを変更できる必要があります。その後、権限は、十分なアクセス権を持つサービスを実行するユーザーに委任されます。

ユーザー名とパスワードを入力せずにこのロールベースを実行したいのですが、正しい方向に向けるリソースが見つからないようです。

助言がありますか?

4

1 に答える 1

4

WIFまたはADFSには、ユーザーパスワードを変更するための特別なものはありません。System.DirectoryServices名前空間で提供される標準のAD機能を使用する必要があります。

ADでパスワードを変更するためのサンプルコードは次のとおりです。

internal UserPrincipal GetUser(string userName)
{
    PrincipalContext principalContext = new PrincipalContext(ContextType.Domain, "YourADController",
                                               "YourADContainer",
                                               "ADAdminUser", "ADAdminPassword");

    UserPrincipal user = UserPrincipal.FindByIdentity(principalContext, userName);

    return user;
}

internal void ResetPassword(string userName, string newPassword)
{
    try
    {
        //
        // Update normal AD attributes
        //
        UserPrincipal user = GetUser(userName);
        user.SetPassword(newPassword);
    }
    catch (PasswordException)
    {
        throw new Exception("Password does not meet complexity requirements");
    }
}

internal void SetPassword(string userName, string oldPassword, string newPassword)
{
    try
    {
        //
        // Update normal AD attributes
        //
        UserPrincipal user = GetUser(userName);
        user.ChangePassword(oldPassword, newPassword);
    }
    catch (PasswordException)
    {
        throw new Exception("Password does not meet complexity requirements");
    }
}
于 2012-08-15T14:13:52.750 に答える