Search in sources :

Example 6 with Subscription

use of com.microsoft.azure.management.resources.Subscription in project azure-tools-for-java by Microsoft.

the class AccessTokenAzureManager method getSubscriptions.

@Override
public List<Subscription> getSubscriptions() throws IOException {
    List<Subscription> sl = new LinkedList<Subscription>();
    // could be multi tenant - return all subscriptions for the current account
    List<Tenant> tl = getTenants("common");
    for (Tenant t : tl) {
        sl.addAll(getSubscriptions(t.tenantId()));
    }
    return sl;
}
Also used : Tenant(com.microsoft.azure.management.resources.Tenant) Subscription(com.microsoft.azure.management.resources.Subscription) LinkedList(java.util.LinkedList)

Example 7 with Subscription

use of com.microsoft.azure.management.resources.Subscription in project azure-tools-for-java by Microsoft.

the class AdAuthManager method signIn.

public AuthenticationResult signIn() throws IOException {
    // build token cache for azure and graph api
    // using azure sdk directly
    cleanCache();
    String commonTid = "common";
    AuthContext ac = new AuthContext(String.format("%s/%s", Constants.authority, commonTid), cache);
    AuthenticationResult result = ac.acquireToken(AzureEnvironment.AZURE.resourceManagerEndpoint(), Constants.clientId, Constants.redirectUri, PromptBehavior.Always, null);
    String displayableId = result.getUserInfo().getDisplayableId();
    UserIdentifier uid = new UserIdentifier(displayableId, UserIdentifierType.RequiredDisplayableId);
    Map<String, List<String>> tidToSidsMap = new HashMap<>();
    //        List<Tenant> tenants = AccessTokenAzureManager.authTid(commonTid).tenants().list();
    List<Tenant> tenants = AccessTokenAzureManager.getTenants(commonTid);
    for (Tenant t : tenants) {
        String tid = t.tenantId();
        AuthContext ac1 = new AuthContext(String.format("%s/%s", Constants.authority, tid), cache);
        // put tokens into the cache
        ac1.acquireToken(AzureEnvironment.AZURE.resourceManagerEndpoint(), Constants.clientId, Constants.redirectUri, PromptBehavior.Auto, uid);
        ac1.acquireToken(AzureEnvironment.AZURE.graphEndpoint(), Constants.clientId, Constants.redirectUri, PromptBehavior.Auto, uid);
        ac1.acquireToken(Constants.resourceVault, Constants.clientId, Constants.redirectUri, PromptBehavior.Auto, uid);
        List<String> sids = new LinkedList<>();
        for (Subscription s : AccessTokenAzureManager.getSubscriptions(tid)) {
            sids.add(s.subscriptionId());
        }
        tidToSidsMap.put(t.tenantId(), sids);
    }
    // save account email
    String accountEmail = displayableId;
    if (accountEmail == null) {
        throw new IllegalArgumentException("accountEmail is null");
    }
    adAuthDetails.setAccountEmail(accountEmail);
    adAuthDetails.setTidToSidsMap(tidToSidsMap);
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) Tenant(com.microsoft.azure.management.resources.Tenant) List(java.util.List) LinkedList(java.util.LinkedList) Subscription(com.microsoft.azure.management.resources.Subscription)

Example 8 with Subscription

use of com.microsoft.azure.management.resources.Subscription in project azure-tools-for-java by Microsoft.

the class SubscriptionManager method updateAccountSubscriptionList.

protected List<SubscriptionDetail> updateAccountSubscriptionList() throws IOException {
    System.out.println(Thread.currentThread().getId() + " SubscriptionManager.updateAccountSubscriptionList()");
    if (azureManager == null) {
        throw new IllegalArgumentException("azureManager is null");
    }
    System.out.println("Getting subscription list from Azure");
    List<SubscriptionDetail> sdl = new ArrayList<>();
    List<Pair<Subscription, Tenant>> stpl = azureManager.getSubscriptionsWithTenant();
    for (Pair<Subscription, Tenant> stp : stpl) {
        sdl.add(new SubscriptionDetail(stp.first().subscriptionId(), stp.first().displayName(), stp.second().tenantId(), true));
    }
    return sdl;
}
Also used : Tenant(com.microsoft.azure.management.resources.Tenant) SubscriptionDetail(com.microsoft.azuretools.authmanage.models.SubscriptionDetail) Subscription(com.microsoft.azure.management.resources.Subscription) Pair(com.microsoft.azuretools.utils.Pair)

Aggregations

Subscription (com.microsoft.azure.management.resources.Subscription)8 Location (com.microsoft.azure.management.resources.Location)4 SubscriptionDetail (com.microsoft.azuretools.authmanage.models.SubscriptionDetail)4 Azure (com.microsoft.azure.management.Azure)3 ResourceGroup (com.microsoft.azure.management.resources.ResourceGroup)3 Tenant (com.microsoft.azure.management.resources.Tenant)3 SubscriptionManager (com.microsoft.azuretools.authmanage.SubscriptionManager)3 AzureManager (com.microsoft.azuretools.sdkmanage.AzureManager)3 Pair (com.microsoft.azuretools.utils.Pair)2 LinkedList (java.util.LinkedList)2 Test (org.junit.Test)2 com.microsoft.azure.docker.model (com.microsoft.azure.docker.model)1 AzureDockerCertVaultOps (com.microsoft.azure.docker.ops.AzureDockerCertVaultOps)1 AzureDockerVMOps (com.microsoft.azure.docker.ops.AzureDockerVMOps)1 KeyVaultClient (com.microsoft.azure.keyvault.KeyVaultClient)1 Vault (com.microsoft.azure.management.keyvault.Vault)1 Network (com.microsoft.azure.management.network.Network)1 Subnet (com.microsoft.azure.management.network.Subnet)1 Region (com.microsoft.azure.management.resources.fluentcore.arm.Region)1 StorageAccount (com.microsoft.azure.management.storage.StorageAccount)1