1

iisでホストされているwcfサービスを別のサーバーのアクティブディレクトリにアクセスさせる方法

2つのサーバーがあります1-WCFサービスがIISでホストされているアプリケーションサーバー2-アクティブディレクトリサーバー私がしたいのは、このWCFがアクティブディレクトリにアクセスしてユーザーを追加、編集、または削除することだけです

WCF サービスを同じネットワーク内の別のサーバーの AD にアクセスさせる方法 ユーザーが Windows 資格情報「AD」でサインインできるイントラネット ポータルに取り組んでおり、ユーザーを「AD」に追加するための管理ページを開発したいと考えています。

「AD」でユーザーを作成する wcf サービスには、それを行う権限がありません。

    public bool AddActiveDirectoryUser(ADUser User)
    {
        string userLoginName = User.Email.Split("@".ToArray())[0];
        // Creating the PrincipalContext
        PrincipalContext principalContext = null;
        try
        {
            principalContext = new PrincipalContext(ContextType.Domain, ADServer, ADPath.Substring(ADPath.IndexOf("DC")), ADUser, ADPassword);

        }
        catch (Exception e)
        {
            WriteLog(e);
            return false;
        }


        UserPrincipal usr = UserPrincipal.FindByIdentity(principalContext, userLoginName);
        if (usr != null)
        {
            WriteLog(Enum.LogType.Error, userLoginName + " already exists. Please use a different Username.");
            return false;
        }

        // Create the new UserPrincipal object
        UserPrincipal userPrincipal = new UserPrincipal(principalContext);

        if (!string.IsNullOrEmpty(User.LastName) && User.LastName.Length > 0)
            userPrincipal.Surname = User.LastName;

        if (!string.IsNullOrEmpty(User.FirstName) && User.FirstName.Length > 0)
            userPrincipal.GivenName = User.FirstName;

        if (!string.IsNullOrEmpty(User.Email) && User.Email.Length > 0)
            userPrincipal.EmailAddress = User.Email;


        if (!string.IsNullOrEmpty(userLoginName) && userLoginName.Length > 0)
            userPrincipal.SamAccountName = userLoginName;

        userPrincipal.SetPassword("123456");

        userPrincipal.Enabled = true;
        userPrincipal.PasswordNeverExpires = true;

        try
        {
            userPrincipal.Save();

//ここで、アクセス拒否の例外がスローされます!!!!?

        }
        catch (Exception e)
        {
            WriteLog(e);
            return false;
        }
        return true;
    }
4

1 に答える 1

1

Ok, given the information you gave the problem is the following. The user you use to create the context doesn't have the enough permissions to perform these tasks. You need to grant permissions to this user on he OU the users are created in and all problems should go away.

Check this post for more information on the subject https://serverfault.com/questions/190566/what-permissions-are-needed-for-a-helpdesk-admin-to-create-users-in-ad

于 2013-08-25T13:52:19.830 に答える