use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class SignInCommandHandler method signInIfNotSignedInInternal.
private static Mono<Boolean> signInIfNotSignedInInternal(Shell projectShell) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final IDeviceLoginUI deviceLoginUI = new DeviceLoginWindow(projectShell);
return Mono.create(sink -> AzureTaskManager.getInstance().runLater(() -> {
final AuthConfiguration auth;
try {
auth = showSignInWindowAndGetAuthConfiguration(projectShell);
} catch (InterruptedException e) {
sink.error(e);
return;
}
Single<AuthMethodDetails> single;
if (auth.getType() != AuthType.DEVICE_CODE) {
single = loginNonDeviceCodeSingle(auth);
} else {
single = loginDeviceCodeSingle().map(account -> {
AzureTaskManager.getInstance().runLater(() -> deviceLoginUI.promptDeviceCode(account.getDeviceCode()));
CompletableFuture<AuthMethodDetails> future = account.continueLogin().map(ac -> fromAccountEntity(ac.getEntity())).doFinally(signal -> deviceLoginUI.closePrompt()).toFuture();
deviceLoginUI.setFuture(future);
try {
return future.get();
} catch (Throwable ex) {
if (!(ex instanceof CancellationException)) {
ex.printStackTrace();
ErrorWindow.go(projectShell, ex.getMessage(), SIGN_IN_ERROR);
}
return new AuthMethodDetails();
}
});
}
single.subscribeOn(rx.schedulers.Schedulers.io()).subscribe(authMethodDetails -> {
if (authMethodManager.isSignedIn()) {
authMethodManager.setAuthMethodDetails(authMethodDetails);
}
sink.success(authMethodManager.isSignedIn());
}, sink::error);
}));
}
use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class AzurePanel method doOKAction.
@Override
public boolean doOKAction() {
final AzureConfiguration data = getData();
// set partial config to global config
final AzureConfiguration config = Azure.az().config();
config.setCloud(data.getCloud());
config.setTelemetryEnabled(data.getTelemetryEnabled());
config.setDatabasePasswordSaveType(data.getDatabasePasswordSaveType());
config.setFunctionCoreToolsPath(data.getFunctionCoreToolsPath());
final String userAgent = String.format(AzurePlugin.USER_AGENT, AzurePlugin.PLUGIN_VERSION, config.getTelemetryEnabled() ? config.getMachineId() : StringUtils.EMPTY);
config.setUserAgent(userAgent);
CommonSettings.setUserAgent(config.getUserAgent());
// we need to get rid of AuthMethodManager, using az.azure_account
if (AuthMethodManager.getInstance().isSignedIn()) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final String azureEnv = authMethodManager.getAuthMethodDetails().getAzureEnv();
final AzureEnvironment currentEnv = AzureEnvironmentUtils.stringToAzureEnvironment(azureEnv);
if (!Objects.equals(currentEnv, azureEnvironmentComboBox.getSelectedItem())) {
EventUtil.executeWithLog(ACCOUNT, SIGNOUT, (operation) -> {
authMethodManager.signOut();
});
}
}
if (StringUtils.isNotBlank(config.getCloud())) {
Azure.az(AzureCloud.class).setByName(config.getCloud());
}
AzureConfigInitializer.saveAzConfig();
return true;
}
use of com.microsoft.azuretools.authmanage.AuthMethodManager in project azure-tools-for-java by Microsoft.
the class SelectSubscriptionsAction method selectSubscriptions.
public static Single<List<SubscriptionDetail>> selectSubscriptions(Project project) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final AzureManager manager = authMethodManager.getAzureManager();
if (manager == null) {
return Single.fromCallable(() -> null);
}
final SubscriptionManager subscriptionManager = manager.getSubscriptionManager();
return loadSubscriptions(subscriptionManager, project).switchMap((subs) -> selectSubscriptions(project, subs)).toSingle().doOnSuccess((subs) -> Optional.ofNullable(subs).ifPresent(subscriptionManager::setSubscriptionDetails));
}
Aggregations