public static List <string> ReadWinUsers(string aStoreName, string RoleName) { try { AzAuthorizationStore store = new AzAuthorizationStore(); string storeLocation = GetAuthStoreLocation(aStoreName); //0 = The authorization store is opened for use by the Update method and the AccessCheck method. store.Initialize(0, storeLocation, null); List <string> members = new List <string>(); IAzRole iAzRole = null; foreach (IAzApplication3 toApplication in store.Applications) { if (RoleName.Equals("Administrator")) { iAzRole = toApplication.OpenRole(RoleName); } else { iAzRole = toApplication.OpenRole("_" + RoleName); } foreach (string member in iAzRole.MembersName) { members.Add(member); } return(members); } return(members); } catch (COMException ce) { MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred"); return(null); } }
public static bool AddWindowsUserToRole(string role, string aStoreName, string windowsUser) { bool success = false; try { AzAuthorizationStore store = new AzAuthorizationStore(); string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName); if (role != "Administrator") { role = "_" + role; } //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE store.Initialize(4, storeLocation, null); foreach (IAzApplication3 application in store.Applications) { IAzRole iAzRole = application.OpenRole(role); iAzRole.AddMemberName(windowsUser); iAzRole.Submit(); application.Submit(); } success = true; } catch (COMException ce) { MessageBox.Show(null, ce.Message + "\n" + ce.ErrorCode.ToString(), "COMException occurred"); } catch (Exception) { success = false; } return(success); }
public static bool DeleteWindowsUserFromRole(string role, string aStoreName, string windowsUser) { bool success; try { AzAuthorizationStore store = new AzAuthorizationStore(); string storeLocation = AzManReader.GetAuthStoreLocation(aStoreName); if (role != "Administrator") { role = "_" + role; } //4 = AZ_AZSTORE_FLAG_BATCH_UPDATE store.Initialize(4, storeLocation, null); foreach (IAzApplication3 application in store.Applications) { IAzRole iAzRole = application.OpenRole(role); iAzRole.DeleteMemberName(windowsUser); iAzRole.Submit(); application.Submit(); } success = true; } catch (Exception) { success = false; } return(success); }
private void CreaStrutturaSuAzMan(string azManStorePath, int n) { this.Clessidra(true); this.StartTimer(); WindowsIdentity id = WindowsIdentity.GetCurrent(); NTAccount userName = new NTAccount(id.Name); IAzAuthorizationStore store = new AzAuthorizationStoreClass(); store.Initialize(0, azManStorePath, null); object o = null; this.pb.Maximum = n - 1; for (int a = 0; a < n; a++) { IAzApplication app = store.CreateApplication("Application" + a.ToString(), null); app.Submit(0, null); this.pb.Value = a; Application.DoEvents(); //IAzClientContext ctx = app.InitializeClientContextFromToken((UInt64)id.Token, null); for (int i = 0; i < n; i++) { IAzOperation op = app.CreateOperation("Operation" + i.ToString(), o); op.OperationID = i + 1; op.Submit(0, null); IAzTask task = app.CreateTask("Task" + i.ToString(), null); task.AddOperation(op.Name, null); task.Submit(0, null); IAzTask roleTask = app.CreateTask("Role" + i.ToString(), null); roleTask.IsRoleDefinition = 1; roleTask.AddTask("Task" + i.ToString(), null); roleTask.Submit(0, null); IAzRole role = app.CreateRole("Role" + i.ToString(), null); role.AddTask("Role" + i.ToString(), null); role.AddMember(id.User.Value, null); //add current user role.Submit(0, null); } } this.StopTimer(this.txtAzManElapsed); this.Clessidra(false); }