Implement ResetPassword and Unlock for PersonUser accounts.
This commit is contained in:
@@ -439,6 +439,12 @@ function Set-PersonUser {
|
|||||||
.PARAMETER Remove
|
.PARAMETER Remove
|
||||||
Specifies user will be removed from the spcified group.
|
Specifies user will be removed from the spcified group.
|
||||||
|
|
||||||
|
.PARAMETER Unlock
|
||||||
|
Specifies user will be unloacked.
|
||||||
|
|
||||||
|
.PARAMETER NewPassword
|
||||||
|
Specifies new password for the specified user.
|
||||||
|
|
||||||
.PARAMETER Server
|
.PARAMETER Server
|
||||||
Specifies the vSphere Sso Admin Server on which you want to run the cmdlet.
|
Specifies the vSphere Sso Admin Server on which you want to run the cmdlet.
|
||||||
If not specified the servers available in $global:DefaultSsoAdminServers variable will be used.
|
If not specified the servers available in $global:DefaultSsoAdminServers variable will be used.
|
||||||
@@ -451,7 +457,17 @@ function Set-PersonUser {
|
|||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Set-PersonUser -User $myPersonUser -Group $myExampleGroup -Remove -Server $ssoAdminConnection
|
Set-PersonUser -User $myPersonUser -Group $myExampleGroup -Remove -Server $ssoAdminConnection
|
||||||
|
|
||||||
Removec $myPersonUser from $myExampleGroup
|
Removes $myPersonUser from $myExampleGroup
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Set-PersonUser -User $myPersonUser -Unlock -Server $ssoAdminConnection
|
||||||
|
|
||||||
|
Unlocks $myPersonUser
|
||||||
|
|
||||||
|
.EXAMPLE
|
||||||
|
Set-PersonUser -User $myPersonUser -NewPassword 'MyBrandNewPa$$W0RD' -Server $ssoAdminConnection
|
||||||
|
|
||||||
|
Resets $myPersonUser password
|
||||||
#>
|
#>
|
||||||
[CmdletBinding(ConfirmImpact='Medium')]
|
[CmdletBinding(ConfirmImpact='Medium')]
|
||||||
param(
|
param(
|
||||||
@@ -491,6 +507,21 @@ function Set-PersonUser {
|
|||||||
[switch]
|
[switch]
|
||||||
$Remove,
|
$Remove,
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
ParameterSetName = 'ResetPassword',
|
||||||
|
Mandatory=$true,
|
||||||
|
HelpMessage='New password for the specified user.')]
|
||||||
|
[ValidateNotNull()]
|
||||||
|
[string]
|
||||||
|
$NewPassword,
|
||||||
|
|
||||||
|
[Parameter(
|
||||||
|
ParameterSetName = 'UnlockUser',
|
||||||
|
Mandatory=$true,
|
||||||
|
HelpMessage='Specifies to unlock user account.')]
|
||||||
|
[switch]
|
||||||
|
$Unlock,
|
||||||
|
|
||||||
[Parameter(
|
[Parameter(
|
||||||
Mandatory=$false,
|
Mandatory=$false,
|
||||||
ValueFromPipeline=$false,
|
ValueFromPipeline=$false,
|
||||||
@@ -525,6 +556,18 @@ function Set-PersonUser {
|
|||||||
Write-Output $User
|
Write-Output $User
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($Unlock) {
|
||||||
|
$result = $connection.Client.UnlockPersonUser($User)
|
||||||
|
if ($result) {
|
||||||
|
Write-Output $User
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($NewPassword) {
|
||||||
|
$connection.Client.ResetPersonUserPassword($User, $NewPassword)
|
||||||
|
Write-Output $User
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -115,6 +115,30 @@ namespace VMware.vSphere.SsoAdminClient.Tests
|
|||||||
Assert.IsTrue(addActual);
|
Assert.IsTrue(addActual);
|
||||||
Assert.IsTrue(removeActual);
|
Assert.IsTrue(removeActual);
|
||||||
|
|
||||||
|
// Cleanup
|
||||||
|
ssoAdminClient.DeleteLocalUser(
|
||||||
|
newUser);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void ResetUserPassword() {
|
||||||
|
// Arrange
|
||||||
|
var ssoAdminClient = new SsoAdminClient(_vc, _user, _password, new AcceptAllX509CertificateValidator());
|
||||||
|
|
||||||
|
var expectedUserName = "test-user6";
|
||||||
|
var expectedPassword = "te$tPa$sW0rd";
|
||||||
|
var updatePassword = "TE$tPa$sW0rd";
|
||||||
|
var newUser = ssoAdminClient.CreateLocalUser(
|
||||||
|
expectedUserName,
|
||||||
|
expectedPassword);
|
||||||
|
|
||||||
|
// Act
|
||||||
|
// Assert
|
||||||
|
Assert.DoesNotThrow(() => {
|
||||||
|
ssoAdminClient.ResetPersonUserPassword(newUser, updatePassword);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
ssoAdminClient.DeleteLocalUser(
|
ssoAdminClient.DeleteLocalUser(
|
||||||
newUser);
|
newUser);
|
||||||
|
|||||||
@@ -302,6 +302,42 @@ namespace VMware.vSphere.SsoAdminClient
|
|||||||
},
|
},
|
||||||
group.Name)).Result;
|
group.Name)).Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void ResetPersonUserPassword(PersonUser user, string newPassword) {
|
||||||
|
// Create Authorization Invocation Context
|
||||||
|
var authorizedInvocationContext =
|
||||||
|
CreateAuthorizedInvocationContext();
|
||||||
|
|
||||||
|
// Invoke SSO Admin ResetLocalPersonUserPasswordAsync operation
|
||||||
|
authorizedInvocationContext.
|
||||||
|
InvokeOperation(() =>
|
||||||
|
_ssoAdminBindingClient.ResetLocalPersonUserPasswordAsync(
|
||||||
|
new ManagedObjectReference {
|
||||||
|
type = "SsoAdminPrincipalManagementService",
|
||||||
|
Value = "principalManagementService"
|
||||||
|
},
|
||||||
|
user.Name,
|
||||||
|
newPassword)).Wait();
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool UnlockPersonUser(PersonUser user) {
|
||||||
|
// Create Authorization Invocation Context
|
||||||
|
var authorizedInvocationContext =
|
||||||
|
CreateAuthorizedInvocationContext();
|
||||||
|
|
||||||
|
// Invoke SSO Admin UnlockUserAccountAsync operation
|
||||||
|
return authorizedInvocationContext.
|
||||||
|
InvokeOperation(() =>
|
||||||
|
_ssoAdminBindingClient.UnlockUserAccountAsync(
|
||||||
|
new ManagedObjectReference {
|
||||||
|
type = "SsoAdminPrincipalManagementService",
|
||||||
|
Value = "principalManagementService"
|
||||||
|
},
|
||||||
|
new SsoPrincipalId {
|
||||||
|
name = user.Name,
|
||||||
|
domain = user.Domain
|
||||||
|
})).Result;
|
||||||
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -262,7 +262,7 @@ Describe "PersonUser Tests" {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Set-PersonUser Add/Remove Group" {
|
Context "Set-PersonUser" {
|
||||||
It 'Adds person user to group' {
|
It 'Adds person user to group' {
|
||||||
# Arrange
|
# Arrange
|
||||||
$userName = "TestAddGroupPersonUserName"
|
$userName = "TestAddGroupPersonUserName"
|
||||||
@@ -334,6 +334,61 @@ Describe "PersonUser Tests" {
|
|||||||
# Assert
|
# Assert
|
||||||
$actual | Should Not Be $null
|
$actual | Should Not Be $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It 'Resets person user password' {
|
||||||
|
# Arrange
|
||||||
|
$userName = "TestResetPassPersonUserName"
|
||||||
|
$userPassword = '$tr0NG_TestPa$$w0rd'
|
||||||
|
$newPassword = 'Update_TestPa$$w0rd'
|
||||||
|
$connection = Connect-SsoAdminServer `
|
||||||
|
-Server $VcAddress `
|
||||||
|
-User $User `
|
||||||
|
-Password $Password `
|
||||||
|
-SkipCertificateCheck
|
||||||
|
|
||||||
|
$personUserToUpdate = New-PersonUser `
|
||||||
|
-UserName $userName `
|
||||||
|
-Password $userPassword `
|
||||||
|
-Server $connection
|
||||||
|
|
||||||
|
$script:usersToCleanup += $personUserToUpdate
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = Set-PersonUser `
|
||||||
|
-User $personUserToUpdate `
|
||||||
|
-NewPassword $newPassword `
|
||||||
|
-Server $connection
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should Not Be $null
|
||||||
|
}
|
||||||
|
|
||||||
|
It 'Unlocks not locked person user' {
|
||||||
|
# Arrange
|
||||||
|
$userName = "TestResetPassPersonUserName"
|
||||||
|
$userPassword = '$tr0NG_TestPa$$w0rd'
|
||||||
|
$connection = Connect-SsoAdminServer `
|
||||||
|
-Server $VcAddress `
|
||||||
|
-User $User `
|
||||||
|
-Password $Password `
|
||||||
|
-SkipCertificateCheck
|
||||||
|
|
||||||
|
$personUserToUpdate = New-PersonUser `
|
||||||
|
-UserName $userName `
|
||||||
|
-Password $userPassword `
|
||||||
|
-Server $connection
|
||||||
|
|
||||||
|
$script:usersToCleanup += $personUserToUpdate
|
||||||
|
|
||||||
|
# Act
|
||||||
|
$actual = Set-PersonUser `
|
||||||
|
-User $personUserToUpdate `
|
||||||
|
-Unlock `
|
||||||
|
-Server $connection
|
||||||
|
|
||||||
|
# Assert
|
||||||
|
$actual | Should Be $null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Context "Remove-PersonUser" {
|
Context "Remove-PersonUser" {
|
||||||
|
|||||||
Reference in New Issue
Block a user