use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class SignOutCommandHandler method doSignOut.
public static void doSignOut(Shell shell) {
try {
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
String artifact = (authMethodManager.getAuthMethod() == AuthMethod.AD) ? "Signed in as " + authMethodManager.getAuthMethodDetails().getAccountEmail() : "Signed in using file \"" + authMethodManager.getAuthMethodDetails().getCredFilePath() + "\"";
MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION | SWT.YES | SWT.NO);
messageBox.setMessage(artifact + "\n" + "Do you really want to sign out?");
messageBox.setText("Azure Sign Out");
int response = messageBox.open();
if (response == SWT.YES) {
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
adAuthManager.signOut();
}
authMethodManager.signOut();
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class SignInWindow method doSignIn.
private void doSignIn() {
try {
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn()) {
doSingOut();
}
signInAsync();
accountEmail = adAuthManager.getAccountEmail();
} catch (Exception ex) {
ex.printStackTrace();
//LOGGER.error("doSignIn", ex);
ErrorWindow.show(project, ex.getMessage(), "Sign In Error");
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method onAzureSignIn.
public static void onAzureSignIn(Project project) {
JFrame frame = WindowManager.getInstance().getFrame(project);
try {
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn) {
String artifact = (authMethodManager.getAuthMethod() == AuthMethod.AD) ? "Signed in as " + authMethodManager.getAuthMethodDetails().getAccountEmail() : "Signed in using file \"" + authMethodManager.getAuthMethodDetails().getCredFilePath() + "\"";
int res = JOptionPane.showConfirmDialog(frame, artifact + "\n" + "Do you really want to sign out?", "Azure Sign Out", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, new ImageIcon("icons/azure.png"));
if (res == JOptionPane.OK_OPTION) {
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (adAuthManager.isSignedIn())
adAuthManager.signOut();
authMethodManager.signOut();
}
} else {
// SignInWindow w = SignInWindow.go(authMethodManager.getAuthMethodDetails(), project);
// if (w != null) {
// AuthMethodDetails authMethodDetailsUpdated = w.getAuthMethodDetails();
// authMethodManager.setAuthMethodDetails(authMethodDetailsUpdated);
// SelectSubscriptionsAction.onShowSubscriptions(project);
// }
doSignIn(authMethodManager, project);
}
} catch (Exception ex) {
ex.printStackTrace();
//LOGGER.error("onAzureSignIn", ex);
ErrorWindow.show(project, ex.getMessage(), "AzureSignIn Action Error");
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager in project azure-tools-for-java by Microsoft.
the class Program method graphApiAction.
@SuppressWarnings("unused")
private static void graphApiAction() throws Exception {
AdAuthManager adAuthManager = AdAuthManager.getInstance();
if (!adAuthManager.isSignedIn()) {
adAuthManager.signIn();
}
String request = "tenantDetails";
List<com.microsoft.azure.management.resources.Tenant> tl = AccessTokenAzureManager.getTenants("common");
for (com.microsoft.azure.management.resources.Tenant t : tl) {
String tid = t.tenantId();
System.out.println("==> tenant ID: " + tid);
String tenantId = tid;
try {
GraphRestHelper grh = new GraphRestHelper(tenantId);
String resp = grh.doGet(request, null);
System.out.println("Graph response:" + resp);
} catch (Exception ex) {
System.out.println("GraphApiAction ex: " + ex.getMessage());
}
}
}
use of com.microsoft.azuretools.authmanage.AdAuthManager 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