Exchange で EWS を使用して別のユーザーのフォルダーのアクセス許可を設定する

Exchange で EWS マネージ API または EWS を使用して、フォルダーのアクセス許可レベルを設定する方法について説明します。

フォルダー レベルのアクセス許可によって、ユーザーは、他のユーザーのメールボックスの 1 つ以上のフォルダーにアクセス可能になります。 フォルダーのアクセス許可は代理人アクセスに似ていますが、次のような相違点があります。

  • フォルダーのアクセス許可では、ユーザーに "代理人として送信" させたり、別のユーザーとして "差出人を指定して送信" したりすることはできません。 ユーザーは、フォルダーにのみアクセスできます。 ユーザーは、フォルダーのアイテムを作成できますが、それらを送信することはできません。

  • メールボックスの任意のフォルダーで、フォルダーのアクセス許可を設定できますが、代理人を追加できるのは、予定表、連絡先、受信トレイ、履歴、メモ、タスクのフォルダーのみです。

  • 特定のフォルダーのアクセス許可の数を設定できます。 代理人を追加する場合、5 つのアクセス許可レベルの内 1 つのみを割り当てることができます。

  • 匿名ユーザーと既定のユーザーに対して、フォルダーのアクセス許可を設定できます。 メールが有効なアカウントだけに代理人アクセスを許可できます。

アクセス制御エントリ (ACE) と随意アクセス制御リスト (DACL) に精通していれば、ユーザーが各フォルダーのアクセス許可のセットを 1 つだけ持てることをご存じでしょう。 ユーザーにアクセス許可のセットを追加しようとすると、そのユーザーがアクセス許可のセットを既に持っている場合、エラーが返されます。 フォルダーのアクセス許可を追加、削除、更新する場合、現在の DACL を取得し、任意の ACE を追加するか削除し、更新した DACL を送信します。 同じユーザーに対して複数の ACE を追加することはできません。 EWS マネージ API を使用してアクセス許可を更新する場合、ユーザーの現在の ACE を削除し、新しい ACE をコレクションに追加する必要があります。 EWS を使用している場合は、以前の ACE のセットを新しいセットに置き換えるだけです。

1 つのフォルダーに対して複数のアクセス許可を変更する場合は、追加、削除、または更新をバッチ処理できます。複数のフォルダーでユーザーの更新をバッチ処理することはできません。 1 つのフォルダーに対するアクセス許可を取得するには 1 回の呼び出しが必要で、そのフォルダーのアクセス許可を更新するには 2 回目の呼び出しが必要です。 ユーザーのアクセス許可を追加、削除、または更新するときは、タスクごとに同じ 2 つのメソッド呼び出しまたは操作を使用します。

表 1. フォルダー アクセス許可を設定する EWS マネージ API メソッドと EWS 操作

目的… 使用する EWS マネージ API メソッド… 使用する EWS 操作…
フォルダーのアクセス許可の有効化、削除、更新
Folder.Bind の後に Folder.Update
GetFolder の後に UpdateFolder
フォルダーの作成、フォルダーのアクセス許可の定義
Folder.Save
CreateFolder

フォルダーのアクセス許可

特定のフォルダーに対するフォルダーのアクセス許可の設定に関しては、かなり多くのオプションがあります。 各ユーザーのフォルダーに対してアクセス許可レベルを設定できます。これにより、定義済みの個々のアクセス許可のセットが DACL に追加されます。また、フォルダーに対して個々のアクセス許可を設定することもできますが、混在および一致することはできません。

次の個別アクセス許可を使用できます。

  • 作成可能
  • サブフォルダー作成可能
  • フォルダーの所有者になる
  • フォルダーを表示可能
  • 連絡先フォルダーにする
  • アイテムの編集
  • アイテムの削除
  • アイテムの参照

さらに、次のアクセス許可レベルを使用できます。それは、表 2 に示すように個別アクセス許可と値のサブセットを定義します。

  • なし
  • Owner (所有者)
  • PublishingEditor (出版編集者)
  • Editor (編集者)
  • PublishingAuthor (出版著者)
  • Author (著者)
  • NoneditingAuthor (非編集著者)
  • Reviewer (校閲者)
  • 共同作成者
  • Custom: この値は、アプリケーションでは設定できません。 個別アクセス許可のカスタム コレクションがアプリケーションに含まれている場合、サーバーはこの値を設定します。
  • FreeBusyTimeOnly: これは予定表フォルダーにのみ設定できます。
  • FreeBusyTimeAndSubjectAndLocation: これは予定表フォルダーにのみ設定できます。

次の表は、アクセス許可レベルに基づき、既定で適用される個別アクセス許可を示しています。

表 2. アクセス許可レベル別の個々のアクセス許可

権限レベル アイテム作成可能 サブ フォルダー作成可能 フォルダーの所有者になる フォルダーを表示可能 連絡先フォルダーにする アイテムの編集 アイテムの削除 アイテムの参照可能
None (なし)
False
False
False
False
False
なし
なし
なし
Owner
True
True
True
True
True
すべて
すべて
FullDetails
PublishingEditor (出版編集者)
True
True
False
True
False
すべて
すべて
FullDetails
Editor (編集者)
True
False
False
True
False
すべて
すべて
FullDetails
PublishingAuthor (出版著者)
True
True
False
True
False
Owned (所有)
Owned (所有)
FullDetails
Author (著者)
True
False
False
True
False
Owned (所有)
Owned (所有)
FullDetails
NoneditingAuthor (非編集著者)
True
False
False
True
False
None (なし)
Owned (所有)
FullDetails
Reviewer (校閲者)
False
False
False
True
False
なし
None (なし)
FullDetails
Contributor (投稿者)
True
False
False
True
False
なし
なし
なし

フォルダー レベルのアクセス許可の要求でカスタム以外のアクセス許可レベルを指定する場合、個別アクセス許可の設定を指定する必要はありません。 アクセス許可レベルを設定する場合、個別アクセス許可を指定すると、応答で ErrorInvalidPermissionSettings エラーが返されます。

EWS マネージ API を使用してフォルダーのアクセス許可を追加する

次のコード例は、以下の目的で EWS マネージ API を使用する方法を示しています。

  • 新規ユーザーに対して FolderPermission オブジェクトを新規作成する。

  • Bind メソッドを使用して、フォルダーに対する現在のアクセス許可を取得する。

  • 新しい FolderPermissionsFolder.Permissions プロパティに追加する。

  • Update メソッドを呼び出して、サーバーに新規アクセス許可を保存する。

この例では、service はメールボックス所有者の有効な ExchangeService オブジェクトであり、ユーザーは Exchange サーバーに既に認証されていると想定しています。

static void EnableFolderPermissions(ExchangeService service)
{
    // Create a property set to use for folder binding.
    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, FolderSchema.Permissions);
    // Specify the SMTP address of the new user and the folder permissions level.
    FolderPermission fldperm = new FolderPermission("sadie@contoso.com", FolderPermissionLevel.Editor);
    
    // Bind to the folder and get the current permissions. 
    // This call results in a GetFolder call to EWS.
    Folder sentItemsFolder = Folder.Bind(service, WellKnownFolderName.SentItems, propSet);
 
    // Add the permissions for the new user to the Sent Items DACL.
    sentItemsFolder.Permissions.Add(fldperm);
    // This call results in a UpdateFolder call to EWS.
    sentItemsFolder.Update();
}

次のコードの行は、アクセス許可レベルを指定します。

    FolderPermission fldperm = new FolderPermission("sadie@contoso.com", FolderPermissionLevel.Editor);

カスタム アクセス許可レベルを使用する場合は、代わりに次のコードを使用します。

FolderPermission fldperm = new FolderPermission();
fldperm.UserId = "sadie@Contoso1000.onmicrosoft.com";
fldperm.CanCreateItems = true;
fldperm.CanCreateSubFolders = true;
…

FolderPermission オブジェクトをカスタム アクセス許可レベルで作成する場合、書き込み可能な FolderPermission プロパティの一部またはすべてを設定できます。 ただし、アプリケーションが FolderPermissionLevel を明示的に Custom に設定することは決してないことにご注意ください。 FolderPermission オブジェクトを作成し、個別アクセス許可を設定する場合のみ、FolderPermissionLevel は Custom に設定されます。

EWS を使用してフォルダーのアクセス許可を追加する

次の EWS のコード例では、現在のアクセス許可を取得し、新しいアクセス許可の一覧を送信することによって、特定のフォルダーにアクセス許可を追加する方法を示しています。

最初の手順は、GetFolder 要求を送信することです。この要求では、DistinguishedFolderId 値でアクセス許可を追加するフォルダー (この例では [送信済みアイテム] フォルダー) を指定し、FieldURI 値に folder:PermissionSet を含んでいます。 この要求は、指定したフォルダーのアクセス許可設定を取得します。

これは、フォルダーのアクセス許可を追加するために Bind メソッドを呼び出す際に、EWS マネージ API が送信する XML 要求でもあります。

  <?xml version="1.0" encoding="utf-8"?>
  <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                 xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages" 
                 xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types" 
                 xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
      <t:RequestServerVersion Version="Exchange2007_SP1" />
    </soap:Header>
    <soap:Body>
      <m:GetFolder>
        <m:FolderShape>
          <t:BaseShape>IdOnly</t:BaseShape>
          <t:AdditionalProperties>
            <t:FieldURI FieldURI="folder:PermissionSet" />
          </t:AdditionalProperties>
        </m:FolderShape>
        <m:FolderIds>
          <t:DistinguishedFolderId Id="sentitems" />
        </m:FolderIds>
      </m:GetFolder>
    </soap:Body>
  </soap:Envelope>

サーバーは、GetFolder 要求に GetFolderResponse メッセージで応答します。このメッセージには、フォルダーが正常に取得されたことを示す、値が NoErrorResponseCode要素が含まれます。 FolderId 値と ParentFolderId 値は、読みやすくするために短縮してあります。

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15"
                         MinorVersion="0"
                         MajorBuildNumber="893"
                         MinorBuildNumber="17"
                         Version="V2_10"
                         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetFolderResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
                         xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetFolderResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Folders>
            <t:Folder>
              <t:FolderId Id="CgAAAA=="
                          ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd1" />
              <t:PermissionSet>
                <t:Permissions>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Default</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                </t:Permissions>
              </t:PermissionSet>
            </t:Folder>
          </m:Folders>
        </m:GetFolderResponseMessage>
      </m:ResponseMessages>
    </m:GetFolderResponse>
  </s:Body>
</s:Envelope>

次に、UpdateFolder 操作を使用して、更新された PermissionSet を送信します。それには、新規ユーザーのための Permission が含まれています。 UpdateFolder 操作で各フォルダーの SetFolderField 要素を含めると、そのフォルダーのすべてのアクセス許可設定が上書きされることに注意してください。 同様に、UpdateFolder 操作の DeleteFolderField オプションを含めると、フォルダーのすべてのアクセス許可設定が削除されます。

これは、フォルダーのアクセス許可を追加するために Update メソッドを呼び出す際に、EWS マネージ API が送信する XML 要求でもあります。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:UpdateFolder>
      <m:FolderChanges>
        <t:FolderChange>
          <t:FolderId Id="CgAAAA=="
                      ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd1" />
          <t:Updates>
            <t:SetFolderField>
              <t:FieldURI FieldURI="folder:PermissionSet" />
              <t:Folder>
                <t:PermissionSet>
                  <t:Permissions>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Default</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:PrimarySmtpAddress>sadie@contoso.com</t:PrimarySmtpAddress>
                      </t:UserId>
                      <t:PermissionLevel>Editor</t:PermissionLevel>
                    </t:Permission>
                  </t:Permissions>
                </t:PermissionSet>
              </t:Folder>
            </t:SetFolderField>
          </t:Updates>
        </t:FolderChange>
      </m:FolderChanges>
    </m:UpdateFolder>
  </soap:Body>
</soap:Envelope>

次のコードの行は、アクセス許可レベルを指定します。

<t:Permission>
    <t:UserId>
        <t:PrimarySmtpAddress>sadie@contoso.com</t:PrimarySmtpAddress>
    </t:UserId>
    <t:PermissionLevel>Editor</t:PermissionLevel>
</t:Permission>

カスタム アクセス許可レベルを使用する場合は、代わりに次のコードを使用します。

<t:Permission>
    <t:UserId>
        <t:PrimarySmtpAddress> sadie@contoso.com </t:PrimarySmtpAddress>
    </t:UserId>
    <t:CanCreateItems>true</t:CanCreateItems>
    <t:CanCreateSubFolders>true</t:CanCreateSubFolders>
    <t:IsFolderOwner>false</t:IsFolderOwner>
    <t:IsFolderVisible>false</t:IsFolderVisible>
    <t:IsFolderContact>false</t:IsFolderContact>
    <t:EditItems>None</t:EditItems>
    <t:DeleteItems>None</t:DeleteItems>
    <t:ReadItems>None</t:ReadItems>
    <t:PermissionLevel>Custom</t:PermissionLevel>
</t:Permission>

サーバーは、UpdateFolder 要求に UpdateFolderResponse メッセージで応答します。このメッセージには、フォルダーが正常に更新されたことを示す、NoErrorResponseCode 要素の値が含まれます。

EWS マネージ API を使用してフォルダーのアクセス許可を削除する

次のコード例は、既定および匿名のアクセス許可を除く、特定のフォルダーのすべてのユーザーのアクセス許可を削除するために、EWS マネージ API を使用する方法を示しています。

  1. Bind メソッドを使用して、フォルダーの現在のアクセス許可を取得します。

  2. Permissions コレクションを反復処理し、個別ユーザーのアクセス許可を削除します。

  3. Update メソッドを呼び出して、変更を保存します。

この例では、フォルダーのすべてのユーザー アクセス許可を削除します。 特定のユーザーのアクセス許可のみを削除するようこの例を変更する場合、次のコードの行を変更して、ユーザーの表示名、または SMTP アドレスのいずれかを識別できるようにします。

if (sentItemsFolder.Permissions[t].UserId.DisplayName != null || sentItemsFolder.Permissions[t].UserId.PrimarySmtpAddress != null)

この例では、service はメールボックス所有者の有効な ExchangeService オブジェクトであり、ユーザーは Exchange サーバーに既に認証されていると想定しています。

static void RemoveFolderPermissions(ExchangeService service)
{
    // Create a property set to use for folder binding.
    PropertySet propSet = new PropertySet(BasePropertySet.FirstClassProperties, FolderSchema.Permissions);
    // Bind to the folder and get the current permissions. 
    // This call results in a GetFolder call to EWS.
    Folder sentItemsFolder = Folder.Bind(service, new FolderId(WellKnownFolderName.SentItems, "primary@contoso.com"), propSet);
    // Iterate through the collection of permissions and remove permissions for any 
    // user with a display name or SMTP address. This leaves the anonymous and 
    // default user permissions unchanged. 
    if (sentItemsFolder.Permissions.Count != 0)
    {
        for (int t = 0; t < sentItemsFolder.Permissions.Count; t++)
        {
            // Find any permissions associated with the specified user and remove them from the DACL
            if (sentItemsFolder.Permissions[t].UserId.DisplayName != null || sentItemsFolder.Permissions[t].UserId.PrimarySmtpAddress != null)
            {
                sentItemsFolder.Permissions.Remove(sentItemsFolder.Permissions[t]);
            }
        }
    }
    // This call results in an UpdateFolder call to EWS.
    sentItemsFolder.Update();
}

EWS を使用してフォルダーのアクセス許可を削除する

EWS の次のコード例は、既定および匿名のアクセス許可を除く、特定のフォルダーのすべてのユーザーのアクセス許可を削除する方法を示します。

最初の手順は、GetFolder 要求を送信することです。この要求では、DistinguishedFolderId 値でアクセス許可を削除するフォルダー (この例では [送信済みアイテム] フォルダー) を指定し、FieldURI 値に folder:PermissionSet を含んでいます。 この要求は、指定したフォルダーの PermissionSet を取得します。

これは、フォルダーのアクセス許可を削除するために Bind メソッドを呼び出す際に、EWS マネージ API が送信する XML 要求でもあります。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:GetFolder>
      <m:FolderShape>
        <t:BaseShape>AllProperties</t:BaseShape>
        <t:AdditionalProperties>
          <t:FieldURI FieldURI="folder:PermissionSet" />
        </t:AdditionalProperties>
      </m:FolderShape>
      <m:FolderIds>
        <t:DistinguishedFolderId Id="drafts">
          <t:Mailbox>
            <t:EmailAddress>primary@contoso.com</t:EmailAddress>
          </t:Mailbox>
        </t:DistinguishedFolderId>
      </m:FolderIds>
    </m:GetFolder>
  </soap:Body>
</soap:Envelope>

サーバーは、GetFolder 要求に GetFolderResponse メッセージで応答します。このメッセージには、フォルダーが正常に取得されたことを示す、値が NoErrorResponseCode要素が含まれます。 FolderId 要素の値と ParentFolderId 要素の値は、読みやすくするために短縮してあります。

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope xmlns:s="https://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <h:ServerVersionInfo MajorVersion="15"
                         MinorVersion="0"
                         MajorBuildNumber="893"
                         MinorBuildNumber="17"
                         Version="V2_10"
                         xmlns:h="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns="https://schemas.microsoft.com/exchange/services/2006/types"
                         xmlns:xsd="http://www.w3.org/2001/XMLSchema"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" />
  </s:Header>
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <m:GetFolderResponse xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
                         xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types">
      <m:ResponseMessages>
        <m:GetFolderResponseMessage ResponseClass="Success">
          <m:ResponseCode>NoError</m:ResponseCode>
          <m:Folders>
            <t:Folder>
              <t:FolderId Id="EAAAAA=="
                          ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd5" />
              <t:ParentFolderId Id="CQAAAA=="
                                ChangeKey="AQAAAA==" />
              <t:FolderClass>IPF.Note</t:FolderClass>
              <t:DisplayName>Drafts</t:DisplayName>
              <t:TotalCount>0</t:TotalCount>
              <t:ChildFolderCount>0</t:ChildFolderCount>
              <t:EffectiveRights>
                <t:CreateAssociated>true</t:CreateAssociated>
                <t:CreateContents>true</t:CreateContents>
                <t:CreateHierarchy>true</t:CreateHierarchy>
                <t:Delete>true</t:Delete>
                <t:Modify>true</t:Modify>
                <t:Read>true</t:Read>
                <t:ViewPrivateItems>true</t:ViewPrivateItems>
              </t:EffectiveRights>
              <t:PermissionSet>
                <t:Permissions>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Default</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                    </t:UserId>
                    <t:CanCreateItems>false</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>false</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>None</t:EditItems>
                    <t:DeleteItems>None</t:DeleteItems>
                    <t:ReadItems>None</t:ReadItems>
                    <t:PermissionLevel>None</t:PermissionLevel>
                  </t:Permission>
                  <t:Permission>
                    <t:UserId>
                      <t:SID>S-1-5-21-1337771579-694202782-848329751-1535223</t:SID>
                      <t:PrimarySmtpAddress>sadie@Contoso.com</t:PrimarySmtpAddress>
                      <t:DisplayName>Sadie Daniels</t:DisplayName>
                    </t:UserId>
                    <t:CanCreateItems>true</t:CanCreateItems>
                    <t:CanCreateSubFolders>false</t:CanCreateSubFolders>
                    <t:IsFolderOwner>false</t:IsFolderOwner>
                    <t:IsFolderVisible>true</t:IsFolderVisible>
                    <t:IsFolderContact>false</t:IsFolderContact>
                    <t:EditItems>All</t:EditItems>
                    <t:DeleteItems>All</t:DeleteItems>
                    <t:ReadItems>FullDetails</t:ReadItems>
                    <t:PermissionLevel>Editor</t:PermissionLevel>
                  </t:Permission>
                </t:Permissions>
              </t:PermissionSet>
              <t:UnreadCount>0</t:UnreadCount>
            </t:Folder>
          </m:Folders>
        </m:GetFolderResponseMessage>
      </m:ResponseMessages>
    </m:GetFolderResponse>
  </s:Body>
</s:Envelope>

次に、UpdateFolder 操作を使用し、更新された PermissionSet を送信します。削除したユーザーの Permission は含まれていません。

これは、フォルダーのアクセス許可を削除するために Update メソッドを呼び出す際に、EWS マネージ API が送信する XML 要求でもあります。

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:m="https://schemas.microsoft.com/exchange/services/2006/messages"
               xmlns:t="https://schemas.microsoft.com/exchange/services/2006/types"
               xmlns:soap="https://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <t:RequestServerVersion Version="Exchange2007_SP1" />
  </soap:Header>
  <soap:Body>
    <m:UpdateFolder>
      <m:FolderChanges>
        <t:FolderChange>
          <t:FolderId Id="EAAAAA=="
                      ChangeKey="AQAAABYAAADOilbYa8KaT7ZgMoTz2P+hAAABiRd5" />
          <t:Updates>
            <t:SetFolderField>
              <t:FieldURI FieldURI="folder:PermissionSet" />
              <t:Folder>
                <t:PermissionSet>
                  <t:Permissions>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Default</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                    <t:Permission>
                      <t:UserId>
                        <t:DistinguishedUser>Anonymous</t:DistinguishedUser>
                      </t:UserId>
                      <t:PermissionLevel>None</t:PermissionLevel>
                    </t:Permission>
                  </t:Permissions>
                </t:PermissionSet>
              </t:Folder>
            </t:SetFolderField>
          </t:Updates>
        </t:FolderChange>
      </m:FolderChanges>
    </m:UpdateFolder>
  </soap:Body>
</soap:Envelope>

サーバーは、UpdateFolderResponse メッセージで UpdateFolder 要求に応答します。このメッセージには、更新が正常に完了したことを示す、NoErrorResponseCode 要素の値が含まれます。

EWS マネージ API を使用してフォルダーのアクセス許可を更新する

EWS マネージ API を使用して、特定のフォルダーのフォルダーのアクセス許可を更新することもできます。 アクセス許可を更新するには、次を行います。

  1. 古いアクセス許可のフォルダーのアクセス許可を削除しますが、(まだ) Update メソッドを呼び出しません。

  2. 新規または変更されたユーザーのフォルダーのアクセス許可を追加します

  3. Update メソッドを呼び出して、変更を保存します。

同じユーザーのアクセス許可の 2 つのセットを追加しようとする場合、「指定したアクセス許可のセットには、重複したユーザー Id が含まれています」という説明がある ServiceResponseException エラーを受け取ります。 このケースでは、Permission コレクションから現在のアクセス許可を削除してから、新しいアクセス許可を Permission コレクションに追加します。

EWS を使用してフォルダーのアクセス許可を更新する

EWS を使用して、削除と追加のプロセスを組み合わせ、特定のフォルダーのフォルダーのアクセス許可を更新することもできます。 アクセス許可を更新するには、次を行います。

  1. GetFolder 操作を使用して、フォルダーの現在のアクセス許可を取得します。

  2. UpdateFolder 操作を使用して、更新されたアクセス許可の一覧を送信します。

これらは、EWS を使用してアクセスの有効化またはアクセスの削除を行うのに使用するのと同じ 2 つの操作です。 唯一の違いは、GetFolder 応答を受信したときにユーザーの Permission 設定が含まれていることです。 単に既存の Permission 要素を新しい Permission 要素に取り替え、新しい Permission の値 (複数の場合もある) を指定して UpdateFolder 操作を送信します。

同じユーザーに、アクセス許可のセットを 2 つ追加しようとすると、値が ErrorDuplicateUserIdsSpecifiedResponseCode を受け取ります。 このケースでは、要求からユーザーのアクセス許可の古い値を削除してから、要求を再試行します。

次の手順

ユーザーのアクセス許可を特定のフォルダーに設定した後、そのユーザーは代理人としてフォルダーにアクセスできます。 詳細については、以下を参照してください:

関連項目