Permission informaiton
Windows Server Forum Index Windows Server
Server discussion on Windows platform.
 
 FAQFAQ   MemberlistMemberlist     RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 
Google
 
Web winserverhelp.com
Permission informaiton

 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development
Author Message
Anders K. Olsen
Guest





Posted: Thu Nov 03, 2005 1:51 pm    Post subject: Permission informaiton Reply with quote

Hello Group

I'm trying to make sense of the Sharepoint (WSS and SPS) security
information. Basically I'm trying to do two things:

1) For each file (SPFile): Which users/groups/roles may read this file?
2) For the current user: Which roles does this user belong to?

I then want to compare the two informations to see if a user may read a
file. I know that SPS/WSS can do this for me, but the matching has to take
place in an external application that can not talk to sharepoint, so I need
to collect enough information to be able to do the comparison.

I have tried to get the information using both a Windows Forms application
and a Web application.

Using the Windows Application, I'm able to list which SPMembers may read
files in a Document Library containing the file. But when I try to get
permission information about the SPFile.ParentFolder.ParentWeb, I get a
System.UnauthorizedAccessException. Does anybody know why?

My code is here:
---
SPWeb pw = selectedFile.ParentFolder.ParentWeb;
SPPermissionCollection perms = null;

perms = pw.Permissions;
foreach (SPPermission perm in perms)
{
txtContent.Text += "Member: " + perm.Member + ", Read access: "
+((perm.PermissionMask & SPRights.ViewListItems) != SPRights.EmptyMask) +
"\r\n";
}

if (selectedFile.InDocumentLibrary)
{
txtContent.Text += "\r\nDocLib
permissions:\r\n----------------------\r\n";

Guid doclib = selectedFile.ParentFolder.ContainingDocumentLibrary;
SPList list = pw.Lists[doclib];
perms = list.Permissions;
foreach (SPPermission perm in perms)
{
txtContent.Text += "Member: " + perm.Member + ", Read access: "
+((perm.PermissionMask & SPRights.ViewListItems) != SPRights.EmptyMask) +
"\r\n";
}
}
---
The first part where I try to list pw.Permissions is the one that fails. The
second part runs just fine.

Second problem:
I try to find out which Roles a user is a member of. I use this method:
----
private void DumpUserInfoWeb(SPWeb web)
{
SPUser cuser = web.CurrentUser;
txtContent.Text += "\r\n-------------------\r\n";
txtContent.Text += "Web: " + web.Name + "\r\n";
txtContent.Text += "Name: " + cuser.Name + "\r\n";
txtContent.Text += "User is admin: " + cuser.IsSiteAdmin + "\r\n";
txtContent.Text += "User XML: " + cuser.Xml + "\r\n";
txtContent.Text += "Group memberships: " + cuser.Groups.Count + "\r\n";
txtContent.Text += "Role memberships: " + cuser.Roles.Count + "\r\n";
SPGroupCollection ugroups = cuser.Groups;
foreach (SPGroup group in ugroups)
{
txtContent.Text += "Group name: " + group.Name + "\r\n";
txtContent.Text += "Group XML: " + group.Xml + "\r\n";
}
foreach (SPRole role in cuser.Roles)
{
txtContent.Text += "Role name: " + role.Name + "\r\n";
txtContent.Text += "Role XML: " + role.Xml + "\r\n";
}
}
----
If I call this method with:

siteCollection = new SPSite(<server>);
DumpUserInfoWeb(siteCollection.RootWeb)

everything works just fine. But if I then try to call it repeatedly for each
web in siteCollection.AllWebs, it fails in the SPRole foreach loop. Again
with a System.UnauthorizedAccessException: Access Denied. Anybody know why?

I hope you can help me to solve my problem.

Is there any good documentation where I can read more about users and file
security?

Regards
Anders
Back to top
 
Post new topic   Reply to topic    Windows Server Forum Index -> Portal Server Development All times are GMT
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum




New Topics Powered by phpBB