public ArmRequestFactory(String tenantId) { this.urlPrefix = CommonSettings.getAdEnvironment().resourceManagerEndpoint() + "subscriptions/"; this.tenantId = tenantId; this.resource = CommonSettings.getAdEnvironment().resourceManagerEndpoint(); this.apiVersion = "api-version=2015-07-01"; }
@Override public String getManagementURI() throws IOException { // environments other than global cloud are not supported for interactive login for now return CommonSettings.getAdEnvironment().resourceManagerEndpoint(); }
public String getAccessToken(String tid) throws IOException { return getAccessToken(tid, env.resourceManagerEndpoint(), PromptBehavior.Auto); }
private void initEnv() { if (env != null) { return; } try { String managementURI = getManagementURI().toLowerCase(); if (managementURI.endsWith("/")) { managementURI = managementURI.substring(0, managementURI.length() - 1); } if (AzureEnvironment.AZURE.resourceManagerEndpoint().toLowerCase().startsWith(managementURI)) { env = Environment.GLOBAL; } else if (AzureEnvironment.AZURE_CHINA.resourceManagerEndpoint().toLowerCase().startsWith(managementURI)) { env = Environment.CHINA; } else if (AzureEnvironment.AZURE_GERMANY.resourceManagerEndpoint().toLowerCase().startsWith(managementURI)) { env = Environment.GERMAN; } else if (AzureEnvironment.AZURE_US_GOVERNMENT.resourceManagerEndpoint().toLowerCase().startsWith(managementURI)) { env = Environment.US_GOVERNMENT; } else { env = Environment.GLOBAL; } } catch (Exception e) { env = Environment.GLOBAL; } } }
@Override public String getManagementURI() throws IOException { initATCIfNeeded(); // default to global cloud return atc.environment() == null ? AzureEnvironment.AZURE.resourceManagerEndpoint() : atc.environment().resourceManagerEndpoint(); }
private String getManagementApiToken() { try { log.info("Requesting authentication token ... "); ApplicationTokenCredentials applicationTokenCredentials = new ApplicationTokenCredentials( clientId, tenantId, clientSecret, AzureEnvironment.AZURE); return applicationTokenCredentials.getToken(AzureEnvironment.AZURE.resourceManagerEndpoint()); } catch (IOException e) { log.error("Cannot retrieve authentication token due to", e); throw new DlabException("Cannot retrieve authentication token", e); } }
void exportAuthFile(ServicePrincipalImpl servicePrincipal) { if (authFile == null) { return; } RestClient restClient = servicePrincipal.manager().roleInner().restClient(); AzureEnvironment environment = Utils.extractAzureEnvironment(restClient); StringBuilder builder = new StringBuilder("{\n"); builder.append(" ").append(String.format("\"clientId\": \"%s\",", servicePrincipal.applicationId())).append("\n"); builder.append(" ").append(String.format("\"clientCertificate\": \"%s\",", privateKeyPath.replace("\\", "\\\\"))).append("\n"); builder.append(" ").append(String.format("\"clientCertificatePassword\": \"%s\",", privateKeyPassword)).append("\n"); builder.append(" ").append(String.format("\"tenantId\": \"%s\",", servicePrincipal.manager().tenantId())).append("\n"); builder.append(" ").append(String.format("\"subscriptionId\": \"%s\",", servicePrincipal.assignedSubscription)).append("\n"); builder.append(" ").append(String.format("\"activeDirectoryEndpointUrl\": \"%s\",", environment.activeDirectoryEndpoint())).append("\n"); builder.append(" ").append(String.format("\"resourceManagerEndpointUrl\": \"%s\",", environment.resourceManagerEndpoint())).append("\n"); builder.append(" ").append(String.format("\"activeDirectoryGraphResourceId\": \"%s\",", environment.graphEndpoint())).append("\n"); builder.append(" ").append(String.format("\"managementEndpointUrl\": \"%s\"", environment.managementEndpoint())).append("\n"); builder.append("}"); try { authFile.write(builder.toString().getBytes()); } catch (IOException e) { throw new RuntimeException(e); } }
void exportAuthFile(ServicePrincipalImpl servicePrincipal) { if (authFile == null) { return; } RestClient restClient = servicePrincipal.manager().roleInner().restClient(); AzureEnvironment environment = Utils.extractAzureEnvironment(restClient); StringBuilder builder = new StringBuilder("{\n"); builder.append(" ").append(String.format("\"clientId\": \"%s\",", servicePrincipal.applicationId())).append("\n"); builder.append(" ").append(String.format("\"clientSecret\": \"%s\",", value())).append("\n"); builder.append(" ").append(String.format("\"tenantId\": \"%s\",", servicePrincipal.manager().tenantId())).append("\n"); builder.append(" ").append(String.format("\"subscriptionId\": \"%s\",", servicePrincipal.assignedSubscription)).append("\n"); builder.append(" ").append(String.format("\"activeDirectoryEndpointUrl\": \"%s\",", environment.activeDirectoryEndpoint())).append("\n"); builder.append(" ").append(String.format("\"resourceManagerEndpointUrl\": \"%s\",", environment.resourceManagerEndpoint())).append("\n"); builder.append(" ").append(String.format("\"activeDirectoryGraphResourceId\": \"%s\",", environment.graphEndpoint())).append("\n"); builder.append(" ").append(String.format("\"managementEndpointUrl\": \"%s\"", environment.managementEndpoint())).append("\n"); builder.append("}"); try { authFile.write(builder.toString().getBytes()); } catch (IOException e) { throw new RuntimeException(e); } }
prop.setProperty("baseURL", azureEnv.resourceManagerEndpoint()); prop.setProperty("authURL", azureEnv.activeDirectoryEndpoint()); prop.setProperty("graphURL", azureEnv.graphEndpoint());
@Override public String getAccessToken(String tid) throws IOException { return AdAuthManager.getInstance().getAccessToken(tid, CommonSettings.getAdEnvironment().resourceManagerEndpoint(), PromptBehavior.Auto); }
/** * Try to extract the environment the client is authenticated to based * on the information on the rest client. * @param restClient the RestClient instance * @return the non-null AzureEnvironment */ public static AzureEnvironment extractAzureEnvironment(RestClient restClient) { AzureEnvironment environment = null; if (restClient.credentials() instanceof AzureTokenCredentials) { environment = ((AzureTokenCredentials) restClient.credentials()).environment(); } else { String baseUrl = restClient.retrofit().baseUrl().toString(); for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) { if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) { environment = env; break; } } if (environment == null) { throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl); } } return environment; }
/** * Try to extract the environment the client is authenticated to based * on the information on the rest client. * @param restClient the RestClient instance * @return the non-null AzureEnvironment */ public static AzureEnvironment extractAzureEnvironment(RestClient restClient) { AzureEnvironment environment = null; if (restClient.credentials() instanceof AzureTokenCredentials) { environment = ((AzureTokenCredentials) restClient.credentials()).environment(); } else { String baseUrl = restClient.retrofit().baseUrl().toString(); for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) { if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) { environment = env; break; } } if (environment == null) { throw new IllegalArgumentException("Unknown resource manager endpoint " + baseUrl); } } return environment; }
private String getNewToken() { try { log.info("Requesting authentication token ... "); ApplicationTokenCredentials applicationTokenCredentials = new ApplicationTokenCredentials( billingConfigurationAzure.getClientId(), billingConfigurationAzure.getTenantId(), billingConfigurationAzure.getClientSecret(), AzureEnvironment.AZURE); return applicationTokenCredentials.getToken(AzureEnvironment.AZURE.resourceManagerEndpoint()); } catch (IOException e) { log.error("Cannot retrieve authentication token due to", e); throw new DlabException("Cannot retrieve authentication token", e); } }
.target(AzureEnvironment.AZURE.resourceManagerEndpoint() + permissionScope + "roleAssignments") .queryParam("api-version", "2015-07-01")
AzureEnvironment environment() { RestClient restClient = this.manager().inner().restClient(); AzureEnvironment environment = null; if (restClient.credentials() instanceof AzureTokenCredentials) { environment = ((AzureTokenCredentials) restClient.credentials()).environment(); } String baseUrl = restClient.retrofit().baseUrl().toString(); for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) { if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) { environment = env; break; } } if (environment != null) { return environment; } throw new IllegalArgumentException("Unknown environment"); }
AzureEnvironment environment() { RestClient restClient = this.manager().inner().restClient(); AzureEnvironment environment = null; if (restClient.credentials() instanceof AzureTokenCredentials) { environment = ((AzureTokenCredentials) restClient.credentials()).environment(); } String baseUrl = restClient.retrofit().baseUrl().toString(); for (AzureEnvironment env : AzureEnvironment.knownEnvironments()) { if (env.resourceManagerEndpoint().toLowerCase().contains(baseUrl.toLowerCase())) { environment = env; break; } } if (environment != null) { return environment; } throw new IllegalArgumentException("Unknown environment"); }
authSettings.put(CredentialSettings.BASE_URL.toString(), AzureEnvironment.AZURE.resourceManagerEndpoint()); authSettings.put(CredentialSettings.MANAGEMENT_URI.toString(), AzureEnvironment.AZURE.managementEndpoint()); authSettings.put(CredentialSettings.GRAPH_URL.toString(), AzureEnvironment.AZURE.graphEndpoint());
AzureCliToken token = userTokens.get(resource); if (token == null && (resource.equalsIgnoreCase(environment().resourceManagerEndpoint()))) { token = userTokens.get(environment().managementEndpoint());
ac1.acquireToken(env.resourceManagerEndpoint(), false, userId, isDisplayable, this.webUi, Constants.redirectUri); } catch (AuthException e) { if (CommonSettings.getEnvironment() instanceof ProvidedEnvironment) { LOGGER.warning("Can't get " + env.resourceManagerEndpoint() + " access token from environment " + CommonSettings.getEnvironment().getName());