私の問題に対する最善の解決策を探しています。私たちがしたいことは、ベースログインにアクティブディレクトリを使用することです。これにより、パスワードなどを管理する必要がなくなります。しかし、AD グループを使用する代わりに、カスタム ロールを作成したいと考えています。したがって、5 つの異なる AD グループに相当する 1 つのロールを持つことができます。
私が考えているのは、特定のグループ内のすべてのユーザーを、c# を介して、roleid から userid テーブルにリンクするカスタム ユーザー テーブルにダンプすることです。誰でもこれについて何か考えがありますか?しかし、誰かがこれらのグループのいずれかから削除された場合、アクセスを失う必要があり、そのグループを処理する方法がわからない場合に、カスタム ユーザー テーブルを管理する必要もあります。
現在、私の方法は次のようになります。
using (PrincipalContext ctx = new PrincipalContext(ContextType.Domain, "SETON"))
{
//Gets all Users in a AD Group
using (GroupPrincipal grp = GroupPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, groupName))
{
//Mkae sure group is not null
if (grp != null)
{
foreach (Principal p in grp.GetMembers())
{
//Sets up Variables to enter into Finance User Table
string UserName = p.SamAccountName;
string DisplayName = p.Name;
string emailAddress = p.UserPrincipalName;
//Get users detials by user
using (UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(ctx, IdentityType.SamAccountName, UserName))
{
if (userPrincipal != null)
{
//Test to see if user is in AD Group
bool inRole = userPrincipal.IsMemberOf(grp);
if (inRole)
{
//Test to See if UserName already exists in Finance User Table
var ds = User.GetUserList(UserName);
//If don't exist add them and to the new Role
if (ds.Tables[0].Rows.Count == 0)
{
//Add User to FinanceUSer Table
Seton.Roster.User user = new User();
user.UserName = UserName;
user.Name = DisplayName;
int id = user.Save();
//Get RoleID by RoleName with Method
var roleDS = SecurityRole.GetRoleList(roleName);
if (roleDS.Tables[0].Rows.Count > 0)
{
var roleDR = roleDS.Tables[0].Rows[0];
int roleid = Convert.ToInt32(roleDR["roleid"].ToString());
SecurityRoleUserLink.AddNewLink(roleid, id);
}
}
//if they exist just Get thier userid and add them to new Role
else
{
//Get UserID of existing FinanceUser
var userDR = ds.Tables[0].Rows[0];
int id = Convert.ToInt32(userDR["userid"].ToString());
//Get RoleID by RoleName with Method
var roleDS = SecurityRole.GetRoleList(roleName);
if (roleDS.Tables[0].Rows.Count > 0)
{
var roleDR = roleDS.Tables[0].Rows[0];
int roleid = Convert.ToInt32(roleDR["roleid"].ToString());
//Test to see if user already in this role
if(!SecurityRoleUserLink.UserInRole(id,roleid))
SecurityRoleUserLink.AddNewLink(roleid, id);