I created my own user permission tables, Where each user can belong to many groups and many security roles. But I have the following as part of my _layout view:-
<li class="nav-header hidden-tablet"style="background-color:#3E9BD4 ; color:white">User Section</li>
<li><a class="ajax-link" href="~/Home/Contact"><i class="icon-home"></i><span class="hidden-tablet">contact</span></a></li>
<li class="nav-header hidden-tablet"style="background-color:#3E9BD4 ; color:white">Administration Section</li>
<li><a class="ajax-link" href="~/SecurityGroup/"><i class="icon-home"></i><span class="hidden-tablet">Security Groups</span></a></li>
<li><a class="ajax-link" href="~/SecurityRole/"><i class="icon-home"></i><span class="hidden-tablet">Security Roles</span></a></li>
<li><a class="ajax-link" href="~/AuditInfo"><i class="icon-home"></i><span class="hidden-tablet">Audit</span></a></li>
<li><a class="ajax-link" href="~/SecurityGroup/ADUsers"><i class="icon-home"></i><span class="hidden-tablet">Active Directory</span></a></li>
So how I can show the administration section only if the current user belongs to a Group that is associated with a predefined security role named “Admin” or directly linked to this security role.
I am not storing any of the users info inside my application , as the users exists inside the Active Directory . So I have the following models classes:-
public partial class Group
{
public Group()
{
this.UserGroups = new HashSet<UserGroup>();
this.SecurityRoles = new HashSet<SecurityRole>();
}
public int GroupID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public byte[] timestamp { get; set; }
public virtual ICollection<UserGroup> UserGroups { get; set; }
public virtual ICollection<SecurityRole> SecurityRoles { get; set; }
}
public partial class UserGroup
{
public int GroupID { get; set; }
public string UserName { get; set; }
public virtual Group Group { get; set; }
}
}
public partial class SecurityRole
{
public SecurityRole()
{
this.SecurityroleTypePermisions = new HashSet<SecurityroleTypePermision>();
this.SecurityRoleUsers = new HashSet<SecurityRoleUser>();
this.Groups = new HashSet<Group>();
}
public int SecurityRoleID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public byte[] timestamp { get; set; }
public virtual ICollection<SecurityroleTypePermision> SecurityroleTypePermisions { get; set; }
public virtual ICollection<SecurityRoleUser> SecurityRoleUsers { get; set; }
public virtual ICollection<Group> Groups { get; set; }
}
public partial class SecurityRoleUser
{
public int SecurityRoleID { get; set; }
public string UserName { get; set; }
public virtual SecurityRole SecurityRole { get; set; }
}
Baring in mind that the _layout view is not a strongly typed view , so am not able to define helper method on the model level such as public bool IsAdmin(string userName) .
Thanks in advance for any help.