コード例 #1
0
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     _token = (IntPtr)_info.GetValue("m_userToken", typeof(IntPtr));
     // can't trust this alone - we must validate the token
     _name = _info.GetString("m_name");
     if (_name != null)
     {
         // validate token by comparing names
         string name = GetTokenName(_token);
         if (name != _name)
         {
             throw new SerializationException("Token-Name mismatch.");
         }
     }
     else
     {
         // validate token by getting name
         _name = GetTokenName(_token);
         if (_name == null)
         {
             throw new SerializationException("Token doesn't match a user.");
         }
     }
     _type          = _info.GetString("m_type");
     _account       = (WindowsAccountType)_info.GetValue("m_acctType", typeof(WindowsAccountType));
     _authenticated = _info.GetBoolean("m_isAuthenticated");
 }
コード例 #2
0
        private void SetToken(IntPtr token)
        {
            if (Environment.IsUnix)
            {
                _token = token;
                // apply defaults
                if (_type == null)
                {
                    _type = "POSIX";
                }
                // override user choice in this specific case
                if (_token == IntPtr.Zero)
                {
                    _account = WindowsAccountType.System;
                }
            }
            else
            {
                if ((token == invalidWindows) && (_account != WindowsAccountType.Anonymous))
                {
                    throw new ArgumentException("Invalid token");
                }

                _token = token;
                // apply defaults
                if (_type == null)
                {
                    _type = "NTLM";
                }
            }
        }
コード例 #3
0
 private void SetToken(IntPtr token)
 {
     if (WindowsIdentity.IsPosix)
     {
         this._token = token;
         if (this._type == null)
         {
             this._type = "POSIX";
         }
         if (this._token == IntPtr.Zero)
         {
             this._account = WindowsAccountType.System;
         }
     }
     else
     {
         if (token == WindowsIdentity.invalidWindows && this._account != WindowsAccountType.Anonymous)
         {
             throw new ArgumentException("Invalid token");
         }
         this._token = token;
         if (this._type == null)
         {
             this._type = "NTLM";
         }
     }
 }
コード例 #4
0
	public WindowsIdentity(IntPtr userToken, String type)
			{
				this.userToken = userToken;
				this.name = String.Empty;
				this.type = type;
				this.acctType = WindowsAccountType.Normal;
				this.isAuthenticated = false;
			}
コード例 #5
0
 public WindowsIdentity(IntPtr userToken, String type)
 {
     this.userToken       = userToken;
     this.name            = String.Empty;
     this.type            = type;
     this.acctType        = WindowsAccountType.Normal;
     this.isAuthenticated = false;
 }
コード例 #6
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Security.Principal.WindowsIdentity" /> class for the user represented by the specified Windows account token, the specified authentication type, the specified Windows account type, and the specified authentication status.</summary>
 /// <param name="userToken">The account token for the user on whose behalf the code is running. </param>
 /// <param name="type">(Informational) The type of authentication used to identify the user. For more information, see Remarks.</param>
 /// <param name="acctType">One of the <see cref="T:System.Security.Principal.WindowsAccountType" /> values. </param>
 /// <param name="isAuthenticated">true to indicate that the user is authenticated; otherwise, false. </param>
 /// <exception cref="T:System.ArgumentException">
 ///   <paramref name="userToken" /> is 0.-or-<paramref name="userToken" /> is duplicated and invalid for impersonation.</exception>
 /// <exception cref="T:System.Security.SecurityException">The caller does not have the correct permissions. -or-A Win32 error occurred.</exception>
 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     this._type          = type;
     this._account       = acctType;
     this._authenticated = isAuthenticated;
     this._name          = null;
     this.SetToken(userToken);
 }
コード例 #7
0
 public WindowsIdentity(String sUserPrincipalName, String type)
 {
     this.userToken       = IntPtr.Zero;
     this.name            = sUserPrincipalName;
     this.type            = type;
     this.acctType        = WindowsAccountType.Normal;
     this.isAuthenticated = false;
 }
コード例 #8
0
 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     _type          = type;
     _account       = acctType;
     _authenticated = isAuthenticated;
     _name          = null;
     // last - as it can override some fields
     SetToken(userToken);
 }
コード例 #9
0
ファイル: WindowsIdentity.cs プロジェクト: nlhepler/mono
		public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
		{
			_type = type;
			_account = acctType;
			_authenticated = isAuthenticated;
			_name = null;
			// last - as it can override some fields
			SetToken (userToken);
		}
コード例 #10
0
	public WindowsIdentity(IntPtr userToken, String type,
						   WindowsAccountType acctType,
						   bool isAuthenticated)
			{
				this.userToken = userToken;
				this.name = String.Empty;
				this.type = type;
				this.acctType = acctType;
				this.isAuthenticated = isAuthenticated;
			}
コード例 #11
0
 public WindowsIdentity(IntPtr userToken, String type,
                        WindowsAccountType acctType,
                        bool isAuthenticated)
 {
     this.userToken       = userToken;
     this.name            = String.Empty;
     this.type            = type;
     this.acctType        = acctType;
     this.isAuthenticated = isAuthenticated;
 }
コード例 #12
0
    //</Snippet4>

    // Create a WindowsIdentity object for the user represented by the
    // specified account token, authentication type, and Windows account
    // type.
    //<Snippet7>
    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 + ".");
    }
コード例 #13
0
        public WindowsIdentity(String sUserPrincipalName)
        {
            IntPtr userToken = _S4ULogon(sUserPrincipalName);

            if (userToken == ZeroHandle)
            {
                throw new ArgumentException(Environment.GetResourceString("Argument_UnableToLogOn"));
            }
            CreateFromToken(userToken, "NTLM", true);
            m_acctType        = WindowsAccountType.Normal;
            m_isAuthenticated = false;
        }
コード例 #14
0
 public WindowsIdentity(SerializationInfo info, StreamingContext context)
 {
     if (info == null)
     {
         throw new ArgumentNullException("info");
     }
     userToken = (IntPtr)(info.GetValue
                              ("m_userToken", typeof(IntPtr)));
     name     = info.GetString("m_name");
     type     = info.GetString("m_type");
     acctType = (WindowsAccountType)(info.GetValue
                                         ("m_acctType", typeof(WindowsAccountType)));
     isAuthenticated = info.GetBoolean("m_isAuthenticated");
 }
コード例 #15
0
        private static WindowsImpersonationContext Impersonate(IntPtr userToken, WindowsAccountType acctType)
        {
            // We grab the current user token and save it so we can revert to it later.

            WindowsImpersonationContext context = null;

            if (acctType == WindowsAccountType.Anonymous)
            {
                throw new InvalidOperationException(Environment.GetResourceString("InvalidOperation_AnonymousCannotImpersonate"));
            }

            IntPtr token = _GetCurrentToken();

            try
            {
                if (token != ZeroHandle)
                {
                    context = new WindowsImpersonationContext(token);
                }
                else
                {
                    context = WindowsImpersonationContext.FromSystem;
                }
            }
            finally
            {
                if (token != ZeroHandle)
                {
                    _CloseHandle(token);
                }
            }

            if (userToken == ZeroHandle)
            {
                if (!_RevertToSelf())
                {
                    throw new SecurityException(Environment.GetResourceString("Argument_ImpersonateSystem"));
                }
            }
            else
            {
                if (!_ImpersonateLoggedOnUser(userToken))
                {
                    throw new SecurityException(Environment.GetResourceString("Argument_ImpersonateUser"));
                }
            }

            return(context);
        }
コード例 #16
0
 private WindowsIdentity(bool isWin9X)
 {
     if (isWin9X)
     {
         // Create a junk identity
         m_acctType = WindowsAccountType.System;
     }
     else
     {
         // Create an anonymous identity
         m_acctType = WindowsAccountType.Anonymous;
     }
     m_name            = "";
     m_type            = "";
     m_userToken       = ZeroHandle;
     m_isAuthenticated = false;
 }
コード例 #17
0
        /// <summary>Initializes a new instance of the <see cref="T:System.Security.Principal.WindowsIdentity" /> class for the user represented by the specified User Principal Name (UPN) and the specified authentication type.</summary>
        /// <param name="sUserPrincipalName">The UPN for the user on whose behalf the code is running. </param>
        /// <param name="type">(Informational) The type of authentication used to identify the user. </param>
        /// <exception cref="T:System.UnauthorizedAccessException">Windows returned the Windows NT status code STATUS_ACCESS_DENIED.</exception>
        /// <exception cref="T:System.OutOfMemoryException">There is insufficient memory available.</exception>
        /// <exception cref="T:System.Security.SecurityException">The caller does not have the correct permissions. </exception>
        public WindowsIdentity(string sUserPrincipalName, string type)
        {
            if (sUserPrincipalName == null)
            {
                throw new NullReferenceException("sUserPrincipalName");
            }
            IntPtr userToken = WindowsIdentity.GetUserToken(sUserPrincipalName);

            if (!WindowsIdentity.IsPosix && userToken == IntPtr.Zero)
            {
                throw new ArgumentException("only for Windows Server 2003 +");
            }
            this._authenticated = true;
            this._account       = WindowsAccountType.Normal;
            this._type          = type;
            this.SetToken(userToken);
        }
コード例 #18
0
        public WindowsIdentity(string sUserPrincipalName, string type)
        {
            if (sUserPrincipalName == null)
            {
                throw new NullReferenceException("sUserPrincipalName");
            }

            // TODO: Windows 2003 compatibility should be done in runtime
            IntPtr token = GetUserToken(sUserPrincipalName);

            if ((!Environment.IsUnix) && (token == IntPtr.Zero))
            {
                throw new ArgumentException("only for Windows Server 2003 +");
            }

            _authenticated = true;
            _account       = WindowsAccountType.Normal;
            _type          = type;
            // last - as it can override some fields
            SetToken(token);
        }
コード例 #19
0
        public WindowsIdentity(SerializationInfo info, StreamingContext context)
        {
            m_userToken       = (IntPtr)info.GetValue("m_userToken", typeof(IntPtr));
            m_name            = (String)info.GetValue("m_name", typeof(String));
            m_type            = (String)info.GetValue("m_type", typeof(String));
            m_acctType        = (WindowsAccountType)info.GetValue("m_acctType", typeof(WindowsAccountType));
            m_isAuthenticated = (bool)info.GetValue("m_isAuthenticated", typeof(bool));

            if (m_userToken != ZeroHandle)
            {
                if (m_name == null)
                {
                    ResolveIdentity();
                }
                else if (!m_name.Equals(_ResolveIdentity(m_userToken)))
                {
                    throw new NotSupportedException(Environment.GetResourceString("NotSupported_CrossProcessWindowsIdentitySerialization"));
                }

                CreateFromToken(m_userToken, m_type, false);
            }
        }
コード例 #20
0
 /// <summary>Implements the <see cref="T:System.Runtime.Serialization.ISerializable" /> interface and is called back by the deserialization event when deserialization is complete.</summary>
 /// <param name="sender">The source of the deserialization event. </param>
 void IDeserializationCallback.OnDeserialization(object sender)
 {
     this._token = (IntPtr)this._info.GetValue("m_userToken", typeof(IntPtr));
     this._name  = this._info.GetString("m_name");
     if (this._name != null)
     {
         string tokenName = WindowsIdentity.GetTokenName(this._token);
         if (tokenName != this._name)
         {
             throw new SerializationException("Token-Name mismatch.");
         }
     }
     else
     {
         this._name = WindowsIdentity.GetTokenName(this._token);
         if (this._name == string.Empty || this._name == null)
         {
             throw new SerializationException("Token doesn't match a user.");
         }
     }
     this._type          = this._info.GetString("m_type");
     this._account       = (WindowsAccountType)((int)this._info.GetValue("m_acctType", typeof(WindowsAccountType)));
     this._authenticated = this._info.GetBoolean("m_isAuthenticated");
 }
コード例 #21
0
	public WindowsIdentity(String sUserPrincipalName, String type)
			{
				this.userToken = IntPtr.Zero;
				this.name = sUserPrincipalName;
				this.type = type;
				this.acctType = WindowsAccountType.Normal;
				this.isAuthenticated = false;
			}
コード例 #22
0
	public WindowsIdentity(SerializationInfo info, StreamingContext context)
			{
				if(info == null)
				{
					throw new ArgumentNullException("info");
				}
				userToken = (IntPtr)(info.GetValue
					("m_userToken", typeof(IntPtr)));
				name = info.GetString("m_name");
				type = info.GetString("m_type");
				acctType = (WindowsAccountType)(info.GetValue
					("m_acctType", typeof(WindowsAccountType)));
				isAuthenticated = info.GetBoolean("m_isAuthenticated");
			}
コード例 #23
0
 public WindowsIdentityEx(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     this.Init();
     _windowsIdentity = new WindowsIdentity(userToken, type, acctType, isAuthenticated);
 }
コード例 #24
0
 private WindowsIdentity(IntPtr userToken, WindowsAccountType type, bool isAuthenticated)
 {
     m_isAuthenticated = isAuthenticated;
     m_acctType        = type;
     CreateFromToken(userToken, "NTLM", true);
 }
コード例 #25
0
 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated) : this(userToken, type, isAuthenticated ? 1 : 0)
 {
 }
コード例 #26
0
ファイル: WindowsIdentity.cs プロジェクト: nlhepler/mono
		private void SetToken (IntPtr token) 
		{
			if (Environment.IsUnix) {

				_token = token;
				// apply defaults
				if (_type == null)
					_type = "POSIX";
				// override user choice in this specific case
				if (_token == IntPtr.Zero)
					_account = WindowsAccountType.System;
			}
			else {
				if ((token == invalidWindows) && (_account != WindowsAccountType.Anonymous))
					throw new ArgumentException ("Invalid token");

				_token = token;
				// apply defaults
				if (_type == null)
					_type = "NTLM";
			}
		}
コード例 #27
0
ファイル: WindowsIdentity.cs プロジェクト: PlumpMath/CIL2Java
 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     throw new NotImplementedException();
 }
コード例 #28
0
 public WindowsIdentity(System.IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
 }
コード例 #29
0
ファイル: HttpRequest.cs プロジェクト: Alister742/ParseKit
 private static WindowsIdentity CreateWindowsIdentityWithAssert(IntPtr token, string authType, WindowsAccountType accountType, bool isAuthenticated)
 {
     return new WindowsIdentity(token, authType, accountType, isAuthenticated);
 }
コード例 #30
0
 private WindowsIdentity CreateWindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     return new WindowsIdentity(userToken, type, acctType, isAuthenticated);
 }
コード例 #31
0
 public WindowsIdentity(IntPtr userToken, String type, WindowsAccountType acctType, bool isAuthenticated)
 {
     CreateFromToken(userToken, type, false);
     m_acctType        = acctType;
     m_isAuthenticated = isAuthenticated;
 }
コード例 #32
0
 public WindowsIdentity(IntPtr userToken, string type, WindowsAccountType acctType)
     : this(userToken, type, acctType, false)
 {
 }
コード例 #33
0

        
コード例 #34
0
 public WindowsIdentity(System.IntPtr userToken, string type, WindowsAccountType acctType)
 {
 }
コード例 #35
0

        
コード例 #36
0
ファイル: WindowsIdentity.cs プロジェクト: nlhepler/mono
		void IDeserializationCallback.OnDeserialization (object sender)
		{
			_token = (IntPtr) _info.GetValue ("m_userToken", typeof (IntPtr));
			// can't trust this alone - we must validate the token
			_name = _info.GetString ("m_name");
			if (_name != null) {
				// validate token by comparing names
				string name = GetTokenName (_token);
				if (name != _name)
					throw new SerializationException ("Token-Name mismatch.");
			}
			else {
				// validate token by getting name
				_name = GetTokenName (_token);
				if (_name == null)
					throw new SerializationException ("Token doesn't match a user.");
			}
			_type = _info.GetString ("m_type");
			_account = (WindowsAccountType) _info.GetValue ("m_acctType", typeof (WindowsAccountType));
			_authenticated = _info.GetBoolean ("m_isAuthenticated");
		}
コード例 #37
0
ファイル: WorkerRequest.cs プロジェクト: dox0/DotNet471RS3
 private static WindowsIdentity CreateWindowsIdentityWithAssert(IntPtr token, string authType, WindowsAccountType accountType, bool isAuthenticated)
 {
     return(new WindowsIdentity(token, authType, accountType, isAuthenticated));
 }
コード例 #38
0
ファイル: WindowsIdentity.cs プロジェクト: nlhepler/mono
		public WindowsIdentity (IntPtr userToken, string type, WindowsAccountType acctType)
			: this (userToken, type, acctType, false)
		{
		}
コード例 #39
0
 public WindowsIdentityEx(IntPtr userToken, string type, WindowsAccountType acctType)
 {
     this.Init();
     _windowsIdentity = new WindowsIdentity(userToken, type, acctType);
 }
コード例 #40
0
ファイル: WindowsIdentity.cs プロジェクト: nlhepler/mono
		public WindowsIdentity (string sUserPrincipalName, string type)
		{
			if (sUserPrincipalName == null)
				throw new NullReferenceException ("sUserPrincipalName");

			// TODO: Windows 2003 compatibility should be done in runtime
			IntPtr token = GetUserToken (sUserPrincipalName);
			if ((!Environment.IsUnix) && (token == IntPtr.Zero)) {
				throw new ArgumentException ("only for Windows Server 2003 +");
			}

			_authenticated = true;
			_account = WindowsAccountType.Normal;
			_type = type;
			// last - as it can override some fields
			SetToken (token);
		}
コード例 #41
0
 public WindowsIdentity(IntPtr userToken)
 {
     CreateFromToken(userToken, "NTLM", false);
     m_acctType        = WindowsAccountType.Normal;
     m_isAuthenticated = false;
 }