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;
}
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;
}
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;
}
Aggregations