SemaphoreSecurity.RemoveAccessRule(SemaphoreAccessRule) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したルールと同じユーザーと AccessControlType (許可または拒否) を持ち、互換性のある継承と伝達フラグを持つアクセス制御規則を検索します。そのような規則が見つかった場合は、指定したアクセス規則に含まれる権限が削除されます。
public:
bool RemoveAccessRule(System::Security::AccessControl::SemaphoreAccessRule ^ rule);
public bool RemoveAccessRule(System.Security.AccessControl.SemaphoreAccessRule rule);
override this.RemoveAccessRule : System.Security.AccessControl.SemaphoreAccessRule -> bool
Public Function RemoveAccessRule (rule As SemaphoreAccessRule) As Boolean
パラメーター
- rule
- SemaphoreAccessRule
検索するユーザーとAccessControlTypeを指定するSemaphoreAccessRuleと、一致するルールが見つかった場合は互換性が必要な継承フラグと伝達フラグのセット。 互換性のあるルールが見つかった場合に削除する権限を指定します。
返品
true 互換性のあるルールが見つかった場合。それ以外の場合は false。
例外
rule は nullです。
例
次のコード例では、RemoveAccessRule メソッドを使用して、SemaphoreSecurity オブジェクトのAllowルールから権限を削除する方法を示します。 また、 rule の他の権限が無視されていることも示しています。
この例では、 SemaphoreSecurity オブジェクトを作成し、現在のユーザーのさまざまな権限を許可および拒否する規則を追加します。 許可される権限には、 Modify、 ReadPermissions、および Synchronizeが含まれます。 次に、ReadPermissions権限やTakeOwnership権限を含む現在のユーザーの新しいルールを作成し、RemoveAccessRule メソッドでそのルールを使用して、SemaphoreSecurity オブジェクトのAllowルールからReadPermissionsを削除します。
rule内の余分なTakeOwnershipは無視されます。
Note
この例では、セキュリティ オブジェクトを Semaphore オブジェクトにアタッチしません。 セキュリティ オブジェクトをアタッチする例は、 Semaphore.GetAccessControl と Semaphore.SetAccessControlにあります。
using System;
using System.Threading;
using System.Security.AccessControl;
using System.Security.Principal;
public class Example
{
public static void Main()
{
// Create a string representing the current user.
string user = Environment.UserDomainName + "\\" +
Environment.UserName;
// Create a security object that grants no access.
SemaphoreSecurity mSec = new SemaphoreSecurity();
// Add a rule that grants the current user the
// right to enter or release the semaphore and read the
// permissions on the semaphore.
SemaphoreAccessRule rule = new SemaphoreAccessRule(user,
SemaphoreRights.Synchronize | SemaphoreRights.Modify
| SemaphoreRights.ReadPermissions,
AccessControlType.Allow);
mSec.AddAccessRule(rule);
// Add a rule that denies the current user the
// right to change permissions on the semaphore.
rule = new SemaphoreAccessRule(user,
SemaphoreRights.ChangePermissions,
AccessControlType.Deny);
mSec.AddAccessRule(rule);
// Display the rules in the security object.
ShowSecurity(mSec);
// Create a rule that grants the current user
// the right to read permissions on the semaphore, and
// take ownership of the semaphore. Use this rule to
// remove the right to read permissions from the
// Allow rule for the current user. The inclusion
// of the right to take ownership has no effect.
rule = new SemaphoreAccessRule(user,
SemaphoreRights.TakeOwnership |
SemaphoreRights.ReadPermissions,
AccessControlType.Allow);
mSec.RemoveAccessRule(rule);
ShowSecurity(mSec);
}
private static void ShowSecurity(SemaphoreSecurity security)
{
Console.WriteLine("\r\nCurrent access rules:\r\n");
foreach(SemaphoreAccessRule ar in
security.GetAccessRules(true, true, typeof(NTAccount)))
{
Console.WriteLine(" User: {0}", ar.IdentityReference);
Console.WriteLine(" Type: {0}", ar.AccessControlType);
Console.WriteLine(" Rights: {0}", ar.SemaphoreRights);
Console.WriteLine();
}
}
}
/*This code example produces output similar to following:
Current access rules:
User: TestDomain\TestUser
Type: Deny
Rights: ChangePermissions
User: TestDomain\TestUser
Type: Allow
Rights: Modify, ReadPermissions, Synchronize
Current access rules:
User: TestDomain\TestUser
Type: Deny
Rights: ChangePermissions
User: TestDomain\TestUser
Type: Allow
Rights: Modify, Synchronize
*/
Imports System.Threading
Imports System.Security.AccessControl
Imports System.Security.Principal
Public Class Example
Public Shared Sub Main()
' Create a string representing the current user.
Dim user As String = Environment.UserDomainName _
& "\" & Environment.UserName
' Create a security object that grants no access.
Dim mSec As New SemaphoreSecurity()
' Add a rule that grants the current user the
' right to enter or release the semaphore, and to
' read its permissions.
Dim rule As New SemaphoreAccessRule(user, _
SemaphoreRights.Synchronize _
Or SemaphoreRights.Modify _
Or SemaphoreRights.ReadPermissions, _
AccessControlType.Allow)
mSec.AddAccessRule(rule)
' Add a rule that denies the current user the
' right to change permissions on the semaphore.
rule = New SemaphoreAccessRule(user, _
SemaphoreRights.ChangePermissions, _
AccessControlType.Deny)
mSec.AddAccessRule(rule)
' Display the rules in the security object.
ShowSecurity(mSec)
' Create a rule that grants the current user
' the right to read permissions on the semaphore, and
' take ownership of the semaphore. Use this rule to
' remove the right to read permissions from the
' Allow rule for the current user. The inclusion
' of the right to take ownership has no effect.
rule = New SemaphoreAccessRule(user, _
SemaphoreRights.TakeOwnership _
Or SemaphoreRights.ReadPermissions, _
AccessControlType.Allow)
mSec.RemoveAccessRule(rule)
ShowSecurity(mSec)
End Sub
Private Shared Sub ShowSecurity(ByVal security As SemaphoreSecurity)
Console.WriteLine(vbCrLf & "Current access rules:" & vbCrLf)
For Each ar As SemaphoreAccessRule In _
security.GetAccessRules(True, True, GetType(NTAccount))
Console.WriteLine(" User: {0}", ar.IdentityReference)
Console.WriteLine(" Type: {0}", ar.AccessControlType)
Console.WriteLine(" Rights: {0}", ar.SemaphoreRights)
Console.WriteLine()
Next
End Sub
End Class
'This code example produces output similar to following:
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Deny
' Rights: ChangePermissions
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: Modify, ReadPermissions, Synchronize
'
'
'Current access rules:
'
' User: TestDomain\TestUser
' Type: Deny
' Rights: ChangePermissions
'
' User: TestDomain\TestUser
' Type: Allow
' Rights: Modify, Synchronize
注釈
現在のSemaphoreSecurityは、ruleと同じユーザーと同じAccessControlType値を持つルールを検索します。 このようなルールが見つからない場合、アクションは実行されません。メソッドは falseを返します。 一致する規則が見つかった場合、継承フラグと互換性フラグは、 ruleで指定されたフラグとの互換性をチェックします。 互換性のあるルールが見つからない場合、アクションは実行されません。メソッドは falseを返します。 互換性のあるフラグを持つ規則が見つかった場合、 rule で指定された権限は互換性のある規則から削除され、メソッドは trueを返します。
ruleが互換性のある規則に含まれていない権限を指定した場合、それらの権限に対するアクションは実行されません。 互換性のあるルールからすべての権限が削除された場合、ルール全体が現在の SemaphoreSecurity オブジェクトから削除されます。
Important
セマフォ アクセス 規則の継承フラグと伝達フラグは指定できますが、 AccessRuleFactory メソッドを使用して作成することはお勧めしません。 継承と伝達は、名前付きセマフォには意味がなく、アクセス規則のメンテナンスがより複雑になります。