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

                _token = token;
                // apply defaults
                if (_type == null)
                {
                    _type = "NTLM";
                }
            }
        }
        internal static string[] _GetRoles(Token token)
        {
            var listRoles = new List <string> ();
            var level     = token.Access;

            if (level >= CA.Authentication.UserAuthenticationLevelEnum.Connect)
            {
                listRoles.Add("Connect");
                if (level >= CA.Authentication.UserAuthenticationLevelEnum.User)
                {
                    listRoles.Add("User");
                    if (level >= CA.Authentication.UserAuthenticationLevelEnum.Operator)
                    {
                        listRoles.Add("Operator");
                        if (level >= CA.Authentication.UserAuthenticationLevelEnum.Programmer)
                        {
                            listRoles.Add("Programmer");
                            if (level >= CA.Authentication.UserAuthenticationLevelEnum.Administrator)
                            {
                                listRoles.Add("Administrator");
                            }
                        }
                    }
                }
            }

            return(listRoles.ToArray());
        }
 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");
 }
 public WindowsIdentity(Token userToken, string type, WindowsAccountType acctType, bool isAuthenticated)
 {
     _type          = type;
     _account       = acctType;
     _authenticated = isAuthenticated;
     _name          = null;
     // last - as it can override some fields
     SetToken(userToken);
 }
        protected virtual void Dispose(bool disposing)
        {
#if SSHARP
            if (_token != default(Token))
            {
                CA.Authentication.ReleaseAuthenticationToken(_token);
            }
#endif
            _token = default(Token);
        }
        public void Dispose()
        {
#if SSHARP
            if (_token != default(Token))
            {
                CA.Authentication.ReleaseAuthenticationToken(_token);
            }
#endif
            _token = default(Token);
        }
        public WindowsIdentity(string sUserPrincipalName, string type)
        {
            if (sUserPrincipalName == null)
            {
                throw new NullReferenceException("sUserPrincipalName");
            }

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

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

            _authenticated = true;
            _account       = WindowsAccountType.Normal;
            _type          = type;
            // last - as it can override some fields
            SetToken(token);
        }
 public WindowsIdentity(Token userToken, string type, WindowsAccountType acctType)
     : this(userToken, type, acctType, false)
 {
 }
 public WindowsIdentity(Token userToken)
     : this(userToken, null, WindowsAccountType.Normal, false)
 {
 }
 public static WindowsImpersonationContext Impersonate(Token userToken)
 {
     return(new WindowsImpersonationContext(userToken));
 }