This project is an implementation of the ASP.NET Role Provider using NHibernate and Sharp Architecture.
- 1.0.0
- Basic methods have been implemented.
Create the entity responsible for persisting data between the Role Provider and your database.
public class Role : NHibernate.Sidekick.Security.RoleProvider.Domain.RoleBase { }
This model assumes your Role
's Identifier is an integer. If this is not the case, inherit from RoleBaseWithTypedId<TId>
instead.
This is who unobtrusively does all the work for you.
public class MembershipProvider : NHibernate.Sidekick.Security.MembershipProvider.Providers.MembershipProvider<User> { }
This model assumes your Role
's Identifier is an integer. If this is not the case, inherit from MembershipProviderWithTypedId<T, TId>
instead.
public class AutoPersistenceModelGenerator : SharpArch.NHibernate.FluentNHibernate.IAutoPersistenceModelGenerator
{
public AutoPersistenceModel Generate()
{
AutoPersistenceModel mappings = AutoMap.AssemblyOf<User>(new AutomappingConfiguration());
// Default Sharp Architecture options go here.
mappings.IgnoreBase<UserBase>();
mappings.IgnoreBase<RoleBase>();
mappings.IgnoreBase(typeof(UserBaseWithTypedId<>));
mappings.IgnoreBase(typeof(RoleBaseWithTypedId<Role, User, int>));
}
}
This step is only relevant if you're using Fluent NHibernate's Automapping mechanism.
See NHibernate Sidekick's ASP.NET Membership Provider. This is necessary for it to be able to read and/or manipulate roles for a given User
.
Set this within your application's web.config
:
<configuration>
<system.web>
<roleManager defaultProvider="SidekickRoleProvider" enabled="true" cacheRolesInCookie="true">
<providers>
<clear/>
<add name="SidekickRoleProvider"
applicationName="/Sidekick_Security_SampleApp"
type="NHibernate.Sidekick.Security.Sampler.Domain.RoleProvider" />
</providers>
</roleManager>
</system.web>
</configuration>
@if (System.Web.Security.Roles.IsUserInRole("TestRole")) {
<text>User has the given role.!</text>
}
[Authorize(Roles="TestRole")]
public class HomeController : Controller { }
If you're unfamiliar with ASP.NET's Role Provider, you can find more information on Microsoft's MSDN.
- .NET Framework 4.0
- System
- System.Core
- System.Data
- System.Configuration
- System.Web
- System.Web.ApplicationServices