WindowsIdentity コンストラクター

定義

WindowsIdentity クラスの新しいインスタンスを初期化します。

オーバーロード

WindowsIdentity(IntPtr)

指定した Windows アカウント トークンによって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(WindowsIdentity)

指定した WindowsIdentity オブジェクトを使用して、WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(String)

指定した UPN (User Principal Name) で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(IntPtr, String)

指定した Windows アカウント トークンと指定した認証の種類によって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(SerializationInfo, StreamingContext)
古い.

SerializationInfo ストリーム内の情報で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(String, String)

指定した UPN (User Principal Name) と指定した認証の種類で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(IntPtr, String, WindowsAccountType)

指定した Windows アカウント トークン、指定した認証の種類、および指定した Windows アカウントの種類によって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

指定した Windows アカウント トークン、指定した認証の種類、指定した Windows アカウントの種類、および指定した認証ステータスによって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(IntPtr)

指定した Windows アカウント トークンによって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(IntPtr userToken);
public WindowsIdentity (IntPtr userToken);
new System.Security.Principal.WindowsIdentity : nativeint -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr)

パラメーター

userToken
IntPtr

nativeint

コードが実行されている対象ユーザーのアカウント トークン。

例外

userToken が 0 です。

- または -

userToken は、複製され、偽装に対して無効になっています。

呼び出し元に、正しいアクセス許可がありません。

- または -

Win32 エラーが発生しました。

注釈

のインスタンスの初期プロパティ値を次の WindowsIdentity表に示します。

プロパティ 初期値
AuthenticationType Negotiate
WindowsAccountType Normal
IsAuthenticated false

Note

によって表される userToken トークンを取得するには、Windows API LogonUser 関数などのアンマネージ コードを呼び出します。 Windows API CloseHandle 関数を呼び出して、常に解放userTokenします。 アンマネージ コードの呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。

適用対象

WindowsIdentity(WindowsIdentity)

指定した WindowsIdentity オブジェクトを使用して、WindowsIdentity クラスの新しいインスタンスを初期化します。

protected:
 WindowsIdentity(System::Security::Principal::WindowsIdentity ^ identity);
protected WindowsIdentity (System.Security.Principal.WindowsIdentity identity);
new System.Security.Principal.WindowsIdentity : System.Security.Principal.WindowsIdentity -> System.Security.Principal.WindowsIdentity
Protected Sub New (identity As WindowsIdentity)

パラメーター

identity
WindowsIdentity

WindowsIdentity の新しいインスタンスの生成元となるオブジェクト。

適用対象

WindowsIdentity(String)

指定した UPN (User Principal Name) で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(System::String ^ sUserPrincipalName);
public WindowsIdentity (string sUserPrincipalName);
new System.Security.Principal.WindowsIdentity : string -> System.Security.Principal.WindowsIdentity
Public Sub New (sUserPrincipalName As String)

パラメーター

sUserPrincipalName
String

コードが実行されている対象ユーザーの UPN。

例外

Windows は、Windows NT ステータス コード STATUS_ACCESS_DENIED を返しました。

使用できるメモリが不足しています。

呼び出し元に、正しいアクセス許可がありません。

- または -

コンピューターは Windows 2003 以降のドメインに接続されていません。

- または -

コンピューターは Windows 2003 以降を実行していません。

- または -

ユーザーは、コンピューターが接続されているドメインのメンバーではありません。

注釈

UPN には、 ユーザー名@domainname.com という形式 (つまり、メール アドレス) があります。 で sUserPrincipalName 識別される UPN は、Windows API LsaLogonUser 関数を使用してそのユーザーのトークンを取得するために使用されます。 次に、そのトークンを使用してユーザーを識別します。 指定された UPN を使用してログオンできないため、例外が返される可能性があります。

Note

このコンストラクターは、Windows Server 2003 以降のドメインに参加しているコンピューターでのみ使用することを目的としています。 以前のドメインの種類では例外がスローされます。 この制限は、このコンストラクターが Windows Server 2003 で最初に導入された KERB_S4U_LOGON構造体を使用するためです。 また、このコンストラクターには、ターゲット ユーザー アカウントの token-groups-global-and-universal (TGGAU) 属性 への読み取りアクセスが必要です。

適用対象

WindowsIdentity(IntPtr, String)

指定した Windows アカウント トークンと指定した認証の種類によって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type);
public WindowsIdentity (IntPtr userToken, string type);
new System.Security.Principal.WindowsIdentity : nativeint * string -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String)

パラメーター

userToken
IntPtr

nativeint

コードが実行されている対象ユーザーのアカウント トークン。

type
String

(情報使用のみ。) ユーザーを識別するために使用される認証の種類。

例外

userToken が 0 です。

- または -

userToken は、複製され、偽装に対して無効になっています。

呼び出し元に、正しいアクセス許可がありません。

- または -

Win32 エラーが発生しました。

次のコードは、コンストラクターを WindowsIdentity 使用して、指定した Windows アカウント トークンと指定した認証の WindowsIdentity 種類で表されるユーザーの クラスの新しいインスタンスを作成する方法を示しています。 このコード例は、WindowsIdentity クラスのために提供されている大規模な例の一部です。

void IntPtrStringConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token 
   // and the specified authentication type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}
private static void IntPtrStringConstructor(IntPtr logonToken)
{
    // Construct a WindowsIdentity object using the input account token 
    // and the specified authentication type.
    string authenticationType = "WindowsAuthentication";
    WindowsIdentity windowsIdentity =
                    new WindowsIdentity(logonToken, authenticationType);

    Console.WriteLine("Created a Windows identity object named " +
        windowsIdentity.Name + ".");
}
Private Sub IntPtrStringConstructor(ByVal logonToken As IntPtr)
    ' Construct a WindowsIdentity object using the input account token 
    ' and the specified authentication type
    Dim authenticationType = "WindowsAuthentication"
    Dim windowsIdentity As _
        New WindowsIdentity(logonToken, authenticationType)

    WriteLine("Created a Windows identity object named " + _
        windowsIdentity.Name + ".")
End Sub

注釈

のインスタンスの初期プロパティ値を次の WindowsIdentity表に示します。

プロパティ 初期値
WindowsAccountType Normal
IsAuthenticated false

パラメーターの値は type 、 パラメーターの設定 AuthenticationType に使用されます。 が の場合type、セキュリティ システムは nullWindows Vista 以降のバージョンの Windows オペレーティング システムでは に、以前のバージョンの Windows オペレーティング システムでは にKerberos設定AuthenticationTypeNegotiateされます。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

Note

によって表される userToken トークンを取得するには、Windows API LogonUser 関数などのアンマネージ コードを呼び出します。 Windows API CloseHandle 関数を呼び出して、常に解放userTokenします。 アンマネージ コードの呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。

適用対象

WindowsIdentity(SerializationInfo, StreamingContext)

注意事項

This API supports obsolete formatter-based serialization. It should not be called or extended by application code.

SerializationInfo ストリーム内の情報で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
public WindowsIdentity (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
public WindowsIdentity (System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
Public Sub New (info As SerializationInfo, context As StreamingContext)

パラメーター

info
SerializationInfo

ユーザーのアカウント情報を格納するオブジェクト。

context
StreamingContext

ストリーム特性を示すオブジェクト。

属性

例外

WindowsIdentity はプロセス間でシリアル化することはできません。

呼び出し元に、正しいアクセス許可がありません。

- または -

Win32 エラーが発生しました。

注釈

重要

信頼されていないデータを指定してこのメソッドを呼び出すことは、セキュリティ上のリスクが伴います。 このメソッドは信頼されたデータでのみ呼び出してください。 詳細については、「 すべての入力を検証する」を参照してください。

適用対象

WindowsIdentity(String, String)

指定した UPN (User Principal Name) と指定した認証の種類で表されるユーザーを表す WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(System::String ^ sUserPrincipalName, System::String ^ type);
public WindowsIdentity (string sUserPrincipalName, string type);
new System.Security.Principal.WindowsIdentity : string * string -> System.Security.Principal.WindowsIdentity
Public Sub New (sUserPrincipalName As String, type As String)

パラメーター

sUserPrincipalName
String

コードが実行されている対象ユーザーの UPN。

type
String

(情報使用のみ。) ユーザーを識別するために使用される認証の種類。

例外

Windows は、Windows NT ステータス コード STATUS_ACCESS_DENIED を返しました。

使用できるメモリが不足しています。

呼び出し元に、正しいアクセス許可がありません。

- または -

コンピューターは Windows 2003 以降のドメインに接続されていません。

- または -

コンピューターは Windows 2003 以降を実行していません。

- または -

ユーザーは、コンピューターが接続されているドメインのメンバーではありません。

注釈

パラメーターの値は、 type パラメーターの設定 AuthenticationType に使用されます。 が のnull場合type、セキュリティ システムは Windows Vista 以降のバージョンの Windows オペレーティング システムでは に、以前のバージョンの Windows オペレーティング システムでは にKerberos設定AuthenticationTypeNegotiateされます。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

sUserPrincipalName 識別される UPN は、Windows API LsaLogonUser 関数を使用してそのユーザーのトークンを取得するために使用されます。 次に、そのトークンを使用してユーザーを識別します。 指定された UPN を使用してログオンできないため、例外が返される可能性があります。

Note

このコンストラクターは、Windows Server 2003 以降のドメインに参加しているコンピューターでのみ使用することを目的としています。 以前のドメインの種類では例外がスローされます。 この制限は、このコンストラクターが Windows Server 2003 で最初に導入された KERB_S4U_LOGON構造を使用するためです。 また、このコンストラクターには、ターゲット ユーザー アカウント の token-groups-global-and-universal (TGGAU) 属性 への読み取りアクセスが必要です。

適用対象

WindowsIdentity(IntPtr, String, WindowsAccountType)

指定した Windows アカウント トークン、指定した認証の種類、および指定した Windows アカウントの種類によって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type, System::Security::Principal::WindowsAccountType acctType);
public WindowsIdentity (IntPtr userToken, string type, System.Security.Principal.WindowsAccountType acctType);
new System.Security.Principal.WindowsIdentity : nativeint * string * System.Security.Principal.WindowsAccountType -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String, acctType As WindowsAccountType)

パラメーター

userToken
IntPtr

nativeint

コードが実行されている対象ユーザーのアカウント トークン。

type
String

(情報使用のみ。) ユーザーを識別するために使用される認証の種類。

acctType
WindowsAccountType

列挙値の 1 つ。

例外

userToken が 0 です。

- または -

userToken は、複製され、偽装に対して無効になっています。

呼び出し元に、正しいアクセス許可がありません。

- または -

Win32 エラーが発生しました。

次のコードは、コンストラクターを WindowsIdentity 使用して、指定した Windows アカウント トークン、指定した認証の種類、および指定した Windows アカウントの WindowsIdentity 種類で表されるユーザーのクラスの新しいインスタンスを作成する方法を示しています。 このコード例は、WindowsIdentity クラスのために提供されている大規模な例の一部です。

void IntPtrStringTypeConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type and Windows account type.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}
private static void IntPtrStringTypeConstructor(IntPtr logonToken)
{
    // Construct a WindowsIdentity object using the input account token,
    // and the specified authentication type, and Windows account type.
    string authenticationType = "WindowsAuthentication";
    WindowsAccountType guestAccount = WindowsAccountType.Guest;
    WindowsIdentity windowsIdentity =
        new WindowsIdentity(logonToken, authenticationType, guestAccount);

    Console.WriteLine("Created a Windows identity object named " +
        windowsIdentity.Name + ".");
}
Private Sub IntPtrStringTypeConstructor(ByVal logonToken As IntPtr)
    ' Construct a WindowsIdentity object using the input account token,
    ' and the specified authentication type and Windows account type.
    Dim authenticationType As String = "WindowsAuthentication"
    Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
    Dim windowsIdentity As _
        New WindowsIdentity(logonToken, authenticationType, guestAccount)

    WriteLine("Created a Windows identity object named " + _
        windowsIdentity.Name + ".")
End Sub

注釈

のインスタンスの初期プロパティ値を次の WindowsIdentity表に示します。

プロパティ 初期値
IsAuthenticated false

パラメーターの値は、 type パラメーターの設定 AuthenticationType に使用されます。 が のnull場合type、セキュリティ システムは Windows Vista 以降のバージョンの Windows オペレーティング システムでは に、以前のバージョンの Windows オペレーティング システムでは にKerberos設定AuthenticationTypeNegotiateされます。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

Note

によって表される userToken トークンを取得するには、Windows API LogonUser 関数などのアンマネージ コードを呼び出します。 Windows API CloseHandle 関数を呼び出して、常にリリースuserTokenします。 アンマネージド コードの呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。

適用対象

WindowsIdentity(IntPtr, String, WindowsAccountType, Boolean)

指定した Windows アカウント トークン、指定した認証の種類、指定した Windows アカウントの種類、および指定した認証ステータスによって表されるユーザーを表す、WindowsIdentity クラスの新しいインスタンスを初期化します。

public:
 WindowsIdentity(IntPtr userToken, System::String ^ type, System::Security::Principal::WindowsAccountType acctType, bool isAuthenticated);
public WindowsIdentity (IntPtr userToken, string type, System.Security.Principal.WindowsAccountType acctType, bool isAuthenticated);
new System.Security.Principal.WindowsIdentity : nativeint * string * System.Security.Principal.WindowsAccountType * bool -> System.Security.Principal.WindowsIdentity
Public Sub New (userToken As IntPtr, type As String, acctType As WindowsAccountType, isAuthenticated As Boolean)

パラメーター

userToken
IntPtr

nativeint

コードが実行されている対象ユーザーのアカウント トークン。

type
String

(情報使用のみ。) ユーザーを識別するために使用される認証の種類。

acctType
WindowsAccountType

列挙値の 1 つ。

isAuthenticated
Boolean

ユーザーが認証されていることを示す場合は true。それ以外の場合は false

例外

userToken が 0 です。

- または -

userToken は、複製され、偽装に対して無効になっています。

呼び出し元に、正しいアクセス許可がありません。

- または -

Win32 エラーが発生しました。

次のコードは、コンストラクターを WindowsIdentity 使用して、指定した Windows アカウント トークン、指定した認証の種類、指定した Windows アカウントの WindowsIdentity 種類、および指定した認証状態で表されるユーザーのクラスの新しいインスタンスを作成する方法を示しています。 このコード例は、WindowsIdentity クラスのために提供されている大規模な例の一部です。

void IntPrtStringTypeBoolConstructor( IntPtr logonToken )
{
   
   // Construct a WindowsIdentity object using the input account token,
   // and the specified authentication type, Windows account type, and
   // authentication flag.
   String^ authenticationType = "WindowsAuthentication";
   WindowsAccountType guestAccount = WindowsAccountType::Guest;
   bool isAuthenticated = true;
   WindowsIdentity^ windowsIdentity = gcnew WindowsIdentity( logonToken,authenticationType,guestAccount,isAuthenticated );
   
   Console::WriteLine( "Created a Windows identity object named {0}.", windowsIdentity->Name );
}
private static void IntPrtStringTypeBoolConstructor(IntPtr logonToken)
{
    // Construct a WindowsIdentity object using the input account token,
    // and the specified authentication type, Windows account type, and
    // authentication flag.
    string authenticationType = "WindowsAuthentication";
    WindowsAccountType guestAccount = WindowsAccountType.Guest;
    bool isAuthenticated = true;
    WindowsIdentity windowsIdentity = new WindowsIdentity(
        logonToken, authenticationType, guestAccount, isAuthenticated);

    Console.WriteLine("Created a Windows identity object named " +
        windowsIdentity.Name + ".");
}
Private Sub IntPrtStringTypeBoolConstructor(ByVal logonToken As IntPtr)
    ' Construct a WindowsIdentity object using the input account token,
    ' and the specified authentication type, Windows account type, and
    ' authentication flag.
    Dim authenticationType As String = "WindowsAuthentication"
    Dim guestAccount As WindowsAccountType = WindowsAccountType.Guest
    Dim isAuthenticated As Boolean = True
    Dim windowsIdentity As New WindowsIdentity( _
        logonToken, authenticationType, guestAccount, isAuthenticated)

    WriteLine("Created a Windows identity object named " + _
        windowsIdentity.Name + ".")
End Sub

注釈

パラメーターの値は、 type パラメーターの設定 AuthenticationType に使用されます。 が のnull場合type、セキュリティ システムは Windows Vista 以降のバージョンの Windows オペレーティング システムでは に、以前のバージョンの Windows オペレーティング システムでは にKerberos設定AuthenticationTypeNegotiateされます。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

によって表される userToken トークンを取得するには、Windows API LogonUser 関数などのアンマネージ コードを呼び出します。 Windows API CloseHandle 関数を呼び出して、常にリリースuserTokenします。 アンマネージド コードの呼び出しの詳細については、「 アンマネージ DLL 関数の使用」を参照してください。

適用対象