WindowsIdentity コンストラクター

定義

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

オーバーロード

名前 説明
WindowsIdentity(IntPtr)

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

WindowsIdentity(WindowsIdentity)

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

WindowsIdentity(String)

指定したユーザー プリンシパル名 (UPN) で表されるユーザーの WindowsIdentity クラスの新しいインスタンスを初期化します。

WindowsIdentity(IntPtr, String)

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

WindowsIdentity(SerializationInfo, StreamingContext)
古い.

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

WindowsIdentity(String, String)

指定したユーザー プリンシパル名 (UPN) と指定した認証の種類で表されるユーザーの 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

Windows API LogonUser関数などのアンマネージ コードを呼び出すことで、userTokenによって表されるトークンを取得できます。 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) で表されるユーザーの 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 には、 ユーザー名@ドメイン名.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 パラメーターの設定に使用されます。 typenullされている場合、セキュリティ システムは、Windows Vista 以降のバージョンの Windows オペレーティング システムでNegotiateし、以前のバージョンの Windows オペレーティング システムでKerberosするようにAuthenticationTypeを設定します。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

Note

Windows API LogonUser関数などのアンマネージ コードを呼び出すことで、userTokenによって表されるトークンを取得できます。 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);
[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);
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}")>]
new System.Security.Principal.WindowsIdentity : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.Security.Principal.WindowsIdentity
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 エラーが発生しました。

注釈

Important

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

適用対象

WindowsIdentity(String, String)

指定したユーザー プリンシパル名 (UPN) と指定した認証の種類で表されるユーザーの 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 パラメーターの設定に使用されます。 typenullされている場合、セキュリティ システムは、Windows Vista 以降のバージョンの Windows オペレーティング システムでNegotiateし、以前のバージョンの Windows オペレーティング システムでKerberosするようにAuthenticationTypeを設定します。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

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 パラメーターの設定に使用されます。 typenullされている場合、セキュリティ システムは、Windows Vista 以降のバージョンの Windows オペレーティング システムでNegotiateし、以前のバージョンの Windows オペレーティング システムでKerberosするようにAuthenticationTypeを設定します。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

Note

Windows API LogonUser関数などのアンマネージ コードを呼び出すことで、userTokenによって表されるトークンを取得できます。 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 パラメーターの設定に使用されます。 typenullされている場合、セキュリティ システムは、Windows Vista 以降のバージョンの Windows オペレーティング システムでNegotiateし、以前のバージョンの Windows オペレーティング システムでKerberosするようにAuthenticationTypeを設定します。 セキュリティ システムでは、この値は使用されません。これは情報提供のみを目的としています。

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

適用対象