Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> AuthorizerToUse guidelines
 

Pages: 1
LLBLGen Pro Runtime Framework
AuthorizerToUse guidelines
Page:1/1 

  Print all messages in this thread  
Poster Message
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 22-Aug-2007 21:43:03.  
LLBLGen 2.5 (yea team!)
SQL Server 2005
C#

I've already upgraded the project from 2.0 with no hiccups (so far).

I have an application with 50+ entities and am interested in implementing the LLBLGen Authorizer. However out of the 50+, there are probably 5 groups/roles in which I could narrow down the number of unique authorizers required.

I'm curious as to how best to setup the authorization classes.

While I could go through and setup a separate Authorizer class for each entity, it seems that could be tedious and error prone.

I don't currently envsion field level controls.

What I am considering is create a interface for each of the groups.

Create the interfaces as:
Code:

public interface IRoleAdmin {}
public interface IRoleDBAdmin {}
public interface IRoleOperations {}
public interface IRoleResearch {}
public interface IRoleStaff {}

// create partial classes that implement the interface
public partial class PersonEntity : IRoleAdmin {}
// repeat for the rest of the entities, grouping appropriately


// create the authorizers for each interface
[DependencyInjectionInfo(typeof (IRoleAdmin), "AuthorizerToUse",
        ContextType = DependencyInjectionContextType.Singleton)]
public class DBAuthorizer : AuthorizerBase
{
// insert overrides here for actual Identity role memberships.
}


Then let DI handle the appropriate authorizers.

I am VERY open to suggestions, pitfalls and other ideas, this is just a thought...
Jim Hughes  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14626 posts
# Posted on: 23-Aug-2007 10:47:53.  
Looks good to me.

Also I don't know if you can specify more than one DependencyInjectionInfo attribute to the Authorizer class, as follows:
Code:
[DependencyInjectionInfo(typeof (PersonEntity), "AuthorizerToUse",
        ContextType = DependencyInjectionContextType.Singleton)]
[DependencyInjectionInfo(typeof (CustomerEntity), "AuthorizerToUse",
        ContextType = DependencyInjectionContextType.Singleton)]
[DependencyInjectionInfo(typeof (EMployeeEntity), "AuthorizerToUse",
        ContextType = DependencyInjectionContextType.Singleton)]
...
public class DBAuthorizer : AuthorizerBase
{
// insert overrides here for actual Identity role memberships.
}


  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38044 posts
# Posted on: 23-Aug-2007 10:56:11.  
Yes you can specify more than 1 attribute. Regular Smiley
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 23-Aug-2007 17:08:40.  
More than one attribute is even easier!

Thank you!


Jim Hughes  Top
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 23-Aug-2007 18:53:20.  
ummmm, It's not working... What did I miss?

Whichever attribute is closer to the class DBAdminAuthorizer works, the other fails with
"AssertionException: AuthorizerToUse is null".

Swapping the order of the attributes moves the error to the other test.

Code:


    [DependencyInjectionInfo(typeof(SamplerEntity), "AuthorizerToUse", ContextType = DependencyInjectionContextType.Singleton)]
    [DependencyInjectionInfo(typeof(SiteEntity), "AuthorizerToUse", ContextType = DependencyInjectionContextType.Singleton)]
    public class DBAdminAuthorizer : DBAuthorizerBase
    {
    }

[TestFixture]
public class AuthorizationTest
{

    [Test]
    public void CreateSamplerEntity()
    {
        SamplerEntity sampler = new SamplerEntity();
        Assert.IsNotNull(sampler.AuthorizerToUse, "AuthorizerToUse is null");
        Assert.IsInstanceOfType(typeof(DBAdminAuthorizer), sampler.AuthorizerToUse, "IsInstanceOfType = DBAdminAuthorizer");
        }
    }

    [Test]
    public void CreateSiteEntity()
    {
        SiteEntity site = new SiteEntity();
        Assert.IsNotNull(site.AuthorizerToUse, "AuthorizerToUse is null");
        Assert.IsInstanceOfType(typeof(DBAdminAuthorizer), site.AuthorizerToUse, "IsInstanceOfType = DBAdminAuthorizer");
    }
}
Jim Hughes  Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38044 posts
# Posted on: 24-Aug-2007 10:42:21.  
It should work, I'll setup a test.

(edit) reproduced. I'll see if I can track down the cause of this.

(edit) It's an implementation flaw: just 1 attribute is used. It's code in private methods, I'll rework it a bit to handle multiple attributes.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
38044 posts
# Posted on: 24-Aug-2007 11:37:35.  
Fixed in next build.

Code:

[DependencyInjectionInfo(typeof(LocationEntity), "AuthorizerToUse")]
[DependencyInjectionInfo(typeof(ProductVendorEntity), "AuthorizerToUse")]
[DependencyInjectionInfo(typeof(CustomerEntity), "AuthorizerToUse")]
public class GeneralAdventureWorksAuthorizer : AdventureWorksAuthorizerBase
{
    public override bool CanGetFieldValue(IEntityCore entity, int fieldIndex)
    {
        return base.CanGetFieldValue(entity, fieldIndex);
    }
}


Code:

[Test]
public void MultiAttributeAuthorizerTest()
{
    CustomerEntity c = new CustomerEntity();
    ProductVendorEntity p = new ProductVendorEntity();
    LocationEntity l = new LocationEntity();

    Assert.IsNotNull(c.AuthorizerToUse);
    Assert.IsNotNull(p.AuthorizerToUse);
    Assert.IsNotNull(l.AuthorizerToUse);
}
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 24-Aug-2007 18:15:15.  
Thanks Frans!

Jim Hughes  Top
JimHugh
User



Location:
Davis, CA
Joined on:
16-Nov-2005 14:32:25
Posted:
191 posts
# Posted on: 27-Aug-2007 19:44:22.  
2007.8.27 Build did the trick for multiple attribute support!

Thanks again!
Jim Hughes  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.