public static void impersonateUserAndSetClientFactory(String canonicalName, String domainName, ServiceClientFactory serviceClientFactory,ResourceManager resourceManager)
throws UMException {
AuthenticationManagerServiceClient authClient = new AuthenticationManagerServiceClient(serviceClientFactory);
AuthResult authResultAdmin = authClient
.authenticate(resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_CREDENTIAL_USERNAME), resourceManager.getPropValue(ServiceClientFactoryProperties.DSC_CREDENTIAL_PASSWORD).getBytes());
Context context = new Context();
context.initPrincipal(authResultAdmin);
AuthResult authResult = authClient.getAuthResultOnBehalfOfUser(
canonicalName, domainName, context);
Context impersonateContext = new Context();
impersonateContext.initPrincipal(authResult);
serviceClientFactory.setContext(impersonateContext);
}