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

ドメインのグループ用のクラス(VB)

$
0
0

ドメインのグループを表すクラス DomainGroup クラスは DomainObject クラスを継承し IGroup インターフェイスを実装します。

Webアプリでデータソースとして使えるようにします。

 

<DataObject()>

Public NotInheritable ClassDomainGroup

  InheritsDomainObject

  ImplementsIGroup

 

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

  Private ReadOnly _security As Boolean

  Private ReadOnly _scope, _type As String

  Private ReadOnly _scopeType As DomainGroupScopeType

#End Region

 

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

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

  Friend Sub New(entry AsDirectoryEntry)

    MyBase.New(entry)

 

    Dim gtype = Convert.ToInt32(entry.Properties.Item("groupType").Value)

    If gtype < 0Then

      _security = True

      _type = "セキュリティ"

    Else

      gtype += Int32.MinValue

      _type = "配布"

    End If

    _scopeType = DirectCast([Enum].ToObject(GetType(DomainGroupScopeType), gtype), DomainGroupScopeType)

    _scope = GetGroupScope()  'グループのスコープを取得

  End Sub

#End Region

 

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

  'Entry の ADSI Group オブジェクトを取得します。

  Public ReadOnly Property Native AsIADsGroupImplementsIGroup.Native

    Get

      If MyBase.IsDisposed Then

        Throw NewObjectDisposedException(Me.GetType().Name)

      End If

      Return DirectCast(MyBase.Entry.NativeObject, IADsGroup)

    End Get

  End Property

 

  'グループのスコープを取得します。

  Public ReadOnly Property Scope As String

    Get

      Return _scope

    End Get

  End Property

 

  'グループのスコープタイプを取得します。

  Public ReadOnly Property ScopeType As DomainGroupScopeType

    Get

      Return _scopeType

    End Get

  End Property

 

  'セキュリティ グループかどうかを取得します。

  Public ReadOnly Property SecurityEnabled As Boolean

    Get

      Return _security

    End Get

  End Property

 

  'グループの種類を取得します。

  Public ReadOnly Property [Type] As String

    Get

      Return _type

    End Get

  End Property

#End Region

 

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

  '指定した名前のグループを検索します。このメソッドはデータバインド用です。

  <DataObjectMethod(DataObjectMethodType.Select)>

  Public Shared Function FindByName(name As String) AsDomainGroup

    Return DirectCast(DirectoryAccess.FindDirectoryObject(name, CategoryType.Group), DomainGroup)

  End Function

 

  'グループの一覧を取得します。このメソッドはデータバインド用です。

  <DataObjectMethod(DataObjectMethodType.Select)>

  Public Shared Function GetGroups() AsIList(OfDomainGroup)

    Return DirectoryAccess.GetGroups(OfDomainGroup)()    'グループを取得

  End Function

#End Region

 

#Region" プライベートメソッド "

  'グループのスコープを取得します。

  Private Function GetGroupScope() As String

    Select Case Me.ScopeType

      CaseDomainGroupScopeType.BuiltInLocal

        Return"ビルトイン ローカル"

      CaseDomainGroupScopeType.DomainLocal

        Return"ドメイン ローカル"

      CaseDomainGroupScopeType.[Global]

        Return"グローバル"

      Case Else

        Return"ユニバーサル"

    End Select

  End Function

#End Region

End Class

 

コンストラクタ内で属性「groupType」が正の値の時に、Int32.MinValue を加算(負の値なので実質減算)してます。

これは配布グループが正の値で符号ビットがないだけだからです。というよりセキュリティ グループに符号ビットが立ってるからです。

※ADSI の ADS_GROUP_TYPE_ENUM 列挙体の ADS_GROUP_TYPE_SECURITY_ENABLED


Viewing all articles
Browse latest Browse all 994

Trending Articles



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