use of com.microsoft.azure.toolkit.lib.auth.model.AuthType in project azure-tools-for-java by Microsoft.
the class SignInDialog method syncControlControls.
private void syncControlControls() {
setErrorMessage(null);
AuthType type = data.getType();
lblDeviceInfo.setEnabled(type == AuthType.DEVICE_CODE);
lblAzureCli.setEnabled(type == AuthType.AZURE_CLI);
lblSP.setEnabled(type == AuthType.SERVICE_PRINCIPAL);
this.lblOAuth.setEnabled(type == AuthType.OAUTH2);
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthType in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method getSignOutWarningMessage.
private static String getSignOutWarningMessage(@NotNull AuthMethodManager authMethodManager) {
final AuthMethodDetails authMethodDetails = authMethodManager.getAuthMethodDetails();
if (authMethodDetails == null || authMethodDetails.getAuthType() == null) {
return "Do you really want to sign out?";
}
final AuthType authType = authMethodDetails.getAuthType();
final String warningMessage;
switch(authType) {
case SERVICE_PRINCIPAL:
warningMessage = String.format("Signed in using service principal \"%s\"", authMethodDetails.getClientId());
break;
case OAUTH2:
case DEVICE_CODE:
warningMessage = String.format("Signed in as %s(%s)", authMethodDetails.getAccountEmail(), authType.toString());
break;
case AZURE_CLI:
warningMessage = "Signed in with Azure CLI";
break;
default:
warningMessage = "Signed in by unknown authentication method.";
break;
}
return String.format("%s\nDo you really want to sign out? %s", warningMessage, authType == AuthType.AZURE_CLI ? "(This will not sign you out from Azure CLI)" : "");
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthType in project azure-tools-for-java by Microsoft.
the class SignOutCommandHandler method getSignOutWarningMessage.
public static String getSignOutWarningMessage(@Nonnull AuthMethodManager authMethodManager) {
final AuthMethodDetails authMethodDetails = authMethodManager.getAuthMethodDetails();
if (authMethodDetails == null || authMethodDetails.getAuthType() == null) {
return "Do you really want to sign out?";
}
final AuthType authType = authMethodDetails.getAuthType();
final String warningMessage;
switch(authType) {
case SERVICE_PRINCIPAL:
warningMessage = String.format("Signed in using service principal \"%s\"", authMethodDetails.getClientId());
break;
case OAUTH2:
case DEVICE_CODE:
warningMessage = String.format("Signed in as %s(%s)", authMethodDetails.getAccountEmail(), authType.toString());
break;
case AZURE_CLI:
warningMessage = "Signed in with Azure CLI";
break;
default:
warningMessage = "Signed in by unknown authentication method.";
break;
}
return String.format("%s\nDo you really want to sign out? %s", warningMessage, authType == AuthType.AZURE_CLI ? "(This will not sign you out from Azure CLI)" : "");
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthType in project azure-tools-for-java by Microsoft.
the class AzureSignInAction method showSignInWindowAndGetAuthConfiguration.
private static AuthConfiguration showSignInWindowAndGetAuthConfiguration(Project project) throws InterruptedException {
final SignInWindow dialog = new SignInWindow(new AuthMethodDetails(), project);
if (!dialog.showAndGet()) {
throw new InterruptedException("user cancel");
}
AuthConfiguration auth = new AuthConfiguration();
AuthType type = dialog.getData();
auth.setType(type);
if (type == AuthType.SERVICE_PRINCIPAL) {
final ServicePrincipalLoginDialog spDialog = new ServicePrincipalLoginDialog(project);
if (!spDialog.showAndGet()) {
throw new InterruptedException("user cancel");
}
auth = spDialog.getData();
}
return auth;
}
use of com.microsoft.azure.toolkit.lib.auth.model.AuthType in project azure-tools-for-java by Microsoft.
the class IdentityAzureManager method restoreSignIn.
public Mono<AuthMethodDetails> restoreSignIn(AuthMethodDetails authMethodDetails) {
if (authMethodDetails == null || authMethodDetails.getAuthMethod() == null || authMethodDetails.getAuthType() == null) {
return Mono.just(new AuthMethodDetails());
}
if (StringUtils.isNotBlank(authMethodDetails.getAzureEnv())) {
Azure.az(AzureCloud.class).setByName(authMethodDetails.getAzureEnv());
}
AuthType authType = authMethodDetails.getAuthType();
try {
if (authType == AuthType.SERVICE_PRINCIPAL) {
AuthConfiguration auth = new AuthConfiguration();
auth.setType(AuthType.SERVICE_PRINCIPAL);
auth.setClient(authMethodDetails.getClientId());
auth.setTenant(authMethodDetails.getTenantId());
auth.setEnvironment(Azure.az(AzureCloud.class).get());
if (StringUtils.isNotBlank(authMethodDetails.getCertificate())) {
auth.setCertificate(authMethodDetails.getCertificate());
} else {
secureStore.migratePassword("account|" + auth.getClient(), null, SERVICE_PRINCIPAL_STORE_SERVICE, auth.getClient(), null);
String key = secureStore == null ? null : secureStore.loadPassword(SERVICE_PRINCIPAL_STORE_SERVICE, authMethodDetails.getClientId(), null);
if (StringUtils.isBlank(key)) {
throw new AzureToolkitRuntimeException(String.format("Cannot find SP security key for '%s' in intellij key pools.", authMethodDetails.getClientId()));
}
auth.setKey(key);
}
return signInServicePrincipal(auth).map(ac -> authMethodDetails);
} else {
if (StringUtils.isNotBlank(authMethodDetails.getClientId())) {
AccountEntity entity = new AccountEntity();
entity.setType(authType);
entity.setEnvironment(Azure.az(AzureCloud.class).get());
entity.setEmail(authMethodDetails.getAccountEmail());
entity.setClientId(authMethodDetails.getClientId());
entity.setTenantIds(StringUtils.isNotBlank(authMethodDetails.getTenantId()) ? Collections.singletonList(authMethodDetails.getTenantId()) : null);
Account account = Azure.az(AzureAccount.class).account(entity);
return Mono.just(fromAccountEntity(account.getEntity()));
} else {
throw new AzureToolkitRuntimeException("Cannot restore credentials due to version change.");
}
}
} catch (Throwable e) {
if (StringUtils.isNotBlank(authMethodDetails.getClientId()) && authMethodDetails.getAuthType() == AuthType.SERVICE_PRINCIPAL && secureStore != null) {
secureStore.forgetPassword(SERVICE_PRINCIPAL_STORE_SERVICE, authMethodDetails.getClientId(), null);
}
return Mono.error(new AzureToolkitRuntimeException(String.format("Cannot restore credentials due to error: %s", e.getMessage())));
}
}
Aggregations