protected override void ProcessRecord() { GetSession(); if (Record == null && HashTable == null) { Record = new XenAPI.Subject(); Record.subject_identifier = SubjectIdentifier; Record.other_config = CommonCmdletFunctions.ConvertHashTableToDictionary <string, string>(OtherConfig); } else if (Record == null) { Record = new XenAPI.Subject(HashTable); } if (!ShouldProcess(session.Url, "Subject.create")) { return; } RunApiCall(() => { var contxt = _context as XenServerCmdletDynamicParameters; if (contxt != null && contxt.Async) { taskRef = XenAPI.Subject.async_create(session, Record); if (PassThru) { XenAPI.Task taskObj = null; if (taskRef != "OpaqueRef:NULL") { taskObj = XenAPI.Task.get_record(session, taskRef.opaque_ref); taskObj.opaque_ref = taskRef.opaque_ref; } WriteObject(taskObj, true); } } else { string objRef = XenAPI.Subject.create(session, Record); if (PassThru) { XenAPI.Subject obj = null; if (objRef != "OpaqueRef:NULL") { obj = XenAPI.Subject.get_record(session, objRef); obj.opaque_ref = objRef; } WriteObject(obj, true); } } }); UpdateSessions(); }
/// <summary> /// Extracts a key value pair list of information on the subject /// </summary> /// <param name="subject"></param> /// <returns></returns> public static List<KeyValuePair<String, String>> ExtractKvpInfo(Subject subject) { List<KeyValuePair<String, String>> kvpList = new List<KeyValuePair<string, string>>(); Dictionary<string, string> info = new Dictionary<string, string>(subject.other_config); // Trim undesirable entries info.Remove("subject-gid"); info.Remove("subject-uid"); info.Remove("subject-sid"); info.Remove("subject-is-group"); info.Remove("subject-gecos"); info.Remove("subject-upn"); if (info.Count == 0) return kvpList; string s; // Try and extract the important info as headers. No need for a label, just put the value as the key of the kvp if (info.TryGetValue("subject-displayname", out s)) { kvpList.Add(new KeyValuePair<string, string>(s, "")); info.Remove("subject-displayname"); } if (info.TryGetValue("subject-name", out s)) { kvpList.Add(new KeyValuePair<string, string>(s, "")); info.Remove("subject-name"); } // Add a double blank entry which is drawn as a vertical space and then add remaining kvps kvpList.Add(new KeyValuePair<string, string>("", "")); foreach (KeyValuePair<string, string> kvp in info) { // Try to localise the property key name string keyText, valueText; keyText = XenAdmin.Core.PropertyManager.GetFriendlyName(string.Format("AD.PropertyKey-{0}", kvp.Key)); if (keyText == null) keyText = kvp.Key; if (kvp.Value == "true") valueText = Messages.YES; else if (kvp.Value == "false") valueText = Messages.NO; else valueText = kvp.Value; keyText += Messages.GENERAL_PAGE_KVP_SEPARATOR; kvpList.Add(new KeyValuePair<string, string>(keyText, valueText)); } return kvpList; }
public AddRemoveRolesAction( Pool pool, Subject subject, List<Role> toAdd, List<Role> toRemove) : base( pool.Connection, string.Format(Messages.AD_ADDING_REMOVING_ROLES_ON, (subject.DisplayName ?? subject.SubjectName ?? subject.subject_identifier).Ellipsise(50)), Messages.AD_ADDING_REMOVING_ROLES, false) { this.Pool = pool; this.toAdd = toAdd; this.toRemove = toRemove; this.subject = subject; }
/// <summary> /// Makes server calls, call off the event thread. /// </summary> /// <param name="session"></param> private UserDetails(Session session) { _session = session; userSid = session.UserSid; try { Subject subj = new Subject(); subj.other_config = Auth.get_subject_information_from_identifier(session, userSid); userDisplayName = subj.DisplayName; userName = subj.SubjectName; groupMembershipSids = Auth.get_group_membership(session, userSid); } catch(Failure) { } }
public RoleSelectionDialog(Subject[] subjects, Pool pool) : this() { this.subjects = subjects; this.pool = pool; roleAssignment = new Dictionary<Role,List<Subject>>(); if (subjects.Length == 1) { Subject subject = subjects[0]; string sName = (subject.DisplayName ?? subject.SubjectName ?? Messages.UNKNOWN_AD_USER).Ellipsise(30); if (subject.IsGroup) { labelBlurb.Text = String.Format(Messages.AD_SELECT_ROLE_GROUP, sName); pictureBoxSubjectType.Image = XenAdmin.Properties.Resources._000_UserAndGroup_h32bit_32; } else { labelBlurb.Text = String.Format(Messages.AD_SELECT_ROLE_USER, sName); pictureBoxSubjectType.Image = XenAdmin.Properties.Resources._000_User_h32bit_16; } } else { labelBlurb.Text = Messages.AD_SELECT_ROLE_MIXED; pictureBoxSubjectType.Image = XenAdmin.Properties.Resources._000_User_h32bit_16; } // Get the list of roles off the server and arrange them into rank List<Role> serverRoles = new List<Role>(pool.Connection.Cache.Roles); //hide basic permissions, we only want the roles. serverRoles.RemoveAll(delegate(Role r){return r.subroles.Count < 1;}); serverRoles.Sort(); serverRoles.Reverse(); foreach (Role r in serverRoles) { roleAssignment.Add(r, new List<Subject>()); } foreach (Subject s in subjects) { List<Role> subjectRoles = (List<Role>)pool.Connection.ResolveAll<Role>(s.roles); foreach (Role r in subjectRoles) { roleAssignment[r].Add(s); } } foreach (Role role in serverRoles) { DataGridViewRow r = new DataGridViewRow(); DataGridViewCheckBoxCellEx c1 = new DataGridViewCheckBoxCellEx(); c1.ThreeState = true; if (roleAssignment[role].Count == subjects.Length) { c1.Value = CheckState.Checked; c1.CheckState = CheckState.Checked; } else if (roleAssignment[role].Count == 0) { c1.Value = CheckState.Unchecked; c1.CheckState = CheckState.Unchecked; } else { c1.Value = CheckState.Indeterminate; c1.CheckState = CheckState.Indeterminate; } DataGridViewTextBoxCell c2 = new DataGridViewTextBoxCell(); c2.Value = role.FriendlyName; r.Cells.Add(c1); r.Cells.Add(c2); r.Tag = role; gridRoles.Rows.Add(r); } setRoleDescription(); }
private int GroupCompare(Subject s1, Subject s2) { if (s1.IsGroup) { if (s2.IsGroup) return 0; return 1; } else { if (s2.IsGroup) return -1; return 0; } }
private int NameCompare(Subject s1, Subject s2) { return StringUtility.NaturalCompare(s1.SubjectName, s2.SubjectName) * -1; }
private int RoleCompare(Subject s1, Subject s2) { List<Role> s1Roles = pool.Connection.ResolveAll(s1.roles); List<Role> s2Roles = pool.Connection.ResolveAll(s2.roles); s1Roles.Sort(); s2Roles.Sort(); // If one subject doesn't have any roles, but it below the one with roles if (s1Roles.Count < 1) { if (s2Roles.Count < 1) { return 0; } return -1; } if (s2Roles.Count < 1) return 1; return s1Roles[0].CompareTo(s2Roles[0]); }
/// <summary> /// A DataGridViewRow that corresponds to a subject and shows their relevant information in expanded and collapsed states /// </summary> /// <param name="subject">If set to null this is assumed to be a root account that does not have a subject</param> internal AdSubjectRow(Subject subject) : base() { this.subject = subject; if (IsLocalRootRow) { contractedRoles = expandedRoles = ""; expandedSubjectInfo = new List<KeyValuePair<String, String>>(); contractedSubjectInfo = new List<KeyValuePair<String, String>>(); expandedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_LOCAL_ROOT_ACCOUNT, "")); expandedSubjectInfo.Add(new KeyValuePair<string, string>("", "")); expandedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_ALWAYS_GRANTED_ACCESS, "")); contractedSubjectInfo.Add(new KeyValuePair<string, string>(Messages.AD_LOCAL_ROOT_ACCOUNT, "")); } else { //Generate the role list string s = ""; List<Role> roles = subject.Connection.ResolveAll<Role>(subject.roles); roles.Sort(); roles.Reverse(); foreach (Role r in roles) { s = String.Format("{0}\n{1}", s, r.FriendlyName); } expandedRoles = s; contractedRoles = roles.Count > 0 ? roles.Count > 1 ? roles[0].FriendlyName.AddEllipsis() : roles[0].FriendlyName : ""; contractedSubjectInfo = new List<KeyValuePair<String, String>>(); contractedSubjectInfo.Add(new KeyValuePair<string, string>(subject.DisplayName ?? subject.SubjectName ?? "", "")); expandedSubjectInfo = Subject.ExtractKvpInfo(subject); } Cells.Add(new DataGridViewImageCell()); // Expander image cell Cells.Add(new DataGridViewImageCell()); // Group/user image cell Cells.Add(new KeyValuePairCell()); // Subject info cell Cells.Add(new DataGridViewTextBoxCell()); // Roles cell Cells.Add(new DataGridViewTextBoxCell()); // logged in cell refreshCellContent(); }
void resolveAction_SubjectAddComplete(object sender, Subject subject, Exception exception) { Program.Invoke(this, delegate { foreach (ListViewItemSubjectWrapper i in entryListView.Items) { if (i.sid == subject.subject_identifier) { i.AddException = exception; i.Subject = subject; i.Update(); break; } } updateProgress(); }); }
private void addResolvedSubjects() { Exception e = null; Subject subject = null; log.DebugFormat("Adding {0} new subjects on pool '{1}'", sidsToAdd.Count, Helpers.GetName(Pool).Ellipsise(50)); foreach (string sid in sidsToAdd) { try { // We pass this object back even if it fails so we know who we are talking about subject = new Subject(); subject.subject_identifier = sid; subject.other_config = Auth.get_subject_information_from_identifier(Session, sid); // Check that this subject doesn't already exist foreach (Subject s in Pool.Connection.Cache.Subjects) { if (s.subject_identifier == sid) { log.WarnFormat("A Subject with sid {0} already exists on the server.", sid); string subjectName = (subject.DisplayName ?? subject.SubjectName ?? "").Ellipsise(50); throw new Exception(String.Format(Messages.AD_USER_ALREADY_HAS_ACCESS, subjectName)); } } XenAPI.Subject.create(Session, subject); } catch (Exception ex) { Failure f = ex as Failure; if (f != null && f.ErrorDescription[0] == Failure.RBAC_PERMISSION_DENIED) Failure.ParseRBACFailure(f,Connection,Session); Exception = ex; log.Warn("Exception adding AD user to subject list", ex); e = ex; } finally { if (SubjectAddComplete != null) { SubjectAddComplete(this, subject, e); } e = null; subject = null; } stepsComplete++; PercentComplete = (100 * stepsComplete) / steps; } }
private string GetName(Session session) { try { Subject subj = new Subject(); subj.other_config = Auth.get_subject_information_from_identifier(session, userSid); return subj.SubjectName; } catch (Failure) { return null; } }
protected override void ProcessRecord() { XenAPI.Session session = XenObject as XenAPI.Session; if (session != null) { WriteObject(new XenRef <XenAPI.Session>(session)); return; } XenAPI.Auth auth = XenObject as XenAPI.Auth; if (auth != null) { WriteObject(new XenRef <XenAPI.Auth>(auth)); return; } XenAPI.Subject subject = XenObject as XenAPI.Subject; if (subject != null) { WriteObject(new XenRef <XenAPI.Subject>(subject)); return; } XenAPI.Role role = XenObject as XenAPI.Role; if (role != null) { WriteObject(new XenRef <XenAPI.Role>(role)); return; } XenAPI.Task task = XenObject as XenAPI.Task; if (task != null) { WriteObject(new XenRef <XenAPI.Task>(task)); return; } XenAPI.Event evt = XenObject as XenAPI.Event; if (evt != null) { WriteObject(new XenRef <XenAPI.Event>(evt)); return; } XenAPI.Pool pool = XenObject as XenAPI.Pool; if (pool != null) { WriteObject(new XenRef <XenAPI.Pool>(pool)); return; } XenAPI.Pool_patch pool_patch = XenObject as XenAPI.Pool_patch; if (pool_patch != null) { WriteObject(new XenRef <XenAPI.Pool_patch>(pool_patch)); return; } XenAPI.Pool_update pool_update = XenObject as XenAPI.Pool_update; if (pool_update != null) { WriteObject(new XenRef <XenAPI.Pool_update>(pool_update)); return; } XenAPI.VM vm = XenObject as XenAPI.VM; if (vm != null) { WriteObject(new XenRef <XenAPI.VM>(vm)); return; } XenAPI.VM_metrics vm_metrics = XenObject as XenAPI.VM_metrics; if (vm_metrics != null) { WriteObject(new XenRef <XenAPI.VM_metrics>(vm_metrics)); return; } XenAPI.VM_guest_metrics vm_guest_metrics = XenObject as XenAPI.VM_guest_metrics; if (vm_guest_metrics != null) { WriteObject(new XenRef <XenAPI.VM_guest_metrics>(vm_guest_metrics)); return; } XenAPI.VMPP vmpp = XenObject as XenAPI.VMPP; if (vmpp != null) { WriteObject(new XenRef <XenAPI.VMPP>(vmpp)); return; } XenAPI.VMSS vmss = XenObject as XenAPI.VMSS; if (vmss != null) { WriteObject(new XenRef <XenAPI.VMSS>(vmss)); return; } XenAPI.VM_appliance vm_appliance = XenObject as XenAPI.VM_appliance; if (vm_appliance != null) { WriteObject(new XenRef <XenAPI.VM_appliance>(vm_appliance)); return; } XenAPI.DR_task dr_task = XenObject as XenAPI.DR_task; if (dr_task != null) { WriteObject(new XenRef <XenAPI.DR_task>(dr_task)); return; } XenAPI.Host host = XenObject as XenAPI.Host; if (host != null) { WriteObject(new XenRef <XenAPI.Host>(host)); return; } XenAPI.Host_crashdump host_crashdump = XenObject as XenAPI.Host_crashdump; if (host_crashdump != null) { WriteObject(new XenRef <XenAPI.Host_crashdump>(host_crashdump)); return; } XenAPI.Host_patch host_patch = XenObject as XenAPI.Host_patch; if (host_patch != null) { WriteObject(new XenRef <XenAPI.Host_patch>(host_patch)); return; } XenAPI.Host_metrics host_metrics = XenObject as XenAPI.Host_metrics; if (host_metrics != null) { WriteObject(new XenRef <XenAPI.Host_metrics>(host_metrics)); return; } XenAPI.Host_cpu host_cpu = XenObject as XenAPI.Host_cpu; if (host_cpu != null) { WriteObject(new XenRef <XenAPI.Host_cpu>(host_cpu)); return; } XenAPI.Network network = XenObject as XenAPI.Network; if (network != null) { WriteObject(new XenRef <XenAPI.Network>(network)); return; } XenAPI.VIF vif = XenObject as XenAPI.VIF; if (vif != null) { WriteObject(new XenRef <XenAPI.VIF>(vif)); return; } XenAPI.VIF_metrics vif_metrics = XenObject as XenAPI.VIF_metrics; if (vif_metrics != null) { WriteObject(new XenRef <XenAPI.VIF_metrics>(vif_metrics)); return; } XenAPI.PIF pif = XenObject as XenAPI.PIF; if (pif != null) { WriteObject(new XenRef <XenAPI.PIF>(pif)); return; } XenAPI.PIF_metrics pif_metrics = XenObject as XenAPI.PIF_metrics; if (pif_metrics != null) { WriteObject(new XenRef <XenAPI.PIF_metrics>(pif_metrics)); return; } XenAPI.Bond bond = XenObject as XenAPI.Bond; if (bond != null) { WriteObject(new XenRef <XenAPI.Bond>(bond)); return; } XenAPI.VLAN vlan = XenObject as XenAPI.VLAN; if (vlan != null) { WriteObject(new XenRef <XenAPI.VLAN>(vlan)); return; } XenAPI.SM sm = XenObject as XenAPI.SM; if (sm != null) { WriteObject(new XenRef <XenAPI.SM>(sm)); return; } XenAPI.SR sr = XenObject as XenAPI.SR; if (sr != null) { WriteObject(new XenRef <XenAPI.SR>(sr)); return; } XenAPI.LVHD lvhd = XenObject as XenAPI.LVHD; if (lvhd != null) { WriteObject(new XenRef <XenAPI.LVHD>(lvhd)); return; } XenAPI.VDI vdi = XenObject as XenAPI.VDI; if (vdi != null) { WriteObject(new XenRef <XenAPI.VDI>(vdi)); return; } XenAPI.VBD vbd = XenObject as XenAPI.VBD; if (vbd != null) { WriteObject(new XenRef <XenAPI.VBD>(vbd)); return; } XenAPI.VBD_metrics vbd_metrics = XenObject as XenAPI.VBD_metrics; if (vbd_metrics != null) { WriteObject(new XenRef <XenAPI.VBD_metrics>(vbd_metrics)); return; } XenAPI.PBD pbd = XenObject as XenAPI.PBD; if (pbd != null) { WriteObject(new XenRef <XenAPI.PBD>(pbd)); return; } XenAPI.Crashdump crashdump = XenObject as XenAPI.Crashdump; if (crashdump != null) { WriteObject(new XenRef <XenAPI.Crashdump>(crashdump)); return; } XenAPI.VTPM vtpm = XenObject as XenAPI.VTPM; if (vtpm != null) { WriteObject(new XenRef <XenAPI.VTPM>(vtpm)); return; } XenAPI.Console console = XenObject as XenAPI.Console; if (console != null) { WriteObject(new XenRef <XenAPI.Console>(console)); return; } XenAPI.User user = XenObject as XenAPI.User; if (user != null) { WriteObject(new XenRef <XenAPI.User>(user)); return; } XenAPI.Data_source data_source = XenObject as XenAPI.Data_source; if (data_source != null) { WriteObject(new XenRef <XenAPI.Data_source>(data_source)); return; } XenAPI.Blob blob = XenObject as XenAPI.Blob; if (blob != null) { WriteObject(new XenRef <XenAPI.Blob>(blob)); return; } XenAPI.Message message = XenObject as XenAPI.Message; if (message != null) { WriteObject(new XenRef <XenAPI.Message>(message)); return; } XenAPI.Secret secret = XenObject as XenAPI.Secret; if (secret != null) { WriteObject(new XenRef <XenAPI.Secret>(secret)); return; } XenAPI.Tunnel tunnel = XenObject as XenAPI.Tunnel; if (tunnel != null) { WriteObject(new XenRef <XenAPI.Tunnel>(tunnel)); return; } XenAPI.PCI pci = XenObject as XenAPI.PCI; if (pci != null) { WriteObject(new XenRef <XenAPI.PCI>(pci)); return; } XenAPI.PGPU pgpu = XenObject as XenAPI.PGPU; if (pgpu != null) { WriteObject(new XenRef <XenAPI.PGPU>(pgpu)); return; } XenAPI.GPU_group gpu_group = XenObject as XenAPI.GPU_group; if (gpu_group != null) { WriteObject(new XenRef <XenAPI.GPU_group>(gpu_group)); return; } XenAPI.VGPU vgpu = XenObject as XenAPI.VGPU; if (vgpu != null) { WriteObject(new XenRef <XenAPI.VGPU>(vgpu)); return; } XenAPI.VGPU_type vgpu_type = XenObject as XenAPI.VGPU_type; if (vgpu_type != null) { WriteObject(new XenRef <XenAPI.VGPU_type>(vgpu_type)); return; } XenAPI.PVS_site pvs_site = XenObject as XenAPI.PVS_site; if (pvs_site != null) { WriteObject(new XenRef <XenAPI.PVS_site>(pvs_site)); return; } XenAPI.PVS_server pvs_server = XenObject as XenAPI.PVS_server; if (pvs_server != null) { WriteObject(new XenRef <XenAPI.PVS_server>(pvs_server)); return; } XenAPI.PVS_proxy pvs_proxy = XenObject as XenAPI.PVS_proxy; if (pvs_proxy != null) { WriteObject(new XenRef <XenAPI.PVS_proxy>(pvs_proxy)); return; } XenAPI.PVS_cache_storage pvs_cache_storage = XenObject as XenAPI.PVS_cache_storage; if (pvs_cache_storage != null) { WriteObject(new XenRef <XenAPI.PVS_cache_storage>(pvs_cache_storage)); return; } XenAPI.Feature feature = XenObject as XenAPI.Feature; if (feature != null) { WriteObject(new XenRef <XenAPI.Feature>(feature)); return; } XenAPI.SDN_controller sdn_controller = XenObject as XenAPI.SDN_controller; if (sdn_controller != null) { WriteObject(new XenRef <XenAPI.SDN_controller>(sdn_controller)); return; } XenAPI.Vdi_nbd_server_info vdi_nbd_server_info = XenObject as XenAPI.Vdi_nbd_server_info; if (vdi_nbd_server_info != null) { WriteObject(new XenRef <XenAPI.Vdi_nbd_server_info>(vdi_nbd_server_info)); return; } XenAPI.PUSB pusb = XenObject as XenAPI.PUSB; if (pusb != null) { WriteObject(new XenRef <XenAPI.PUSB>(pusb)); return; } XenAPI.USB_group usb_group = XenObject as XenAPI.USB_group; if (usb_group != null) { WriteObject(new XenRef <XenAPI.USB_group>(usb_group)); return; } XenAPI.VUSB vusb = XenObject as XenAPI.VUSB; if (vusb != null) { WriteObject(new XenRef <XenAPI.VUSB>(vusb)); return; } }