use of com.microsoft.azuretools.authmanage.srvpri.step.Status in project azure-tools-for-java by Microsoft.
the class SrvPriCreationStatusDialog method createServicePrincipalAsync.
private void createServicePrincipalAsync() {
try {
class StatusTask implements IRunnableWithProgress, IListener<Status> {
IProgressMonitor progressIndicator = null;
@Override
public void listen(Status status) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
if (progressIndicator != null) {
progressIndicator.setTaskName(status.getAction());
}
// if only action was set in the status - the info for progress indicator only - igonre for table
if (status.getResult() != null) {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { status.getAction(), status.getResult().toString(), status.getDetails() });
}
}
});
}
@Override
public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
progressIndicator = monitor;
monitor.beginTask("Creating Service Principal...", IProgressMonitor.UNKNOWN);
for (String tid : tidSidsMap.keySet()) {
if (monitor.isCanceled()) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { "!!! Canceled by user" });
}
});
return;
}
List<String> sidList = tidSidsMap.get(tid);
if (!sidList.isEmpty()) {
try {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
TableItem item = new TableItem(table, SWT.NULL);
item.setText(new String[] { "tenant ID: " + tid + " ===" });
}
});
Date now = new Date();
String suffix = new SimpleDateFormat("yyyyMMddHHmmss").format(now);
;
String authFilepath = SrvPriManager.createSp(tid, sidList, suffix, this, destinationFolder);
if (authFilepath != null) {
Display.getDefault().asyncExec(new Runnable() {
@Override
public void run() {
listCreatedFiles.add(authFilepath);
listCreatedFiles.setSelection(0);
}
});
}
} catch (Exception ex) {
ex.printStackTrace();
LOG.log(new org.eclipse.core.runtime.Status(IStatus.ERROR, Activator.PLUGIN_ID, "run@ProgressDialog@createServicePrincipalAsync@SrvPriCreationStatusDialog", ex));
}
}
}
}
}
new ProgressMonitorDialog(this.getShell()).run(true, true, new StatusTask());
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of com.microsoft.azuretools.authmanage.srvpri.step.Status in project azure-tools-for-java by Microsoft.
the class Program method createSp.
@SuppressWarnings("unused")
private static void createSp() {
try {
LogManager.getLogManager().reset();
boolean doFirst = false;
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (doFirst) {
if (adAuthManager.isSignedIn()) {
adAuthManager.signOut();
//AuthMethodManager.getInstance().clean(AuthMethod.AD);
}
adAuthManager.signIn();
} else {
if (!adAuthManager.isSignedIn())
adAuthManager.signIn();
}
Map<String, List<String>> tsm = adAuthManager.getAccountTenantsAndSubscriptions();
for (String tid : tsm.keySet()) {
List<String> sids = tsm.get(tid);
if (!sids.isEmpty()) {
try {
SrvPriManager.createSp(tid, sids, "808", new IListener<Status>() {
@Override
public void listen(Status message) {
System.out.format(">> Status report: %s\t:\t%s\t:\t%s\n", message.getAction(), message.getResult(), message.getDetails());
}
}, null);
} catch (Exception t1) {
System.out.println("CreateServicePrincipalsAction ex: " + t1.getMessage());
t1.printStackTrace();
}
}
}
} catch (Exception t) {
t.printStackTrace();
}
}
Aggregations