use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class ApplicationInsightsPreferencePage method signInOutBtnListener.
private void signInOutBtnListener() {
try {
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignedIn = authMethodManager.isSignedIn();
if (isSignedIn) {
SignOutCommandHandler.doSignOut(PluginUtil.getParentShell());
} else {
SignInCommandHandler.doSignIn(PluginUtil.getParentShell());
}
signInOutBtn.setImage(PluginUtil.getImage(authMethodManager.isSignedIn() ? ICON_SIGNOUT : ICON_SIGNIN));
tableViewer.refresh();
} catch (Exception ex) {
Activator.getDefault().log(ex.getMessage(), ex);
}
}
use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method doSignIn.
public static boolean doSignIn(Shell shell) {
try {
AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn)
return true;
SignInDialog d = SignInDialog.go(shell, authMethodManager.getAuthMethodDetails());
if (null != d) {
AuthMethodDetails authMethodDetailsUpdated = d.getAuthMethodDetails();
authMethodManager.setAuthMethodDetails(authMethodDetailsUpdated);
SelectSubsriptionsCommandHandler.onSelectSubscriptions(shell);
authMethodManager.notifySignInEventListener();
}
return authMethodManager.isSignedIn();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
use of com.microsoft.azuretools.authmanage.AuthMethodManager 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.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class Program method main.
@SuppressWarnings("unused")
public static void main(String[] args) {
LogManager.getLogManager().reset();
try {
try {
if (CommonSettings.getUiFactory() == null)
CommonSettings.setUiFactory(new UIFactory());
String wd = "AuthManageWorkingDir";
Path dirPath = Paths.get(System.getProperty("user.home"), wd);
if (!Files.exists(dirPath)) {
Files.createDirectory(dirPath);
}
CommonSettings.settingsBaseDir = dirPath.toString();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("--- Service Principals section ---");
// create with sp
//final File credFile = new File(System.getProperty("user.home") + "/ServicePrincipals/srv-pri.azureauth-778");
String path = "C:\\Users\\shch\\_ServicePrincipalsTest\\sp5\\sp-9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef_20161202161437.azureauth";
final File credFile = new File("C:\\Users\\shch\\_ServicePrincipalsTest\\sp5\\sp-9657ab5d-4a4a-4fd2-ae7a-4cd9fbd030ef_20161202161437.azureauth");
AuthMethodDetails amd = new AuthMethodDetails();
amd.setAuthMethod(AuthMethod.SP);
amd.setCredFilePath(path);
AuthMethodManager amm = AuthMethodManager.getInstance();
amm.setAuthMethodDetails(amd);
AzureManager am = amm.getAzureManager();
SubscriptionManager subscriptionManager = am.getSubscriptionManager();
List<SubscriptionDetail> sdl = subscriptionManager.getSubscriptionDetails();
//AzureManager spManager = new ServicePrincipalAzureManager(credFile);
//printResourceGroups(spManager);
//printSubscriptions(spManager);
// create with token
//AzureManager atManager = new AccessTokenAzureManager(Constants.tenant);
//AzureManager atManager = new AccessTokenAzureManager();
//SubscriptionManager.getInstance().showSubscriptionDialog();
// AdAuthManager adAuthManager = AdAuthManager.getInstance();
System.out.println("=== Access token section ---");
// AuthenticationResult res = AdAuthManager.getInstance().signIn();
// UserInfo ui = res.getUserInfo();
// Setup working dir
String wd = "AuthManageWorkingDir";
Path dirPath = Paths.get(System.getProperty("user.home"), wd);
if (!Files.exists(dirPath)) {
Files.createDirectory(dirPath);
}
CommonSettings.settingsBaseDir = dirPath.toString();
// Setup uiFactory
if (CommonSettings.getUiFactory() == null)
CommonSettings.setUiFactory(new UIFactory());
//testReporter(dirPath.toString());
//graphApiAction();
//createSp();
// AzureManager am = AuthMethodManager.getInstance().getAzureManager(AuthMethod.AD);
// if (am == null) {
// return;
// }
//
// System.out.println("-- Subscription list ---");
// printSubscriptions(am);
// sidList = AdAuthManager.getInstance().getAccountSidList();
// for (String sid : AdAuthManager.getInstance().getAccountSidList()) {
// System.out.println(" - " + sid);
// }
//printResourceGroups(am);
//printTenants(atManager);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.exit(1);
}
}
use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method onAzureSignIn.
private void onAzureSignIn(Shell shell) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
boolean isSignIn = authMethodManager.isSignedIn();
if (isSignIn) {
boolean res = showYesNoDialog(shell, "Azure Sign Out", SignOutCommandHandler.getSignOutWarningMessage(authMethodManager));
if (res) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
} else {
signInIfNotSignedIn(shell).subscribe(isLoggedIn -> {
if (isLoggedIn) {
AzureAccount az = Azure.az(AzureAccount.class);
AzureTaskManager.getInstance().runOnPooledThread(() -> authMethodManager.getAzureManager().getSelectedSubscriptions().stream().limit(5).forEach(s -> {
// pre-load regions;
az.listRegions(s.getId());
}));
}
});
}
}
Aggregations