Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions sdk/management/azure/src/main/java/com/azure/management/Azure.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import com.azure.core.credential.TokenCredential;
import com.azure.core.http.HttpPipeline;
import com.azure.core.management.AzureEnvironment;
import com.azure.management.appservice.AppServiceCertificateOrders;
import com.azure.management.appservice.AppServiceCertificates;
import com.azure.management.appservice.AppServiceDomains;
Expand Down Expand Up @@ -96,6 +97,8 @@
import com.azure.management.storage.Usages;
import com.azure.management.storage.implementation.StorageManager;

import java.util.Objects;

/** The entry point for accessing resource management APIs in Azure. */
public final class Azure {
private final ResourceManager resourceManager;
Expand Down Expand Up @@ -243,22 +246,26 @@ public interface Authenticated extends AccessManagement {
/** The implementation for the Authenticated interface. */
private static final class AuthenticatedImpl implements Authenticated {
private final HttpPipeline httpPipeline;
private final AzureProfile profile;
private final ResourceManager.Authenticated resourceManagerAuthenticated;
private final GraphRbacManager graphRbacManager;
private SdkContext sdkContext;
private String tenantId;
private String subscriptionId;
private final AzureEnvironment environment;

private AuthenticatedImpl(HttpPipeline httpPipeline, AzureProfile profile) {
this.resourceManagerAuthenticated = ResourceManager.authenticate(httpPipeline, profile);
this.graphRbacManager = GraphRbacManager.authenticate(httpPipeline, profile);
this.httpPipeline = httpPipeline;
this.profile = profile;
this.tenantId = profile.tenantId();
this.subscriptionId = profile.subscriptionId();
this.environment = profile.environment();
this.sdkContext = new SdkContext();
}

@Override
public String tenantId() {
return profile.tenantId();
return this.tenantId;
}

@Override
Expand Down Expand Up @@ -314,22 +321,22 @@ public SdkContext sdkContext() {

@Override
public Authenticated withTenantId(String tenantId) {
profile.withTenantId(tenantId);
Objects.requireNonNull(tenantId);
this.tenantId = tenantId;
return this;
}

@Override
public Azure withSubscription(String subscriptionId) {
profile.withSubscriptionId(subscriptionId);
return new Azure(httpPipeline, profile, this);
return new Azure(httpPipeline, new AzureProfile(tenantId, subscriptionId, environment), this);
}

@Override
public Azure withDefaultSubscription() {
if (profile.subscriptionId() == null) {
profile.withSubscriptionId(Utils.defaultSubscription(this.subscriptions().list()));
if (subscriptionId == null) {
subscriptionId = Utils.defaultSubscription(this.subscriptions().list());
}
return new Azure(httpPipeline, profile, this);
return new Azure(httpPipeline, new AzureProfile(tenantId, subscriptionId, environment), this);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate
//
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate
//
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public static void main(String[] args) {
//=============================================================
// Authenticate

final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE, true);
final AzureProfile profile = new AzureProfile(AzureEnvironment.AZURE);
final TokenCredential credential = new DefaultAzureCredentialBuilder()
.authorityHost(profile.environment().getActiveDirectoryEndpoint())
.build();
Expand Down
Loading