473,405 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

FileSecurity - Test if WindowsIdentity has write access?

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;
}
Oct 10 '06 #1
0 1369

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Phillips | last post by:
I periodically get an ApplicationException "access is denied" in the WindowsIdentity._GetCurrentToken() method. Reflector shows the _GetCurrentToken() method as private static extern IntPtr...
3
by: Kevin Burton | last post by:
This is more of a solution that raised a question. I have a Web service that does not allow anonymous users. For debugging I put in the following lines in my Web Service: WindowsIdentity wi =...
8
by: Razak | last post by:
Hi, I have a class which basically do Impersonation in my web application. From MS KB sample:- ++++++++++++++++++++code starts Dim impersonationContext As...
13
by: ALI-R | last post by:
I know how to authenticate to a webservice using either of these ways(Assuming that rService represents the webservice): 1) rService.Credentials = new...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.