chelnak
10/4/2016 - 12:56 PM

Reset the password of a vRA local user principal with vRO

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;
	
}