Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > FileSecurity - Test if WindowsIdentity has write access?

Reply
Thread Tools

FileSecurity - Test if WindowsIdentity has write access?

 
 
Ed Sutton
Guest
Posts: n/a
 
      10-10-2006
Is there a FileSecurity method that can determine if the current
WindowsIdentity has write access to a file?

I can get the current windows identity and use FileSecurity to return
the AuthorizationRuleCollection and then search for the
FileSystemAccessRule's that apply to my identity. The problem is my
current identity may be "MYDOMAIN\JDOE", but I do not know how to
determine if a group this identity belongs, for example "EVERYONE",
permits write access for the identity?

Background
----------
I need to test if I my application has read/write access to a file based
database. The database may be running on a client or as a webservice on
a server. I could try to create a new dummy record and hope the
database provider gives me an error or an exception but there must be a
more elegant solution?

Thanks in advance for any tips or suggestions,

-Ed


// This does not work but shows what I wish to achieve
private static bool IdentityHasAccces(FileInfo fileInfo,
FileSystemRights
fileSystemRights)
{
System.Security.Principal.WindowsIdentity windowsIdentity =
System.Security.Principal.WindowsIdentity.GetCurre nt();

FileSecurity fileSecutiy = fileInfo.GetAccessControl();
AuthorizationRuleCollection authorizationRuleCollection =
fileInfo.GetAccessControl().GetAccessRules(true, true, typeof(NTAccount));
foreach (FileSystemAccessRule fileSystemAccessRule in
authorizationRuleCollection)
{
if ( true == (AccessControlType.Allow ==
fileSystemAccessRule.AccessControlType &&
fileSystemRights ==
(fileSystemAccessRule.FileSystemRights & fileSystemRights)))
{
// Test if this FileSystemAccessRule IdentityReference is
one of the Groups the current identity belongs to
foreach(IdentityReference identityReference in
windowsIdentity.Groups)
{
if( identityReference ==
fileSystemAccessRule.IdentityReference)
{
return true;
}
}
}
}
return false;
}
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
NullUser and WindowsIdentity (ImpersonateAnonymousToken) has no groups Eric Pearson ASP .Net 2 05-30-2006 06:18 PM
NullUser and WindowsIdentity (ImpersonateAnonymousToken) has no groups Eric Pearson ASP .Net Security 0 05-30-2006 12:49 PM
Win32::FileSecurity doesn't show all perms? perl coder Perl Misc 1 04-02-2004 05:12 AM
WindowsPrincipal and WindowsIdentity. Kevin Burton ASP .Net 1 01-08-2004 01:20 AM
test test test test test test test Computer Support 2 07-02-2003 06:02 PM



Advertisments