For Ben Day's project here is what I changed during the configure calls. I changed both the SchemaUtility.cs and NHibernateHttpModule.cs
It is really much easier to have two seperate files. For my projects I usually just add a key to the web config that points to the nhibernate config file. I also change my nhibernate config file to nhibernate.config that way the web server will block a request for the file.
Code:
if (System.Web.HttpContext.Current != null)
config.Configure(System.Web.HttpContext.Current.Request.MapPath("~/hibernate.cfg.xml"));
else
config.Configure();
I also altered the CreateSchema.aspx.cs file to the following. This wll build a minimum config to start playing with.
Code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Com.Benday.NHibernate.Facades;
using VSLive.RightsBasedSecurity.Security.DomainModel;
using VSLive.RightsBasedSecurity.Security.Facades;
public partial class CreateSchema : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
SchemaFacade.Export();
CreateRightGrants();
}
protected List<UserLogin> CreateUsers()
{
List<UserLogin> users = new List<UserLogin>();
users.Add(CreateUser("Catalog", "Administrator", "admin", "admin@test.org", "password"));
users.Add(CreateUser("Joe Q.", "Public", "public", "joe.q.public@test.org", "password"));
users.Add(CreateUser("FirstName3", "LastName3", "UserName3", "username3@test.org", "password"));
users.Add(CreateUser("FirstName4", "LastName4", "UserName4", "username4@test.org", "password"));
BusinessFacade<UserLogin> facade = new BusinessFacade<UserLogin>(SessionFacade.Session);
facade.Save(users);
return users;
}
protected List<UserGroup> CreateGroups()
{
List<UserGroup> groups = new List<UserGroup>();
groups.Add(CreateUserGroup("CatalogAdmins"));
groups.Add(CreateUserGroup("CatalogPublicUsers"));
groups.Add(CreateUserGroup("CatalogInternalUsers"));
BusinessFacade<UserGroup> facade = new BusinessFacade<UserGroup>(SessionFacade.Session);
facade.Save(groups);
return groups;
}
protected UserLogin CreateUser(string firstName, string lastName, string userName, string email, string password)
{
UserLogin login = new UserLogin();
login.FirstName = firstName;
login.LastName = lastName;
login.Username = userName;
login.Password = password;
login.Email = email;
return login;
}
protected UserGroup CreateUserGroup(string name)
{
UserGroup group = new UserGroup();
group.Name = name;
return group;
}
protected UserGroupMember CreateUserGroupMember(UserGroup group, UserLogin user)
{
group.AddMember(user);
return group.FindMember(user);
}
protected ItemRight CreateItemRight(string name, bool isItemSpecific, SecurableItem securableItem)
{
ItemRight right = new ItemRight();
right.IsItemSpecific = isItemSpecific;
right.Name = name;
right.SecurableItem = securableItem;
return right;
}
protected SecurableItem CreateSecurableItem(string name)
{
SecurableItem item = new SecurableItem();
item.Name = name;
item.ItemType = "Library Entry";
return item;
}
protected List<ItemRight> CreateItemRights(SecurableItem securableItem)
{
List<ItemRight> itemRights = new List<ItemRight>();
itemRights.Add(CreateItemRight("CATALOG_ADMIN", false, null));
itemRights.Add(CreateItemRight("CATALOG_USER", false, null));
itemRights.Add(CreateItemRight("VIEW_ENTRY", true, securableItem));
itemRights.Add(CreateItemRight("VIEW_RELATED", true, securableItem));
itemRights.Add(CreateItemRight("EXPORT_TO_EXCEL", true, securableItem));
itemRights.Add(CreateItemRight("DOWNLOAD_EDOC", true, securableItem));
BusinessFacade<ItemRight> facade = new BusinessFacade<ItemRight>(SessionFacade.Session);
facade.Save(itemRights);
return itemRights;
}
public List<UserGroupMember> CreateUsersAndGroups()
{
List<UserGroup> groups = CreateGroups();
List<UserLogin> users = CreateUsers();
List<UserGroupMember> members = new List<UserGroupMember>();
BusinessFacade<UserGroupMember> facade = new BusinessFacade<UserGroupMember>(SessionFacade.Session);
members.Add(CreateUserGroupMember(groups[0], users[0]));
members.Add(CreateUserGroupMember(groups[1], users[1]));
members.Add(CreateUserGroupMember(groups[1], users[2]));
members.Add(CreateUserGroupMember(groups[1], users[3]));
facade.Save(members);
return members;
}
public ItemGroup CreateItemGroup(string name, SecurableItem securableItem)
{
ItemGroup itemGroup = new ItemGroup();
itemGroup.Name = name;
itemGroup.SecurableItem = securableItem;
return itemGroup;
}
public List<ItemGroup> CreateItemGroups(SecurableItem securableItem)
{
List<ItemGroup> list = new List<ItemGroup>();
list.Add(CreateItemGroup("Public", securableItem));
list.Add(CreateItemGroup("Private", securableItem));
list.Add(CreateItemGroup("Internal", securableItem));
BusinessFacade<ItemGroup> facade = new BusinessFacade<ItemGroup>(SessionFacade.Session);
facade.Save(list);
return list;
}
public ItemGroupMember CreateItemGroupMember(ItemGroup itemGroup, int itemId)
{
ItemGroupMember member = new ItemGroupMember();
member.ItemGroup = itemGroup;
member.ItemId = itemId;
return member;
}
public void CreateRightGrants()
{
SecurableItem item = CreateSecurableItem("Library Entry");
List<ItemRight> itemRights = CreateItemRights(item);
List<ItemGroup> itemGroups = CreateItemGroups(item);
List<UserGroupMember> userGroupMembers = CreateUsersAndGroups();
BusinessFacade<UserLogin> userFacade = new BusinessFacade<UserLogin>(SessionFacade.Session);
IList users = userFacade.GetList();
UserLogin user1 = users[0] as UserLogin;
UserLogin user2 = users[1] as UserLogin;
BusinessFacade<ItemGroupMember> facade = new BusinessFacade<ItemGroupMember>(SessionFacade.Session);
ItemGroupMember igm = CreateItemGroupMember(itemGroups[0], 10);
facade.Save(igm);
igm = CreateItemGroupMember(itemGroups[0], 20);
facade.Save(igm);
igm = CreateItemGroupMember(itemGroups[1], 30);
facade.Save(igm);
igm = CreateItemGroupMember(itemGroups[1], 40);
facade.Save(igm);
BusinessFacade<RightGrant> rgFacade = new BusinessFacade<RightGrant>(SessionFacade.Session);
BusinessFacade<UserGroup> ugFacade = new BusinessFacade<UserGroup>(SessionFacade.Session);
BusinessFacade<ItemRight> rightsFacade = new BusinessFacade<ItemRight>(SessionFacade.Session);
UserGroup ugCatalogUsers = ugFacade.Get("Name", "CatalogUsers");
ItemRight rightViewEntry = rightsFacade.Get("Name", "VIEW_ENTRY");
RightGrant rg = null;
// Grant UserGroup Right on Item
rg = new RightGrant();
rg.Recipient.UserGroup = userGroupMembers[0].UserGroup;
rg.Right = itemRights[0];
rg.Target.Item = CreateItemGrantTarget(10, "GrantTarget1");
rgFacade.Save(rg);
// Grant UserGroup Right on ItemGroup
rg = new RightGrant();
rg.Recipient.UserGroup = userGroupMembers[0].UserGroup;
rg.Right = itemRights[0];
rg.Target.ItemGroup = itemGroups[0];
rgFacade.Save(rg);
// Grant UserGroup Right on ItemGroup
rg = new RightGrant();
rg.Recipient.UserGroup = ugCatalogUsers;
rg.Right = rightViewEntry;
rg.Target.ItemGroup = itemGroups[1];
rgFacade.Save(rg);
// Grant User Right on Item
rg = new RightGrant();
rg.Recipient.User = user1;
rg.Right = itemRights[0];
rg.Target.Item = CreateItemGrantTarget(10, "GrantTarget2");
rgFacade.Save(rg);
// Grant User Right on ItemGroup
rg = new RightGrant();
rg.Recipient.User = user1;
rg.Right = itemRights[0];
rg.Target.ItemGroup = itemGroups[0];
rgFacade.Save(rg);
// Grant User Right on Item
rg = new RightGrant();
rg.Recipient.User = user2;
rg.Right = itemRights[1];
rg.Target.Item = CreateItemGrantTarget(10, "GrantTarget2");
rgFacade.Save(rg);
// Grant User Right on ItemGroup
rg = new RightGrant();
rg.Recipient.User = user2;
rg.Right = itemRights[1];
rg.Target.ItemGroup = itemGroups[1];
rgFacade.Save(rg);
}
public ItemGrantTarget CreateItemGrantTarget(int itemId, string itemType)
{
ItemGrantTarget igt = new ItemGrantTarget();
igt.ItemId = itemId;
igt.ItemType = itemType;
return igt;
}
}
[/code]