private UserDto AddUser (UserDto userDto) { userDto.Domain = _systemDomain; userDto.Alias = new PrincipalDto { Name = userDto.Name, Domain = userDto.Domain }; userDto.PersonDetails.UserPrincipalName = string.Format("{0}@{1}", userDto.Name, _systemDomain); var serverDto = SnapInContext.Instance.AuthTokenManager.GetAuthToken(_serverDto.ServerName); return SnapInContext.Instance.ServiceGateway.User.Create(_serverDto, _tenantName, userDto, serverDto.Token); }
public string Delete(ServerDto serverDto, string tenantName, UserDto user, Token token) { var name = Uri.EscapeDataString(user.Name + "@" + user.Domain); tenantName = Uri.EscapeDataString(tenantName); var url = string.Format(ServiceConfigManager.UserEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName, name); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Delete, }; var headers = ServiceHelper.AddHeaders(ServiceConfigManager.JsonContentType); var json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower(); return _webRequestManager.GetResponse(url, requestConfig, headers, null, json); }
public UserDto Create(ServerDto serverDto, string tenantName, UserDto userDto, Token token) { tenantName = Uri.EscapeDataString(tenantName); var json = JsonConvert.Serialize(userDto); var url = string.Format(ServiceConfigManager.UsersEndPoint, serverDto.Protocol, serverDto.ServerName, serverDto.Port, tenantName); ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; var requestConfig = new RequestSettings { Method = HttpMethod.Post, }; var headers = ServiceHelper.AddHeaders(); headers[HttpRequestHeader.Accept] = ServiceConfigManager.JsonContentType; headers[HttpRequestHeader.ContentType] = ServiceConfigManager.JsonContentType; json = "access_token=" + token.AccessToken + "&token_type=" + token.TokenType.ToString().ToLower() + "&" + json; var response = _webRequestManager.GetResponse(url, requestConfig, headers, null, json); return JsonConvert.Deserialize<UserDto>(response); }
public override void AwakeFromNib () { base.AwakeFromNib (); UserDto = UserDtoOriginal.DeepCopy (); Groups = new List<GroupDto> (GroupsOriginal); TxtUsername.StringValue = UserDto.Name == null ? string.Empty : UserDto.Name; TxtFirstName.StringValue = UserDto.PersonDetails.FirstName == null ? string.Empty : UserDto.PersonDetails.FirstName; TxtLastName.StringValue = UserDto.PersonDetails.LastName == null ? string.Empty : UserDto.PersonDetails.LastName; TxtEmail.StringValue = UserDto.PersonDetails.EmailAddress == null ? string.Empty : UserDto.PersonDetails.EmailAddress; TxtDescription.StringValue = UserDto.PersonDetails.Description == null ? string.Empty : UserDto.PersonDetails.Description; if (UserDto.PasswordDetails != null) { TxtPasswordLastChanged.StringValue = DateTimeHelper.UnixToWindows ((long)UserDto.PasswordDetails.LastSet).ToString ("dd-MMM-yyyy hh:mm:ss"); TxtPasswordDaysUntilExpiry.StringValue = SecondsToDaysAndHours (UserDto.PasswordDetails.Lifetime); } ChDisabled.StringValue = UserDto.Disabled ? "0" : "1"; //Window.Title = UserDto.Name + "@" + UserDto.Domain + " Properties"; ChActAsUser.StringValue = UserDto.ActAsUsers ? "1" : "0"; ChIdpAdmin.StringValue = UserDto.IsIdpAdmin ? "1" : "0"; RdoRoleGroup.SelectCell (new NSCell (UserDto.Role.ToString ())); lstGroups = new NSTableView (); lstGroups.Delegate = new TableDelegate (); this.LstGroupMembershipView.AddSubview (lstGroups); var listView = new GroupsDataSource { Entries = Groups }; var columnNames = new List<ColumnOptions> { new ColumnOptions{ Id = "Name", DisplayName = "Group Name", DisplayOrder = 1, Width = 300 } }; var columns = ListViewHelper.ToNSTableColumns (columnNames); foreach (var column in columns) { lstGroups.AddColumn (column); } lstGroups.DataSource = listView; lstGroups.ReloadData (); //Events this.BtnSave.Activated += OnClickSaveButton; this.BtnAddGroup.Activated += OnClickAddGroupButton; this.BtnRemoveGroup.Activated += OnClickRemoveGroupButton; // this.BtnClose.Activated += (object sender, EventArgs e) => { // this.Close (); // NSApplication.SharedApplication.StopModalWithCode (0); // }; }
public override void AwakeFromNib () { base.AwakeFromNib (); UserDto = UserDtoOriginal.DeepCopy (); Groups = new List<GroupDto> (GroupsOriginal); TxtUsername.StringValue = UserDto.Name == null ? string.Empty : UserDto.Name.Length > 10 ? UserDto.Name.Substring(0,10) + "..." : UserDto.Name; TxtFirstName.StringValue = UserDto.PersonDetails.FirstName == null ? string.Empty : UserDto.PersonDetails.FirstName; TxtLastName.StringValue = UserDto.PersonDetails.LastName == null ? string.Empty : UserDto.PersonDetails.LastName; TxtEmail.StringValue = UserDto.PersonDetails.EmailAddress == null ? string.Empty : UserDto.PersonDetails.EmailAddress; TxtDescription.StringValue = UserDto.PersonDetails.Description == null ? string.Empty : UserDto.PersonDetails.Description; chkActive.StringValue = UserDto.Disabled ? "0" : "1"; ChActAsUser.StringValue = UserDto.ActAsUsers ? "1" : "0"; ChIdpAdmin.StringValue = UserDto.IsIdpAdmin ? "1" : "0"; var roleTag = UserDto.Role == UserRole.Administrator ? 1 : UserDto.Role == UserRole.RegularUser ? 2 : 3; RdoRoleGroup.SelectCellWithTag ((nint)roleTag); foreach(NSTableColumn column in MemberTableView.TableColumns()) { MemberTableView.RemoveColumn (column); } MemberTableView.Delegate = new TableDelegate (); var listView = new GroupsDataSource { Entries = Groups }; var columnNames = new List<ColumnOptions> { new ColumnOptions{ Id = "Name", DisplayName = "Group Name", DisplayOrder = 1, Width = 200 } }; var columns = ListViewHelper.ToNSTableColumns (columnNames); foreach (var column in columns) { MemberTableView.AddColumn (column); } MemberTableView.DataSource = listView; MemberTableView.ReloadData (); BtnApply.Hidden = !IsSystemDomain; //Events this.BtnApply.Activated += OnClickSaveButton; this.BtnAddGroup.Activated += OnClickAddGroupButton; this.BtnRemoveGroup.Activated += OnClickRemoveGroupButton; }
public void OnClickAddButton (object sender, EventArgs e) { if (string.IsNullOrEmpty (TxtUserName.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid username", "Alert"); } else if (string.IsNullOrEmpty (TxtFirstName.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid First Name", "Alert"); } else if (string.IsNullOrEmpty (TxtLastName.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid Last name", "Alert"); } else if (string.IsNullOrEmpty (TxtEmail.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid Email", "Alert"); } else if (string.IsNullOrEmpty (TxtDescription.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid Description", "Alert"); } else if (string.IsNullOrEmpty (TxtPassword.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid Password", "Alert"); } else if (string.IsNullOrEmpty (TxtConfirmPassword.StringValue)) { UIErrorHelper.ShowAlert ("Please enter valid Confirm Password", "Alert"); } else if (TxtPassword.StringValue != TxtConfirmPassword.StringValue) { UIErrorHelper.ShowAlert ("Password and confirm password values do not match", "Alert"); } else { UserDto = new UserDto () { Name = TxtUserName.StringValue, PersonDetails = new PersonUserDto { FirstName = TxtFirstName.StringValue, LastName = TxtLastName.StringValue, EmailAddress = TxtEmail.StringValue, Description = TxtDescription.StringValue }, PasswordDetails = new PasswordDetailsDto { Password = TxtPassword.StringValue } }; this.Close (); NSApplication.SharedApplication.StopModalWithCode (1); } }
public bool IsDifferentThan(UserDto other) { return (this.Name != other.Name || this.PasswordDetails != other.PasswordDetails || this.Locked != other.Locked || this.Disabled != other.Disabled || this.Domain != other.Domain || this.PersonDetails.Description != other.PersonDetails.Description || this.PersonDetails.EmailAddress != other.PersonDetails.EmailAddress || this.PersonDetails.FirstName != other.PersonDetails.FirstName || this.PersonDetails.LastName != other.PersonDetails.LastName || this.PersonDetails.UserPrincipalName != other.PersonDetails.UserPrincipalName || this.Role != other.Role || this.IsIdpAdmin != other.IsIdpAdmin || this.ActAsUsers != other.ActAsUsers); }
public void DeleteUser (UserDto userDto) { ActionHelper.Execute (delegate() { userDto.PersonDetails.UserPrincipalName = string.Format ("{0}@{1}", userDto.Name, _systemDomain); var serverDto = SnapInContext.Instance.AuthTokenManager.GetAuthToken (_serverDto.ServerName); var result = SnapInContext.Instance.ServiceGateway.User.Delete (_serverDto, _tenantName, userDto, serverDto.Token); var success = string.IsNullOrEmpty (result); if (success) { UIErrorHelper.ShowAlert ("User " + userDto.Name + " deleted successfully", "Information"); } else { UIErrorHelper.ShowAlert ("Failed to delete User " + userDto.Name, "Information"); } Refresh (this, EventArgs.Empty); }); }