Secure Dynamic Data Site

Last post 07-15-2009 2:11 PM by sjnaughton. 15 replies.

Sort Posts:

  • Secure Dynamic Data Site

    11-05-2008, 2:55 PM
    • Member
      175 point Member
    • veloce
    • Member since 12-16-2002, 3:21 PM
    • Seattle
    • Posts 46
    An example of a Secure Dynamic Data Site is available on the Dynamic Data samples page on CodePlex: http://www.codeplex.com/aspnet/Release/ProjectReleases.aspx?ReleaseId=14473.The Secure Dynamic Data Site allows or denies user's access to the database tables based on the user's authenticated role. Furthermore, it allows or denies user's table actions based on the user's authorization.The site integrates the ASP.NET forms authentication with a new concept of authorization provided by Dynamic Data.

    To achieve these objectives the Web site uses the following security mechanisms:

    ·         Authentication (forms authentication) performed by ASP.NET. It provides the first security level, which enables you to allow or deny access to a table to authenticated users in function of their role.

    ·         Authorization performed by Dynamic Data. It provides the second security level which enables you to allow or deny access to tables and specific actions on the tables as specified by the SecurityAttribute properties in the data model. The roles used in the attribute must be the same role used by ASP.NET authentication.

    Note   Only the tables flagged with SecurtyAttribute are displayed in a scaffolded site.

    The site uses scaffolding, which is enabled. It also uses a SQL-Express database for both AdventureWorksLT and Aspnetdb (security database).

    You can move the information to a complete SQL database. For more information, see Deploying a SQL Database to a Remote Hosting Environment.

     

    Please, play with this example and have fun as I did.Cool

    More can be done. I would like to hear from you.Thanks,Michael   
    This posting is provided "AS IS" with no warranties, and confers no rights.


    I blog at: Technical Notes

  • Re: Secure Dynamic Data Site

    11-07-2008, 6:33 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

    Hi Veloce, I like your solution although it doesn't have the granularity that some may want, do you mind if I adapt it into my solution here:

    1. Part 1 - Create the database tables.
    2. Part 2 - Add a User Interface to modify the permissions.
    3. Part 3 - User Marcin's InMemoryMetadataProvider to add the database based permissions to the Metadata at runtime.
    4. Part 4 - Add components from A DynamicData Attribute Based Permission Solution using User Roles to consume the database based metadata.
    5. Part 5 - Oops! Table Names with Spaces in them and Pluralization.

    Which in turn extends the earlier articles here:

  • Introduction - A DynamicData Attribute Based Permission Solution using User Roles.
  • Part 1 - Permissions Attribute (Metadata) Classes.
  • Part 2 - Sample Metadata for project.
  • Part 3 - The Helper Extension Methods.
  • Part 4 - Limit Tables shown on Default page and List, Edit & Details etc.
  • Part 5 - Generate Columns/Rows (using IAutoFieldGenerator)
  • Part 6 - Miscellaneous bits
  • Part 7 - Updating the ListDetails Page
  • DynamicData - Limit the Filter Fields
  • I think I could adapt it to do the table part, but I'm still looking into a way of centralising the Field Security.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    11-07-2008, 3:07 PM
    • Member
      175 point Member
    • veloce
    • Member since 12-16-2002, 3:21 PM
    • Seattle
    • Posts 46

    Steve, I want to thank you for your remarks. Please, feel free to modify my example and let us know what you can come up with.

    Remember that the two basic design principles I adopted are as follows:

    1.      Use ASP.NET Forms Authentication to discriminate the user's roles.

    Everything you do in terms of authentication such as modify permissions, if I understand you correctly, must be integrated I believe with ASP.NET authentication mechanism.

    2.      Use ASP.NET Dynamic Data to authorize authenticated users to perform tasks at lower level, tasks only understood by Dynamic Data. Probably the centralization of field security should be done at this level. May be you can expand on this: I'm still looking into a way of centralizing the Field Security.

    Thanks,

    Michael (aka veloce)

     

    This posting is provided "AS IS" with no warranties, and confers no rights.


    I blog at: Technical Notes

  • Re: Secure Dynamic Data Site

    11-08-2008, 1:04 PM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

    Yes I understand the principals have a look at this post Dynamic Data - Default FieldGenerator which I think could be the way forward for Field Security.

    Big Smile

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-10-2009, 10:38 PM
    • Member
      2 point Member
    • mdausmann
    • Member since 08-29-2008, 7:39 AM
    • Posts 2

    Hi

    Thanks heaps for sample, I have implemented on my site and it works ok.  I had a couple of questions.

    Delete is only available for the role tagged as 'administrator' How would I go about allowing other user roles to have delete access on certain tables?  I tried adding the 'Delete' action in attributes but it didn't work.

    [Security(Role = "Anonymous", Action = "AnonymousList")]
    [Security(Role = "Developer", Action = "List")]
    [Security(Role = "Developer", Action = "Details")]
    [Security(Role = "Rule Author", Action = "List")]
    [Security(Role = "Rule Author", Action = "Details")]
    [Security(Role = "Rule Author", Action = "Edit")]
    [Security(Role = "Rule Author", Action = "Delete")]
    public partial class BehaviourDocument
    {

    }

    Michael

  • Re: Secure Dynamic Data Site

    07-11-2009, 4:43 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     Hi Mdausmann, I'll have a look at my sample and get back you.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
    Filed under:
  • Re: Secure Dynamic Data Site

    07-11-2009, 5:02 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     Hi Mdausmann, in this sample from Veloce, you have to be admin to get delete facility you will need to look at the test on each page e.g. List page:

    // Enable delete button only to allowed users.
    private void SetDelete(TableRow row)
    {
        // Instantiate the SecurityInformation 
        // utility object.
        DynamicDataSecurity secInfo =
          new DynamicDataSecurity();
    
        foreach (Control c in row.Cells[0].Controls)
        {
            // Deny delete capability to users that are 
            // not administrators
            if (!secInfo.IsUserInAdmimistrativeRole() &&
              secInfo.IsUserInAuthenticatedRole())
            {
                // Do not allow delete.
                LinkButton btn = c as LinkButton;
                if (btn != null &&
                    btn.CommandName ==
                    DataControlCommands.DeleteCommandName)
                {
                    btn.Visible = false;
                    btn.OnClientClick = null;
                    btn.Enabled = false;
                }
            }
        }
    }
    

    if you note the statement:

    if (!secInfo.IsUserInAdmimistrativeRole() &&
              secInfo.IsUserInAuthenticatedRole())
    


    you will need to change the !secInfo.IsUserInAdmimistrativeRole() to some other test the will test that will check for a role with delete.

    Hope that makes sense Big Smile

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-12-2009, 10:32 AM
    • Member
      81 point Member
    • zzdfc
    • Member since 07-06-2004, 6:07 AM
    • Posts 72

    The example of a Secure Dynamic Data Site Use CustomDynamicDataRouteHandler to achieve security,but how to transport data of session to CustomDynamicDataRouteHandler? I need transport custom logined user infomation to CustomDynamicDataRouteHandler.

    Thanks.

  • Re: Secure Dynamic Data Site

    07-12-2009, 11:16 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     Hi Zzdfc, I'm working on a simplified sample based on Veloces work, I should have part 1 ready early this week.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-14-2009, 9:41 AM
    • Member
      81 point Member
    • zzdfc
    • Member since 07-06-2004, 6:07 AM
    • Posts 72

     Hi sjnaughton:

           I have read your article "Securing Dynamic Data Preview 4 Refresh – Part 1",but it don't demo how to transport  session data to CustomDynamicDataRouteHandler? I need transport custom logined user infomation to CustomDynamicDataRouteHandler,example:

    Roles 、Permissions  and orgnization of the logined user.

  • Re: Secure Dynamic Data Site

    07-14-2009, 9:56 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     Hi Zzdfc, I'm not sure I understand what you are trying to do, could you explain in a little more detail and I will try to create a sample that demostraits it.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-14-2009, 11:58 AM
    • Member
      81 point Member
    • zzdfc
    • Member since 07-06-2004, 6:07 AM
    • Posts 72

    public class SecurityDynamicDataRouteHandler : DynamicDataRouteHandler
        {
            public override IHttpHandler CreateHandler(DynamicDataRoute route, MetaTable table, string action)
            {
               
                HttpContext httpContext = HttpContext.Current;
                string userName= httpContext.Session["UserName"].ToString();
                string userID= httpContext.Session["UserID"].ToString();
                string isAdmin= httpContext.Session["IsAdmin"].ToString();
                if(isAdmin==true)
               {
                       .........
                }
                else
               {
                  .........
                }

                 return null;

            }
        }

    but data of httpContext.Session alaways is null,how to do?

    thanks.

  • Re: Secure Dynamic Data Site

    07-14-2009, 12:39 PM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     OK I get what you mean now I'll have a look into it and see if anything can be done.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-15-2009, 6:26 AM
    • Star
      11,463 point Star
    • sjnaughton
    • Member since 04-29-2008, 1:11 PM
    • Newton-le-Willows, Merseyside, UK
    • Posts 2,418
    • TrustedFriends-MVPs

     Hi Zzdfc, I've just tested it on my sample and I get Session populated, I think it may be when you are setting the session, but why are you using Session anyway?

    If you e-mail me I can give you my sample working.

    Steve Big Smile

    Always seeking an elegant solution.
    [Oh! If olny I colud tpye!]
    c# Bits blog
    Oh, and don't forget to mark as answer any posts that help you Big Smile
  • Re: Secure Dynamic Data Site

    07-15-2009, 10:55 AM
    • Member
      81 point Member
    • zzdfc
    • Member since 07-06-2004, 6:07 AM
    • Posts 72

    Hi sjnaughton:

          I hope get your sample of  session,thank you very much!

           I use session to save user's permissions 、roles and infomation because user's permissions 、roles and infomation is from database, not is from attributes and metadata.

           I don't know if it have else method to save data in entire session lifecycle.

     

           In my program, I get session populated in first page,but session is null when it turn to list.aspx、detail.aspx、edit.aspx,I have tested many times.

     

     

                                                                 Thanks!

Page 1 of 2 (16 items) 1 2 Next >