Dev2.FileIO.CheckPermissions C# (CSharp) Method

CheckPermissions() public static method

Checks the permissions.
Failed to authenticate with user [ + userAndDomain + ] for resource [ + path + ]
public static CheckPermissions ( string userAndDomain, string pass, string path, FileSystemRights rights ) : bool
userAndDomain string The user and domain.
pass string The pass.
path string The path.
rights FileSystemRights The rights.
return bool
        public static bool CheckPermissions(string userAndDomain, string pass, string path, FileSystemRights rights)
        {
            bool result;

            // handle UNC path
            try
            {
                string user = ExtractUserName(userAndDomain);
                string domain = ExtractDomain(userAndDomain);
                SafeTokenHandle safeTokenHandle;
                bool loginOk = LogonUser(user, domain, pass, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT,
                    out safeTokenHandle);


                if (loginOk)
                {
                    using (safeTokenHandle)
                    {
                        var newID = new WindowsIdentity(safeTokenHandle.DangerousGetHandle());
                        using (WindowsImpersonationContext impersonatedUser = newID.Impersonate())
                        {
                            // Do the operation here
                            result = CheckPermissions(newID, path, rights);

                            impersonatedUser.Undo(); // remove impersonation now
                        }
                    }
                }
                else
                {
                    // login failed
                    throw new Exception("Failed to authenticate with user [ " + userAndDomain + " ] for resource [ " +
                                        path + " ] ");
                }
            }
            catch (Exception ex)
            {
                Dev2Logger.Log.Error("FileIO", ex);
                throw;
            }
            return result;
        }

Same methods

FileIO::CheckPermissions ( System.Security.Principal.WindowsIdentity user, string path, FileSystemRights expectedRights ) : bool