Quantcast
Channel: わんくま同盟
Viewing all articles
Browse latest Browse all 994

ForeignSecurityPrincipal クラス

$
0
0

グループのネストしているすべてのメンバーを表示する画面の追加に伴いクラスライブラリ側にクラスを追加しました。

今まで扱ってきたのは ユーザー、グループ、コンピューター、OU、プリンター、共有フォルダーの 6 オブジェクトで、これらのオブジェクトを表す DirectoryEntry をラップした専用のクラスで表しています。

今回、外部のセキュリティ プリンシパルがグループのメンバーに含まれるようになるので、これを表すクラスを追加しました。

 

ForeignSecurityPrincipal クラス(System.Security.Principal 名前空間をインポートしてます)

VB

Public NotInheritable ClassForeignSecurityPrincipal

  InheritsDomainObject

 

#Region" プライベートフィールド "

  Private ReadOnly _readableName, _displayName As String

#End Region

 

#Region" フレンドコンストラクター "

  'DirectoryEntry を指定して ForeignSecurityPrincipal クラスの新しいインスタンスを初期化します。

  Friend Sub New(entry AsDirectoryEntry)

    MyBase.New(entry)

 

    Dim objectSid = DirectCast(entry.Properties.Item("objectSid").Value, Byte())

    Dim sid = NewSecurityIdentifier(objectSid, 0'SID

    Dim account = DirectCast(sid.Translate(GetType(NTAccount)), NTAccount'アカウントに変換

    _readableName = account.Value   'NT AUTHORITY\○○ => ToStringメソッドでも同じ

    _displayName = IO.Path.GetFileName(account.Value)   'NT AUTHORITY\○○ の ○○部分

  End Sub

#End Region

 

#Region" パブリックプロパティ "

  '表示用の名前を取得します。

  Public ReadOnly Property DisplayName As String

    Get

      Return _displayName

    End Get

  End Property

 

  '読み取り可能な名前を取得します。

  Public ReadOnly Property ReadableName As String

    Get

      Return _readableName

    End Get

  End Property

#End Region

 

#Region" パブリックメソッド "

  '表示用の名前を返します。

  Public Overrides Function ToString() As String

    Return Me.DisplayName

  End Function

#End Region

End Class

 

C#

public sealed classForeignSecurityPrincipal : DomainObject

{

  #regionプライベートフィールド

  private readonly string _readableName, _displayName;

  #endregion

 

  #regionインターナルコンストラクタ

  //DirectoryEntry を指定して ForeignSecurityPrincipal クラスの新しいインスタンスを初期化します。

  internal ForeignSecurityPrincipal(DirectoryEntry entry)

    : base(entry)

  {

    var objectSid = (byte[])entry.Properties["objectSid"].Value;

    var sid = newSecurityIdentifier(objectSid, 0);   //SID

    var account = (NTAccount)sid.Translate(typeof(NTAccount));  //アカウントに変換

    _readableName = account.Value;   //NT AUTHORITY\○○ => ToStringメソッドでも同じ

    _displayName = System.IO.Path.GetFileName(account.Value);   //NT AUTHORITY\○○ の ○○部分

  }

  #endregion

 

  #regionパブリックプロパティ

  //表示用の名前を取得します。

  public string DisplayName

  {

    get

    {

      return _displayName;

    }

  }

 

  //読み取り可能な名前を取得します。

  public string ReadableName

  {

    get

    {

      return _readableName;

    }

  }

  #endregion

 

  #regionパブリックメソッド

  //表示用の名前を返します。

  public override string ToString()

  {

    return this.DisplayName;

  }

  #endregion

}

 

 

 

Active Directory 関連 Blog

http://www.pbyk.com/blog/bloglist.html


Viewing all articles
Browse latest Browse all 994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>