public override void ExecuteCmdlet() { PasswordProfile profile = null; #pragma warning disable 0618 if (!string.IsNullOrEmpty(Password)) #pragma warning restore 0618 { profile = new PasswordProfile { #pragma warning disable 0618 Password = Password, #pragma warning restore 0618 ForceChangePasswordNextLogin = ForceChangePasswordNextLogin.IsPresent ? true : false }; } var userUpdateParameters = new UserUpdateParameters(EnableAccount, DisplayName, profile); ExecutionBlock(() => { if (ShouldProcess(target: UPNOrObjectId, action: string.Format("Updating properties for user with upn or object id '{0}'", UPNOrObjectId))) { WriteObject(ActiveDirectoryClient.UpdateUser(UPNOrObjectId, userUpdateParameters)); } }); }
/// <inheritdoc /> public async Task <User> Update(string id, UserUpdateParameters parameters) { var response = await ApiClient.PutAsJsonAsync($"users/{id}", parameters); if (response.IsSuccessStatusCode) { return(await GetById(id)); } throw new ApiException("Users.Update", response.StatusCode, await response.Content.ReadAsStringAsync()); }
/// <inheritdoc /> public async Task <User> Update(UserUpdateParameters parameters) { var response = await ApiClient.PostAsJsonAsync("Users/Update/", parameters); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsJsonAsync <User>()); } throw new ApiException("Users.Update", response.StatusCode, await response.Content.ReadAsStringAsync()); }
internal ActiveDirectoryUserImpl(UserInner innerObject, GraphRbacManager manager) : base(innerObject.DisplayName, innerObject) { this.manager = manager; this.createParameters = new UserCreateParameters { DisplayName = Name, AccountEnabled = true }; this.updateParameters = new UserUpdateParameters { DisplayName = Name }; }
public virtual async Task <Response> UpdateAsync(string upnOrObjectId, UserUpdateParameters parameters, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("UsersClient.Update"); scope.Start(); try { return(await RestClient.UpdateAsync(upnOrObjectId, parameters, cancellationToken).ConfigureAwait(false)); } catch (Exception e) { scope.Failed(e); throw; } }
public virtual Response Update(string upnOrObjectId, UserUpdateParameters parameters, CancellationToken cancellationToken = default) { using var scope = _clientDiagnostics.CreateScope("UsersClient.Update"); scope.Start(); try { return(RestClient.Update(upnOrObjectId, parameters, cancellationToken)); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task TestUserApiMethods() { // Create test user var userCreateParameters = new UserCreateParameters { FirstName = "TestUserApiMethods", LastName = "TestUserApiMethods", EmailAddress = $"TestUserApiMethods{Guid.NewGuid():N}@brightertools.com", Role = UserRole.Administrator, Password = "", WebLoginEnabled = false }; var userCreated = await _context.ApiClient.Users.Create(userCreateParameters); Assert.True(userCreated != null); // Get the user by id var retrievedUserById = await _context.ApiClient.Users.GetById(userCreated.Id, true); Assert.True(retrievedUserById != null && userCreated.Id == retrievedUserById.Id); // Update the user var userUpdateParameters = new UserUpdateParameters { Id = retrievedUserById.Id, FirstName = "updated", LastName = "updated", EmailAddress = userCreated.EmailAddress, Role = UserRole.Administrator, WebLoginEnabled = true }; var updatedUser = await _context.ApiClient.Users.Update(userUpdateParameters); // Get the user by email var retrievedUserByEmail = await _context.ApiClient.Users.GetByEmail(userCreated.EmailAddress); Assert.True(retrievedUserById != null && userCreated.Id == retrievedUserByEmail.Id); // Check the user is updated Assert.True(retrievedUserByEmail.FirstName == "updated"); // Delete the user await _context.ApiClient.Users.Delete(userCreated.Id); // Get the user by if to see if user exists var userExists = await _context.ApiClient.Users.GetById(userCreated.Id); Assert.True(userExists == null); }
internal async Task UpdateUser() { Printer.PrintStepTitle("Update User Details"); Console.Write("Enter a User ID:"); string id = Console.ReadLine(); if (id == "-1") { return; } var existingUser = await _apiClient.Users.GetById(id); Printer.PrintUser(existingUser); if (existingUser == null) { return; } Console.Write("Enter New Name:"); string newName = Console.ReadLine(); Console.Write("Enter New Lastname:"); string newLastName = Console.ReadLine(); Console.Write("Enter New Password (min 6 characters):"); string newPassword = Console.ReadLine(); Console.Write($"Set If User Can Login via mediamarkup.com (true / false):"); string webLoginInput = Console.ReadLine(); bool.TryParse(webLoginInput, out bool webLoginEnabled); var parameters = new UserUpdateParameters { FirstName = newName, LastName = newLastName, Password = newPassword, WebLoginEnabled = webLoginEnabled }; var updatedUser = await _apiClient.Users.Update(id, parameters); Printer.PrintUser(updatedUser); }
public override void ExecuteCmdlet() { PasswordProfile profile = null; if (Password != null && Password.Length > 0) { string decodedPassword = SecureStringExtensions.ConvertToString(Password); profile = new PasswordProfile { Password = decodedPassword, ForceChangePasswordNextLogin = ForceChangePasswordNextLogin.IsPresent ? true : false }; } var userUpdateParameters = new UserUpdateParameters { AccountEnabled = EnableAccount, DisplayName = DisplayName, PasswordProfile = profile }; ExecutionBlock(() => { if (this.IsParameterBound(c => c.InputObject)) { UPNOrObjectId = !string.IsNullOrEmpty(InputObject.UserPrincipalName) ? InputObject.UserPrincipalName : InputObject.Id.ToString(); } else if (this.IsParameterBound(c => c.UserPrincipalName)) { UPNOrObjectId = UserPrincipalName; } else if (this.IsParameterBound(c => c.ObjectId)) { UPNOrObjectId = ObjectId; } if (ShouldProcess(target: UPNOrObjectId, action: string.Format("Updating properties for user with upn or object id '{0}'", UPNOrObjectId))) { WriteObject(ActiveDirectoryClient.UpdateUser(UPNOrObjectId, userUpdateParameters)); } }); }
public static async Task UpdateUser() { Printer.PrintStepTitle("Updating user..."); var payload = new UserUpdateParameters { FirstName = "Updated Firstname", LastName = "Updated Lastname", WebLoginEnabled = false, Password = Guid.NewGuid().ToString() }; var updatedUser = await ApiClient.Users.Update(TestContainer.User.Id, payload); Assert.AreEqual(payload.FirstName, updatedUser.FirstName); Assert.AreEqual(payload.LastName, updatedUser.LastName); Assert.AreEqual(payload.WebLoginEnabled, updatedUser.WebLoginEnabled); Printer.Print("User updated!"); TestContainer.UpdateUser(updatedUser); }
public override void ExecuteCmdlet() { PasswordProfile profile = null; if(!string.IsNullOrEmpty(Password)) { profile = new PasswordProfile { Password = Password, ForceChangePasswordNextLogin = ForceChangePasswordNextLogin.IsPresent ? true : false }; } var userUpdateParameters = new UserUpdateParameters(EnableAccount, DisplayName, profile); ExecutionBlock(() => { if (ShouldProcess(target: UPNOrObjectId, action: string.Format("Updating properties for user with upn or object id '{0}'", UPNOrObjectId))) { WriteObject(ActiveDirectoryClient.UpdateUser(UPNOrObjectId, userUpdateParameters)); } }); }
public IActionResult Update(int id, [FromBody] UserUpdateParameters u) { try { var user = _repo.Get(id); if (user != null) { if (IsSuperAdmin(user)) { return(ReturnUserFriendlyError(Errors.SuperUserModificationForbidden)); } else { // Cambio en la propiedad "EsAdmin" solo puede ser hecha por un administrador if (user.IsAdmin != u.IsAdmin) { var currentUser = _securityHelper.GetCurrentUser(HttpContext); if (currentUser.IsAdmin) { user.IsAdmin = u.IsAdmin; user = _repo.Update(id, user); } } } return(Ok(BuildResponse(user))); } return(NotFound()); } catch { return(ReturnUserFriendlyError(Errors.Unknown)); } }
public override void ExecuteCmdlet() { PasswordProfile profile = null; if (Password != null && Password.Length > 0) { string decodedPassword = SecureStringExtensions.ConvertToString(Password); profile = new PasswordProfile { Password = decodedPassword, ForceChangePasswordNextLogin = ForceChangePasswordNextLogin.IsPresent ? true : false }; } var userUpdateParameters = new UserUpdateParameters(EnableAccount, DisplayName, profile); ExecutionBlock(() => { if (ShouldProcess(target: UPNOrObjectId, action: string.Format("Updating properties for user with upn or object id '{0}'", UPNOrObjectId))) { WriteObject(ActiveDirectoryClient.UpdateUser(UPNOrObjectId, userUpdateParameters)); } }); }
/// <summary> /// Updates specific user. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IUsersOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='uid'> /// Required. Identifier of the user. /// </param> /// <param name='parameters'> /// Required. Update parameters. /// </param> /// <param name='etag'> /// Required. ETag. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static Task <AzureOperationResponse> UpdateAsync(this IUsersOperations operations, string resourceGroupName, string serviceName, string uid, UserUpdateParameters parameters, string etag) { return(operations.UpdateAsync(resourceGroupName, serviceName, uid, parameters, etag, CancellationToken.None)); }
/// <summary> /// Updates an exisitng user. Reference: /// https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#UpdateUser /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='upnOrObjectId'> /// User object Id or user principal name to get user information. /// </param> /// <param name='parameters'> /// Parameters to update an exisitng user. /// </param> public static void Update(this IUsersOperations operations, string upnOrObjectId, UserUpdateParameters parameters) { Task.Factory.StartNew(s => ((IUsersOperations)s).UpdateAsync(upnOrObjectId, parameters), operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult(); }
private static async Task <IActiveDirectoryUser?> ProcessUserAsync(MyUser item, IActiveDirectoryUser[] list, // ReSharper disable once UnusedParameter.Local Azure.IAuthenticated authenticated, string password) { async Task ApplyPassword(IActiveDirectoryUser activeDirectoryUser) { if (item.UseDefaultPassword) { Log(3, $"Updating UseDefaultPassword: {activeDirectoryUser.UserPrincipalName}"); var respo = await authenticated.ActiveDirectoryUsers.Inner.UpdateWithHttpMessagesAsync( activeDirectoryUser.UserPrincipalName, new UserUpdateParameters() //{ // PasswordProfile = new PasswordProfile(password) // PasswordProfile = new PasswordProfile(SdkContext.RandomResourceName("Pa5$", 15)) // { // ForceChangePasswordNextLogin = false // } // } ); var cont = await respo.Response.Content.ReadAsStringAsync(); Log(3, $"Updating UseDefaultPassword Responce: {activeDirectoryUser.UserPrincipalName}: {respo.Response.StatusCode} {cont}"); } } Log(0, "==========================================="); Log(0, "Processing User"); Log(1, item); var cur = list.FirstOrDefault(x => x.UserPrincipalName == item.Upn); if (cur == null && !item.Delete) { Log(3, $"Creating User: {item.Upn}"); // var userCreateParameters = new UserCreateParameters() // { // MailNickname = item.Upn, // Surname = item.Surname, // GivenName = item.Givenname, // DisplayName = item.Displayname, // UserPrincipalName = item.Upn, // UserType = UserType.Member, // PasswordProfile = new PasswordProfile(SdkContext.RandomResourceName("Pa5$", 15)) // // { // // Password = SdkContext.RandomResourceName("Pa5$", // // 15), // Guid.NewGuid().ToString(), // password, // // ForceChangePasswordNextLogin = false // // } // }; // userCreateParameters.Validate(); // // // var inner = await authenticated.ActiveDirectoryUsers.Inner.CreateWithHttpMessagesAsync( // userCreateParameters // ); // // // Policy.Handle<Exception>() // .RetryAsync(5, // async (exception, i) => // { // cur = await authenticated.ActiveDirectoryUsers.GetByIdAsync(inner.Body.ObjectId); // // if (cur == null) // throw new Exception(); // }); cur = await authenticated.ActiveDirectoryUsers .Define(item.Displayname) .WithUserPrincipalName(item.Upn) // .WithPassword(password) .WithPassword(SdkContext.RandomResourceName("Pa5$", 15)) .WithPromptToChangePasswordOnLogin(false) .CreateAsync(); await ApplyPassword(cur); } if (cur != null) { if (item.Delete) { Log(3, $"Deleting User: {cur.UserPrincipalName}"); await authenticated.ActiveDirectoryUsers.DeleteByIdAsync(cur.Id); return(null); } Log(3, $"Updating User: {cur.UserPrincipalName}"); Log(3, cur); var parameters = new UserUpdateParameters { Surname = item.Surname, GivenName = item.Givenname, DisplayName = item.Displayname }; // if (item.UseDefaultPassword) // { // parameters.AdditionalProperties = new Dictionary<string, object>(); // // // parameters.AdditionalProperties.Add("UseDefaultPassword", item.UseDefaultPassword.ToString()); // } await authenticated.ActiveDirectoryUsers.Inner.UpdateWithHttpMessagesAsync(cur.UserPrincipalName, parameters); // await ApplyPassword(cur); } if (cur != null) { Log(0, $"Finished Processing: {cur.UserPrincipalName}"); } return(cur); }
/// <summary> /// Updates a user. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='upnOrObjectId'> /// The object ID or principal name of the user to update. /// </param> /// <param name='parameters'> /// Parameters to update an existing user. /// </param> public static void Update(this IUsersOperations operations, string upnOrObjectId, UserUpdateParameters parameters) { operations.UpdateAsync(upnOrObjectId, parameters).GetAwaiter().GetResult(); }
public PSADUser UpdateUser(string upnOrObjectId, UserUpdateParameters userUpdateParam) { GraphClient.Users.Update(upnOrObjectId, userUpdateParam); return(GraphClient.Users.Get(upnOrObjectId).ToPSADUser()); }
public PSADUser UpdateUser(string upnOrObjectId, UserUpdateParameters userUpdateParam) { GraphClient.Users.Update(upnOrObjectId, userUpdateParam); return GraphClient.Users.Get(upnOrObjectId).ToPSADUser(); }
/// <summary> /// Updates the details of the user specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='userId'> /// User identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <UserContract> UpdateAsync(this IUserOperations operations, string resourceGroupName, string serviceName, string userId, UserUpdateParameters parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, userId, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Updates the details of the user specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='userId'> /// User identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> public static UserContract Update(this IUserOperations operations, string resourceGroupName, string serviceName, string userId, UserUpdateParameters parameters, string ifMatch) { return(operations.UpdateAsync(resourceGroupName, serviceName, userId, parameters, ifMatch).GetAwaiter().GetResult()); }
/// <summary> /// Updates the details of the user specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='uid'> /// User identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this IUserOperations operations, string resourceGroupName, string serviceName, string uid, UserUpdateParameters parameters, string ifMatch, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(resourceGroupName, serviceName, uid, parameters, ifMatch, null, cancellationToken).ConfigureAwait(false)).Dispose(); }
/// <summary> /// Updates the details of the user specified by its identifier. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='resourceGroupName'> /// The name of the resource group. /// </param> /// <param name='serviceName'> /// The name of the API Management service. /// </param> /// <param name='uid'> /// User identifier. Must be unique in the current API Management service /// instance. /// </param> /// <param name='parameters'> /// Update parameters. /// </param> /// <param name='ifMatch'> /// ETag of the Entity. ETag should match the current entity state from the /// header response of the GET request or it should be * for unconditional /// update. /// </param> public static void Update(this IUserOperations operations, string resourceGroupName, string serviceName, string uid, UserUpdateParameters parameters, string ifMatch) { operations.UpdateAsync(resourceGroupName, serviceName, uid, parameters, ifMatch).GetAwaiter().GetResult(); }
/// <summary> /// Updates specific user. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.ApiManagement.IUsersOperations. /// </param> /// <param name='resourceGroupName'> /// Required. The name of the resource group. /// </param> /// <param name='serviceName'> /// Required. The name of the Api Management service. /// </param> /// <param name='uid'> /// Required. Identifier of the user. /// </param> /// <param name='parameters'> /// Required. Update parameters. /// </param> /// <param name='etag'> /// Required. ETag. /// </param> /// <returns> /// A standard service response including an HTTP status code and /// request ID. /// </returns> public static AzureOperationResponse Update(this IUsersOperations operations, string resourceGroupName, string serviceName, string uid, UserUpdateParameters parameters, string etag) { return(Task.Factory.StartNew((object s) => { return ((IUsersOperations)s).UpdateAsync(resourceGroupName, serviceName, uid, parameters, etag); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }
/// <summary> /// Updates a user. /// </summary> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='upnOrObjectId'> /// The object ID or principal name of the user to update. /// </param> /// <param name='parameters'> /// Parameters to update an existing user. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task UpdateAsync(this IUsersOperations operations, string upnOrObjectId, UserUpdateParameters parameters, CancellationToken cancellationToken = default(CancellationToken)) { (await operations.UpdateWithHttpMessagesAsync(upnOrObjectId, parameters, null, cancellationToken).ConfigureAwait(false)).Dispose(); }