Java Code Examples for com.microsoft.rest.RestClient#credentials()

The following examples show how to use com.microsoft.rest.RestClient#credentials() . 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: Utils.java    From azure-libraries-for-java with MIT License 6 votes vote down vote up
/**
 * 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;
}
 
Example 2
Source File: GraphRbacManager.java    From azure-libraries-for-java with MIT License 5 votes vote down vote up
private GraphRbacManager(RestClient restClient, String tenantId) {
    String graphEndpoint = AzureEnvironment.AZURE.graphEndpoint();
    if (restClient.credentials() instanceof AzureTokenCredentials) {
        graphEndpoint = ((AzureTokenCredentials) restClient.credentials()).environment().graphEndpoint();
    }
    this.graphRbacManagementClient = new GraphRbacManagementClientImpl(
            restClient.newBuilder().withBaseUrl(graphEndpoint).build()).withTenantID(tenantId);
    this.authorizationManagementClient = new AuthorizationManagementClientImpl(restClient);
    this.tenantId = tenantId;
}