none
Adding FBA Roles to SharePoint Groups and ListItem Permissions programmatically RRS feed

  • Question

  • I need to add an Role from my FBA database to sharepoint programatically. Also I need to Add that Role as to the permissions of an item in a list or library.

    Can anyone provide me a code snippet to do this?

    • Edited by Mike Walsh FIN Friday, May 8, 2009 1:36 PM " programmatically" added to Title so it fits this forum
    Thursday, March 19, 2009 2:01 PM

Answers

  • Mike,

    I meant to get back to this just got busy with the project. My appologies to everyone, as Mike is entirely correct in his point.

    A brief history of the issue:

    I needed to be able to create users based on a series of properties that are selected by content managers when they are adding or editing content in a document library. These properties represent Attributes on users in a CRM System (Parent Account, Account, Account Types and Account Roles).

    I extended the aspnetdb to include tables for a Rules Engine that maps these rules to a particular Business Rule (aka Role aka Security Group). Then I wrote a custom Membership and Role Provider over that database.

    To Add a new user to SharePoint I use the following code in a SPListItemEventReceiver:

    properites.OpenWeb().SiteUsers.Add(string.Format("{0}:{1}", "mxlroleprovider", rolename), null, string.Format("{0}:{1}", "mxlroleprovider", rolename), "System generated permission rule");

    This will add the Role to SharePoint.


    To Assign the permissions to a list object

    SPRoleAssignment user_assignment = new SPRoleAssignment(SPUserThatYouJustAdded);
                                user_assignment.RoleDefinitionBindings.Add(item.Web.RoleDefinitions["Read"]); // Or any other permission you want.
                                item.RoleAssignments.Add(user_assignment);
    Friday, June 5, 2009 6:44 PM

All replies

  • I figured it out.
    • Marked as answer by Arc Andersen Monday, March 23, 2009 3:19 PM
    • Unmarked as answer by Mike Walsh FIN Friday, May 8, 2009 1:36 PM
    Monday, March 23, 2009 3:18 PM
  • hi Arc Andersen,
       Please let us know how you achieved it, beacuse we are able to get FBA users but lacking with their roles as MOSS groups

    Thanks in advance

    Friday, May 8, 2009 9:52 AM
  • > I figured it out.

    Never just write this.

    Just as you expect that people spend their time trying to help you, we expect you to spend a little bit of your time giving us the solution if you have it. Google/Live searchers really hate threads where the question matches their problem and the answer is "I figured it out".
    WSS FAQ sites: http://wssv2faq.mindsharp.com and http://wssv3faq.mindsharp.com
    Total list of WSS 3.0 / MOSS 2007 Books (including foreign language) http://wssv3faq.mindsharp.com/Lists/v3%20WSS%20FAQ/V%20Books.aspx
    Friday, May 8, 2009 1:38 PM
  • Mike,

    I meant to get back to this just got busy with the project. My appologies to everyone, as Mike is entirely correct in his point.

    A brief history of the issue:

    I needed to be able to create users based on a series of properties that are selected by content managers when they are adding or editing content in a document library. These properties represent Attributes on users in a CRM System (Parent Account, Account, Account Types and Account Roles).

    I extended the aspnetdb to include tables for a Rules Engine that maps these rules to a particular Business Rule (aka Role aka Security Group). Then I wrote a custom Membership and Role Provider over that database.

    To Add a new user to SharePoint I use the following code in a SPListItemEventReceiver:

    properites.OpenWeb().SiteUsers.Add(string.Format("{0}:{1}", "mxlroleprovider", rolename), null, string.Format("{0}:{1}", "mxlroleprovider", rolename), "System generated permission rule");

    This will add the Role to SharePoint.


    To Assign the permissions to a list object

    SPRoleAssignment user_assignment = new SPRoleAssignment(SPUserThatYouJustAdded);
                                user_assignment.RoleDefinitionBindings.Add(item.Web.RoleDefinitions["Read"]); // Or any other permission you want.
                                item.RoleAssignments.Add(user_assignment);
    Friday, June 5, 2009 6:44 PM