use of com.azure.identity.TokenCachePersistenceOptions in project azure-maven-plugins by microsoft.
the class AzureAccount method restoreLogin.
private Mono<Account> restoreLogin(@Nonnull AccountEntity accountEntity) {
Preconditions.checkNotNull(accountEntity.getEnvironment(), "Azure environment for account entity is required.");
Preconditions.checkNotNull(accountEntity.getType(), "Auth type for account entity is required.");
Account target;
if (Arrays.asList(AuthType.DEVICE_CODE, AuthType.OAUTH2).contains(accountEntity.getType())) {
AzureEnvironmentUtils.setupAzureEnvironment(accountEntity.getEnvironment());
SharedTokenCacheCredentialBuilder builder = new SharedTokenCacheCredentialBuilder();
SharedTokenCacheCredential credential = builder.tokenCachePersistenceOptions(new TokenCachePersistenceOptions().setName(Account.TOOLKIT_TOKEN_CACHE_NAME)).username(accountEntity.getEmail()).tenantId(accountEntity.getTenantIds() == null ? "organizations" : accountEntity.getTenantIds().get(0)).clientId(accountEntity.getClientId()).build();
target = new SimpleAccount(accountEntity, credential);
} else if (Arrays.asList(AuthType.VSCODE, AuthType.AZURE_CLI).contains(accountEntity.getType())) {
target = buildAccountMap().get(accountEntity.getType()).get();
} else {
return Mono.error(new AzureToolkitAuthenticationException(String.format("login for auth type '%s' cannot be restored.", accountEntity.getType())));
}
return target.login().map(ac -> {
if (ac.getEnvironment() != accountEntity.getEnvironment()) {
throw new AzureToolkitAuthenticationException(String.format("you have changed the azure cloud to '%s' for auth type: '%s' since last time you signed in.", AzureEnvironmentUtils.getCloudNameForAzureCli(ac.getEnvironment()), accountEntity.getType()));
}
if (!StringUtils.equalsIgnoreCase(ac.entity.getEmail(), accountEntity.getEmail())) {
throw new AzureToolkitAuthenticationException(String.format("you have changed the account from '%s' to '%s' since last time you signed in.", accountEntity.getEmail(), ac.entity.getEmail()));
}
return ac;
}).doOnSuccess(this::setAccount);
}
use of com.azure.identity.TokenCachePersistenceOptions in project azure-maven-plugins by microsoft.
the class DeviceCodeAccount method createCredential.
private TokenCredential createCredential(AzureEnvironment env) {
if (executorService.isShutdown()) {
throw new AzureToolkitAuthenticationException("device login twice is forbidden.");
}
AzureEnvironmentUtils.setupAzureEnvironment(env);
DeviceCodeCredentialBuilder builder = new DeviceCodeCredentialBuilder();
if (isEnablePersistence()) {
builder.tokenCachePersistenceOptions(new TokenCachePersistenceOptions().setName(TOOLKIT_TOKEN_CACHE_NAME));
}
return builder.clientId(IdentityConstants.DEVELOPER_SINGLE_SIGN_ON_ID).executorService(executorService).challengeConsumer(deviceCodeFuture::complete).build();
}
use of com.azure.identity.TokenCachePersistenceOptions in project azure-maven-plugins by microsoft.
the class OAuthAccount method createCredential.
protected TokenCredential createCredential(AzureEnvironment env) {
AzureEnvironmentUtils.setupAzureEnvironment(env);
InteractiveBrowserCredentialBuilder builder = new InteractiveBrowserCredentialBuilder();
if (isEnablePersistence()) {
builder.tokenCachePersistenceOptions(new TokenCachePersistenceOptions().setName(TOOLKIT_TOKEN_CACHE_NAME));
}
return builder.redirectUrl("http://localhost:" + FreePortFinder.findFreeLocalPort()).build();
}
Aggregations