Skip to content

Instantly share code, notes, and snippets.

@chelnak
Created October 4, 2016 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chelnak/2a3d3c5ffa1e4a9b5d67fe04a3cb078d to your computer and use it in GitHub Desktop.
Save chelnak/2a3d3c5ffa1e4a9b5d67fe04a3cb078d to your computer and use it in GitHub Desktop.
Reset the password of a vRA local user principal with vRO
/*
- Reset the password of a local user principal
- Input: vCACCAFEHost [vCACCAFE:vCACHost]
- Input: principalId [String]
- Input: password [SecureString]
- Input: confirmPassword [SecureString]
- Output: [Void]
*/
var tenant = vCACCAFEHost.tenant;
var authenticationClient = vCACCAFEHost.createAuthenticationClient();
var authenticationPrincipalService = authenticationClient.getAuthenticationPrincipalService();
try {
//Get the principal
var principal = authenticationPrincipalService.getPrincipal(tenant,principalId);
//Simple confirmation that both passwords match
if (password != confirmPassword) {
throw "Passwords do not match";
}
//Set the password on the vCACCAFEUser object
principal.setPassword(password);
//Update the principal
System.log("Setting password for " + principalId);
authenticationPrincipalService.updateLocalUser(principal);
System.log("Success");
} catch (e) {
throw "An error occured when updating principal: " +e;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment