473,782 Members | 2,505 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 AuthorizationRu leCollection and then search for the
FileSystemAcces sRule'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 IdentityHasAccc es(FileInfo fileInfo,
FileSystemRight s
fileSystemRight s)
{
System.Security .Principal.Wind owsIdentity windowsIdentity =
System.Security .Principal.Wind owsIdentity.Get Current();

FileSecurity fileSecutiy = fileInfo.GetAcc essControl();
AuthorizationRu leCollection authorizationRu leCollection =
fileInfo.GetAcc essControl().Ge tAccessRules(tr ue, true, typeof(NTAccoun t));
foreach (FileSystemAcce ssRule fileSystemAcces sRule in
authorizationRu leCollection)
{
if ( true == (AccessControlT ype.Allow ==
fileSystemAcces sRule.AccessCon trolType &&
fileSystemRight s ==
(fileSystemAcce ssRule.FileSyst emRights & fileSystemRight s)))
{
// Test if this FileSystemAcces sRule IdentityReferen ce is
one of the Groups the current identity belongs to
foreach(Identit yReference identityReferen ce in
windowsIdentity .Groups)
{
if( identityReferen ce ==
fileSystemAcces sRule.IdentityR eference)
{
return true;
}
}
}
}
return false;
}
Oct 10 '06 #1
0 1396

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

Similar topics

0
1414
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 _GetCurrentToken(); which i believe means it is an internal call into the CLR.Does anyone have any thoughts on why this would be happening?
3
4300
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 = WindowsIdentity.GetCurrent(); WindowsPrincipal wp = Thread.CurrentPrincipal as WindowsPrincipal; wi = wp.Identity as WindowsIdentity;
8
9469
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 System.Security.Principal.WindowsImpersonationContext Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity
13
12961
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 System.Net.NetworkCredential("username","password","domainName"); 2)rService.Credentials = System.Net.CredentialCache.DefaultCredentials; My question is that is there a way to authenticate to a user using WindowsIdentity ???
0
9479
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10311
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10146
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8967
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7492
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5378
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4043
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3639
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2874
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.