use of com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration in project azure-tools-for-java by Microsoft.
the class ServicePrincipalLoginDialog method json2UIComponents.
private void json2UIComponents() {
if (txtJson.isDisposed()) {
return;
}
try {
String json = this.txtJson.getText();
Map<String, String> map = JsonUtils.fromJson(json, HashMap.class);
if (map == null) {
return;
}
AuthConfiguration newData = new AuthConfiguration();
if (map.containsKey("appId")) {
newData.setClient(StringUtils.defaultString(map.get("appId")));
}
if (map.containsKey("tenant")) {
newData.setTenant(StringUtils.defaultString(map.get("tenant")));
}
if (map.containsKey("password")) {
newData.setKey(isPlaceHolder(map.get("password")) ? this.txtPassword.getText() : map.get("password"));
}
if (map.containsKey("fileWithCertAndPrivateKey")) {
newData.setCertificate(StringUtils.defaultString(map.get("fileWithCertAndPrivateKey")));
}
setData(newData);
} catch (JsonSyntaxException ex) {
// ignore all json errors
} finally {
intermediateState.set(false);
}
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method signInIfNotSignedInInternal.
private static Mono<Boolean> signInIfNotSignedInInternal(Project project) {
final AuthMethodManager authMethodManager = AuthMethodManager.getInstance();
final IDeviceLoginUI deviceLoginUI = new DeviceLoginUI();
return Mono.create(sink -> AzureTaskManager.getInstance().runLater(() -> {
final AuthConfiguration auth;
try {
auth = showSignInWindowAndGetAuthConfiguration(project);
} 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.show(project, 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.azure.toolkit.lib.auth.model.AuthConfiguration in project azure-tools-for-java by Microsoft.
the class ServicePrincipalLoginDialog method getData.
public AuthConfiguration getData() {
AuthConfiguration data = new AuthConfiguration();
data.setClient(clientIdTextField.getText());
data.setTenant(tenantIdTextField.getText());
if (passwordRadioButton.isSelected()) {
data.setKey(String.valueOf(keyPasswordField.getPassword()));
} else {
data.setCertificate(this.certFileTextField.getText());
}
data.setType(AuthType.SERVICE_PRINCIPAL);
return data;
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration in project azure-tools-for-java by Microsoft.
the class ServicePrincipalLoginDialog method getData.
public AuthConfiguration getData() {
AuthConfiguration data = new AuthConfiguration();
data.setClient(txtClientId.getText());
data.setTenant(txtTenantId.getText());
if (radioPassword.getSelection()) {
data.setKey(String.valueOf(txtPassword.getText()));
} else {
data.setCertificate(this.txtCertificate.getText());
}
data.setType(AuthType.SERVICE_PRINCIPAL);
return data;
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthConfiguration 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);
}));
}
Aggregations