@Override public String getManagementURI() throws IOException { initATCIfNeeded(); // default to global cloud return atc.environment() == null ? AzureEnvironment.AZURE.resourceManagerEndpoint() : atc.environment().resourceManagerEndpoint(); }
/** * 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 DelegatedTokenCredentials(ApplicationTokenCredentials applicationCredentials, String redirectUrl) { super(applicationCredentials.environment(), applicationCredentials.domain()); // defer token acquisition this.applicationCredentials = applicationCredentials; this.tokens = new ConcurrentHashMap<>(); this.redirectUrl = redirectUrl; this.refreshTokenClient = new RefreshTokenClient(applicationCredentials.environment().activeDirectoryEndpoint(), proxy()); }
private AuthenticationResult acquireAccessToken(String resource) throws IOException { String authorityUrl = this.environment().activeDirectoryEndpoint() + this.domain(); ExecutorService executor = Executors.newSingleThreadExecutor(); AuthenticationContext context = new AuthenticationContext(authorityUrl, false, executor);
@Bean @ConditionalOnMissingBean public Azure azure(AzureProperties azureProperties) throws IOException { CredentialsProvider credentialsProvider = new DefaultCredentialsProvider(azureProperties); ApplicationTokenCredentials credentials = credentialsProvider.getCredentials(); TelemetryCollector.getInstance().setSubscription(credentials.defaultSubscriptionId()); RestClient restClient = new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials).withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()).withUserAgent(SPRING_CLOUD_USER_AGENT) .build(); return Azure.authenticate(restClient, credentials.domain()).withDefaultSubscription(); }
@Bean @ConditionalOnMissingBean public Azure azure(AzureProperties azureProperties) throws IOException { CredentialsProvider credentialsProvider = new DefaultCredentialsProvider(azureProperties); ApplicationTokenCredentials credentials = credentialsProvider.getCredentials(); TelemetryCollector.getInstance().setSubscription(credentials.defaultSubscriptionId()); RestClient restClient = new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials).withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()).withUserAgent(SPRING_CLOUD_USER_AGENT) .build(); return Azure.authenticate(restClient, credentials.domain()).withDefaultSubscription(); }
/** * Authenticates API access using a properties file containing the required credentials. * @param credentialsFile the file containing the credentials in the standard Java properties file format, * with the following keys:<p> * <code> * subscription= #subscription ID<br> * tenant= #tenant ID<br> * client= #client id<br> * key= #client key<br> * managementURI= #management URI<br> * baseURL= #base URL<br> * authURL= #authentication URL<br> *</code> * @return authenticated Azure client * @throws IOException exception thrown from file access */ public static Authenticated authenticate(File credentialsFile) throws IOException { ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); return new AuthenticatedImpl(new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(), credentials.domain()).withDefaultSubscription(credentials.defaultSubscriptionId()); }
/** * Authenticates API access using a properties file containing the required credentials. * @param credentialsFile the file containing the credentials in the standard Java properties file format, * with the following keys:<p> * <code> * subscription= #subscription ID<br> * tenant= #tenant ID<br> * client= #client id<br> * key= #client key<br> * managementURI= #management URI<br> * baseURL= #base URL<br> * authURL= #authentication URL<br> *</code> * @return authenticated Azure client * @throws IOException exception thrown from file access */ public static Authenticated authenticate(File credentialsFile) throws IOException { ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credentialsFile); return new AuthenticatedImpl(new RestClient.Builder() .withBaseUrl(credentials.environment(), AzureEnvironment.Endpoint.RESOURCE_MANAGER) .withCredentials(credentials) .withSerializerAdapter(new AzureJacksonAdapter()) .withResponseBuilderFactory(new AzureResponseBuilder.Factory()) .withInterceptor(new ProviderRegistrationInterceptor(credentials)) .withInterceptor(new ResourceManagerThrottlingInterceptor()) .build(), credentials.domain()).withDefaultSubscription(credentials.defaultSubscriptionId()); }