com.microsoft.azure.credentials.ApplicationTokenCredentials Java Examples
The following examples show how to use
com.microsoft.azure.credentials.ApplicationTokenCredentials.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CreateCosmosDBTableWithVirtualNetworkRule.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #2
Source File: ManageHACosmosDB.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #3
Source File: CreateCosmosDBWithKindMongoDB.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #4
Source File: ManageSqlFailoverGroups.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #5
Source File: ManageSqlDatabasesAcrossDifferentDataCenters.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #6
Source File: ManageSqlFirewallRules.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #7
Source File: ManageSqlWithRecoveredOrRestoredDatabase.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #8
Source File: ManageSqlVirtualNetworkRules.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #9
Source File: ManageSqlImportExportDatabase.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #10
Source File: GettingSqlServerMetrics.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #11
Source File: ManageSqlServerDnsAliases.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #12
Source File: ManageSqlServerKeysWithAzureKeyVaultKey.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, credentials.clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #13
Source File: ManageSqlDatabaseInElasticPool.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #14
Source File: ManageSqlDatabase.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #15
Source File: ManageSqlServerSecurityAlertPolicy.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile); RestClient restClient = new RestClient.Builder() .withBaseUrl(AzureEnvironment.AZURE, AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withReadTimeout(150, TimeUnit.SECONDS) .withLogLevel(LogLevel.BODY) .withCredentials(credentials).build(); Azure azure = Azure.authenticate(restClient, credentials.domain(), credentials.defaultSubscriptionId()).withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #16
Source File: CreateCosmosDBWithEventualConsistency.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #17
Source File: ManageKeyVault.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #18
Source File: CreateCosmosDBWithIPRange.java From azure-libraries-for-java with MIT License | 6 votes |
/** * Main entry point. * @param args the parameters */ public static void main(String[] args) { try { //============================================================= // Authenticate final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); Azure azure = Azure.configure() .withLogLevel(LogLevel.BASIC) .authenticate(credFile) .withDefaultSubscription(); // Print selected subscription System.out.println("Selected subscription: " + azure.subscriptionId()); runSample(azure, ApplicationTokenCredentials.fromFile(credFile).clientId()); } catch (Exception e) { System.out.println(e.getMessage()); e.printStackTrace(); } }
Example #19
Source File: KeyTests.java From azure-libraries-for-java with MIT License | 6 votes |
private Vault createVault() throws Exception { String vaultName = SdkContext.randomResourceName("vault", 20); ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(new File(System.getenv("AZURE_AUTH_LOCATION"))); Vault vault = keyVaultManager.vaults().define(vaultName) .withRegion(Region.US_WEST) .withNewResourceGroup(RG_NAME) .defineAccessPolicy() .forServicePrincipal(credentials.clientId()) .allowKeyAllPermissions() .attach() .create(); Assert.assertNotNull(vault); SdkContext.sleep(10000); return vault; }
Example #20
Source File: AzureFileSystemBehaviorITCase.java From flink with Apache License 2.0 | 6 votes |
private static boolean isHttpsTrafficOnly() throws IOException { if (StringUtils.isNullOrWhitespaceOnly(RESOURCE_GROUP) || StringUtils.isNullOrWhitespaceOnly(TOKEN_CREDENTIALS_FILE)) { // default to https only, as some fields are missing return true; } Assume.assumeTrue("Azure storage account not configured, skipping test...", !StringUtils.isNullOrWhitespaceOnly(ACCOUNT)); AzureTokenCredentials credentials = ApplicationTokenCredentials.fromFile(new File(TOKEN_CREDENTIALS_FILE)); Azure azure = StringUtils.isNullOrWhitespaceOnly(SUBSCRIPTION_ID) ? Azure.authenticate(credentials).withDefaultSubscription() : Azure.authenticate(credentials).withSubscription(SUBSCRIPTION_ID); return azure.storageAccounts().getByResourceGroup(RESOURCE_GROUP, ACCOUNT).inner().enableHttpsTrafficOnly(); }
Example #21
Source File: AzureCredentialConnector.java From cloudbreak with Apache License 2.0 | 6 votes |
@Override public Map<String, String> initCodeGrantFlow(CloudContext cloudContext, CloudCredential cloudCredential) { Map<String, String> parameters = new HashMap<>(); AzureCredentialView azureCredential = new AzureCredentialView(cloudCredential); ApplicationTokenCredentials applicationCredentials = new ApplicationTokenCredentials( azureCredential.getAccessKey(), azureCredential.getTenantId(), azureCredential.getSecretKey(), AzureEnvironment.AZURE); String replyUrl = appCreationCommand.getRedirectURL(String.valueOf(cloudContext.getAccountId()), azureCredential.getDeploymentAddress()); CbDelegatedTokenCredentials creds = new CbDelegatedTokenCredentials(applicationCredentials, replyUrl, authenticationContextProvider, cbRefreshTokenClientProvider); String state = UUID.randomUUID().toString(); parameters.put("appLoginUrl", creds.generateAuthenticationUrl(state)); parameters.put("appReplyUrl", replyUrl); parameters.put("codeGrantFlowState", state); return parameters; }
Example #22
Source File: AzureFileSystemBehaviorITCase.java From flink with Apache License 2.0 | 6 votes |
private static boolean isHttpsTrafficOnly() throws IOException { if (StringUtils.isNullOrWhitespaceOnly(RESOURCE_GROUP) || StringUtils.isNullOrWhitespaceOnly(TOKEN_CREDENTIALS_FILE)) { // default to https only, as some fields are missing return true; } Assume.assumeTrue("Azure storage account not configured, skipping test...", !StringUtils.isNullOrWhitespaceOnly(ACCOUNT)); AzureTokenCredentials credentials = ApplicationTokenCredentials.fromFile(new File(TOKEN_CREDENTIALS_FILE)); Azure azure = StringUtils.isNullOrWhitespaceOnly(SUBSCRIPTION_ID) ? Azure.authenticate(credentials).withDefaultSubscription() : Azure.authenticate(credentials).withSubscription(SUBSCRIPTION_ID); return azure.storageAccounts().getByResourceGroup(RESOURCE_GROUP, ACCOUNT).inner().enableHttpsTrafficOnly(); }
Example #23
Source File: AzureClientConfiguration.java From cloudbreak with Apache License 2.0 | 5 votes |
@Bean public Azure getAzure() { Credential credential = azureProperties.getCredential(); AzureTokenCredentials azureTokenCredentials = new ApplicationTokenCredentials(credential.getAppId(), credential.getTenantId(), credential.getAppPassword(), AzureEnvironment.AZURE); return Azure .configure() .withProxyAuthenticator(new JavaNetAuthenticator()) .withLogLevel(LogLevel.BODY_AND_HEADERS) .authenticate(azureTokenCredentials) .withSubscription(credential.getSubscriptionId()); }
Example #24
Source File: KeyVaultSampleTests.java From azure-libraries-for-java with MIT License | 5 votes |
@Test @Ignore("Some RBAC related issue with current credentials") public void testManageKeyVault() { String clientId = ""; if (!isPlaybackMode()) { final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION")); try { clientId = ApplicationTokenCredentials.fromFile(credFile).clientId(); } catch (IOException e) { e.printStackTrace(); } } Assert.assertTrue(ManageKeyVault.runSample(azure, clientId)); }
Example #25
Source File: AzureSetup.java From cloudbreak with Apache License 2.0 | 5 votes |
private void validateAdlsFileSystem(CloudCredential credential, SpiFileSystem fileSystem) { Map<String, Object> credentialAttributes = credential.getParameters(); CloudAdlsView cloudFileSystem = (CloudAdlsView) fileSystem.getCloudFileSystems().get(0); String clientSecret = String.valueOf(credentialAttributes.get(CloudAdlsView.CREDENTIAL_SECRET_KEY)); String subscriptionId = String.valueOf(credentialAttributes.get(CloudAdlsView.SUBSCRIPTION_ID)); String clientId = String.valueOf(credentialAttributes.get(CloudAdlsView.ACCESS_KEY)); String tenantId = StringUtils.isEmpty(cloudFileSystem.getTenantId()) ? credential.getStringParameter(TENANT_ID) : cloudFileSystem.getTenantId(); String accountName = cloudFileSystem.getAccountName(); ApplicationTokenCredentials creds = new ApplicationTokenCredentials(clientId, tenantId, clientSecret, AzureEnvironment.AZURE); DataLakeStoreAccountManagementClient adlsClient = new DataLakeStoreAccountManagementClientImpl(creds); adlsClient.withSubscriptionId(subscriptionId); PagedList<DataLakeStoreAccountBasic> dataLakeStoreAccountPagedList = adlsClient.accounts().list(); boolean validAccountname = false; List<DataLakeStoreAccountBasic> dataLakeStoreAccountList = new ArrayList<>(); while (dataLakeStoreAccountPagedList.hasNextPage()) { dataLakeStoreAccountList.addAll(dataLakeStoreAccountPagedList); dataLakeStoreAccountPagedList.loadNextPage(); } for (DataLakeStoreAccountBasic account : dataLakeStoreAccountList) { if (account.name().equalsIgnoreCase(accountName)) { validAccountname = true; break; } } if (!validAccountname) { throw new CloudConnectorException("The provided file system account name does not belong to a valid ADLS account"); } }
Example #26
Source File: CbDelegatedTokenCredentials.java From cloudbreak with Apache License 2.0 | 5 votes |
public CbDelegatedTokenCredentials(ApplicationTokenCredentials applicationCredentials, String redirectUrl, Map<String, AuthenticationResult> tokens, String clientSecret, AuthenticationContextProvider authenticationContextProvider, CBRefreshTokenClientProvider cbRefreshTokenClientProvider) { super(applicationCredentials.environment(), applicationCredentials.domain()); this.authenticationContextProvider = authenticationContextProvider; this.tokens = new ConcurrentHashMap<>(tokens); this.redirectUrl = redirectUrl; cbRefreshTokenClient = cbRefreshTokenClientProvider.getCBRefreshTokenClient(applicationCredentials.environment().activeDirectoryEndpoint()); this.clientSecret = clientSecret; this.applicationCredentials = applicationCredentials; }
Example #27
Source File: CbDelegatedTokenCredentials.java From cloudbreak with Apache License 2.0 | 5 votes |
/** * Initializes a new instance of the DelegatedTokenCredentials. * * @param applicationCredentials the credentials representing a service principal * @param redirectUrl the URL to redirect to after authentication in Active Directory */ public CbDelegatedTokenCredentials(ApplicationTokenCredentials applicationCredentials, String redirectUrl, AuthenticationContextProvider authenticationContextProvider, CBRefreshTokenClientProvider cbRefreshTokenClientProvider) { super(applicationCredentials.environment(), applicationCredentials.domain()); this.authenticationContextProvider = authenticationContextProvider; this.applicationCredentials = applicationCredentials; tokens = new ConcurrentHashMap<>(); this.redirectUrl = redirectUrl; cbRefreshTokenClient = cbRefreshTokenClientProvider.getCBRefreshTokenClient(applicationCredentials.environment().activeDirectoryEndpoint()); }
Example #28
Source File: CbDelegatedTokenCredentials.java From cloudbreak with Apache License 2.0 | 5 votes |
/** * Initializes a new instance of the DelegatedTokenCredentials, with a pre-acquired oauth2 authorization code. * * @param applicationCredentials the credentials representing a service principal * @param redirectUrl the URL to redirect to after authentication in Active Directory * @param authorizationCode the oauth2 authorization code */ public CbDelegatedTokenCredentials(ApplicationTokenCredentials applicationCredentials, String redirectUrl, String authorizationCode, String clientSecret, AuthenticationContextProvider authenticationContextProvider, CBRefreshTokenClientProvider cbRefreshTokenClientProvider) { super(applicationCredentials.environment(), applicationCredentials.domain()); this.authenticationContextProvider = authenticationContextProvider; tokens = new ConcurrentHashMap<>(); this.redirectUrl = redirectUrl; this.authorizationCode = authorizationCode; cbRefreshTokenClient = cbRefreshTokenClientProvider.getCBRefreshTokenClient(applicationCredentials.environment().activeDirectoryEndpoint()); this.clientSecret = clientSecret; this.applicationCredentials = applicationCredentials; }
Example #29
Source File: AzureClientCredentials.java From cloudbreak with Apache License 2.0 | 5 votes |
private AzureTokenCredentials getAzureCredentials() { String tenantId = credentialView.getTenantId(); String clientId = credentialView.getAccessKey(); String secretKey = credentialView.getSecretKey(); String subscriptionId = credentialView.getSubscriptionId(); AzureEnvironment azureEnvironment = AzureEnvironment.AZURE; ApplicationTokenCredentials applicationTokenCredentials = new ApplicationTokenCredentials(clientId, tenantId, secretKey, azureEnvironment); Optional<Boolean> codeGrantFlow = Optional.ofNullable(credentialView.codeGrantFlow()); AzureTokenCredentials result = applicationTokenCredentials; if (codeGrantFlow.orElse(Boolean.FALSE)) { String refreshToken = credentialView.getRefreshToken(); if (StringUtils.isNotEmpty(refreshToken)) { LOGGER.info("Creating Azure credentials for a new delegated token with refresh token, credential: {}", credentialView.getName()); String resource = azureEnvironment.managementEndpoint(); CBRefreshTokenClient refreshTokenClient = cbRefreshTokenClientProvider.getCBRefreshTokenClient(azureEnvironment.activeDirectoryEndpoint()); AuthenticationResult authenticationResult = refreshTokenClient.refreshToken(tenantId, clientId, secretKey, resource, refreshToken, false); if (authenticationResult == null) { String msg = String.format("New token couldn't be obtain with refresh token for credential: %s", credentialView.getName()); LOGGER.warn(msg); throw new CloudConnectorException(msg); } Map<String, AuthenticationResult> tokens = Map.of(resource, authenticationResult); result = new CbDelegatedTokenCredentials(applicationTokenCredentials, resource, tokens, secretKey, authenticationContextProvider, cbRefreshTokenClientProvider); } else { LOGGER.info("Creating Azure credentials for a new delegated token with authorization code, credential: {}", credentialView.getName()); String appReplyUrl = credentialView.getAppReplyUrl(); String authorizationCode = credentialView.getAuthorizationCode(); result = new CbDelegatedTokenCredentials(applicationTokenCredentials, appReplyUrl, authorizationCode, secretKey, authenticationContextProvider, cbRefreshTokenClientProvider); } } else { LOGGER.info("Creating Azure credentials with application token credentials, credential: {}", credentialView.getName()); } return result.withDefaultSubscriptionId(subscriptionId); }
Example #30
Source File: AzureAccount.java From clouditor with Apache License 2.0 | 5 votes |
private static AzureTokenCredentials defaultCredentialProviderChain() throws IOException { // check if the default credentials-file exists var credentialsFile = new File(defaultAuthFile()); if (credentialsFile.exists()) { LOGGER.info("Using default credentials file {}", credentialsFile); return ApplicationTokenCredentials.fromFile(credentialsFile); } else { // otherwise, use default locations LOGGER.info("Did not find default credentials. Trying to use AzureCLI credentials instead."); return AzureCliCredentials.create(); } }