use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class SignInDialog method doCreateServicePrincipal.
private void doCreateServicePrincipal() {
setErrorMessage(null);
AdAuthManager adAuthManager = null;
try {
adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
adAuthManager.signOut();
}
signInAsync();
if (!adAuthManager.isSignedIn()) {
// canceled by the user
System.out.println(">> Canceled by the user");
return;
}
AccessTokenAzureManager accessTokenAzureManager = new AccessTokenAzureManager();
SubscriptionManager subscriptionManager = accessTokenAzureManager.getSubscriptionManager();
IRunnableWithProgress op = new IRunnableWithProgress() {
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
monitor.beginTask("Getting Subscription List...", IProgressMonitor.UNKNOWN);
try {
subscriptionManager.getSubscriptionDetails();
} catch (Exception ex) {
System.out.println("run@ProgressDialog@doCreateServicePrincipal@SignInDialog: " + ex.getMessage());
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@doCreateServicePrincipal@SignInDialogg", ex));
}
}
};
new ProgressMonitorDialog(this.getShell()).run(true, false, op);
SrvPriSettingsDialog d = SrvPriSettingsDialog.go(this.getShell(), subscriptionManager.getSubscriptionDetails());
List<SubscriptionDetail> subscriptionDetailsUpdated;
String destinationFolder;
if (d != null) {
subscriptionDetailsUpdated = d.getSubscriptionDetails();
destinationFolder = d.getDestinationFolder();
} else {
System.out.println(">> Canceled by the user");
return;
}
Map<String, List<String>> tidSidsMap = new HashMap<>();
for (SubscriptionDetail sd : subscriptionDetailsUpdated) {
if (sd.isSelected()) {
System.out.format(">> %s\n", sd.getSubscriptionName());
String tid = sd.getTenantId();
List<String> sidList;
if (!tidSidsMap.containsKey(tid)) {
sidList = new LinkedList<>();
} else {
sidList = tidSidsMap.get(tid);
}
sidList.add(sd.getSubscriptionId());
tidSidsMap.put(tid, sidList);
}
}
SrvPriCreationStatusDialog d1 = SrvPriCreationStatusDialog.go(this.getShell(), tidSidsMap, destinationFolder);
if (d1 == null) {
System.out.println(">> Canceled by the user");
return;
}
String path = d1.getSelectedAuthFilePath();
if (path == null) {
System.out.println(">> No file was created");
return;
}
textAuthenticationFilePath.setText(path);
fileDialog.setFilterPath(destinationFolder);
} catch (Exception ex) {
ex.printStackTrace();
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "doCreateServicePrincipal@SignInDialog", ex));
} finally {
if (adAuthManager != null) {
adAuthManager.signOut();
}
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class SignInDialog method doSignIn.
private void doSignIn() {
try {
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
doSignOut();
}
signInAsync();
accountEmail = adAuthManager.getAccountEmail();
} catch (IOException | InvocationTargetException | InterruptedException ex) {
System.out.println("doSignIn@SingInDialog: " + ex.getMessage());
ex.printStackTrace();
LOG.log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, "doSignIn@SingInDialog", ex));
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class SignInWindow method doCreateServicePrincipal.
private void doCreateServicePrincipal() {
AdAuthManager adAuthManager = null;
try {
adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
adAuthManager.signOut();
}
signInAsync();
if (!adAuthManager.isSignedIn()) {
// canceled by the user
System.out.println(">> Canceled by the user");
return;
}
AccessTokenAzureManager accessTokenAzureManager = new AccessTokenAzureManager();
SubscriptionManager subscriptionManager = accessTokenAzureManager.getSubscriptionManager();
ProgressManager.getInstance().run(new Task.Modal(project, "Load Subscriptions Progress", true) {
@Override
public void run(ProgressIndicator progressIndicator) {
progressIndicator.setText("Loading subscriptions...");
try {
progressIndicator.setIndeterminate(true);
subscriptionManager.getSubscriptionDetails();
} catch (Exception ex) {
ex.printStackTrace();
//LOGGER.error("doCreateServicePrincipal::Task.Modal", ex);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
ErrorWindow.show(project, ex.getMessage(), "Load Subscription Error");
}
});
}
}
});
SrvPriSettingsDialog d = SrvPriSettingsDialog.go(subscriptionManager.getSubscriptionDetails(), project);
List<SubscriptionDetail> subscriptionDetailsUpdated;
String destinationFolder;
if (d != null) {
subscriptionDetailsUpdated = d.getSubscriptionDetails();
destinationFolder = d.getDestinationFolder();
} else {
System.out.println(">> Canceled by the user");
return;
}
Map<String, List<String>> tidSidsMap = new HashMap<>();
for (SubscriptionDetail sd : subscriptionDetailsUpdated) {
if (sd.isSelected()) {
System.out.format(">> %s\n", sd.getSubscriptionName());
String tid = sd.getTenantId();
List<String> sidList;
if (!tidSidsMap.containsKey(tid)) {
sidList = new LinkedList<>();
} else {
sidList = tidSidsMap.get(tid);
}
sidList.add(sd.getSubscriptionId());
tidSidsMap.put(tid, sidList);
}
}
SrvPriCreationStatusDialog d1 = SrvPriCreationStatusDialog.go(tidSidsMap, destinationFolder, project);
if (d1 == null) {
System.out.println(">> Canceled by the user");
return;
}
String path = d1.getSelectedAuthFilePath();
if (path == null) {
System.out.println(">> No file was created");
return;
}
authFileTextField.setText(path);
fileChooser.setCurrentDirectory(new File(destinationFolder));
} catch (Exception ex) {
ex.printStackTrace();
//LOGGER.error("doCreateServicePrincipal", ex);
ErrorWindow.show(project, ex.getMessage(), "Get Subscription Error");
} finally {
if (adAuthManager != null) {
try {
System.out.println(">> Signing out...");
adAuthManager.signOut();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
Aggregations