本文整理汇总了Java中com.microsoft.azure.management.Azure.Authenticated方法的典型用法代码示例。如果您正苦于以下问题:Java Azure.Authenticated方法的具体用法?Java Azure.Authenticated怎么用?Java Azure.Authenticated使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.microsoft.azure.management.Azure
的用法示例。
在下文中一共展示了Azure.Authenticated方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createActiveDirectoryApplication
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
private static ActiveDirectoryApplication createActiveDirectoryApplication(Azure.Authenticated authenticated) throws Exception {
String name = SdkContext.randomResourceName("adapp-sample", 20);
//create a self-sighed certificate
String domainName = name + ".com";
String certPassword = "StrongPass!12";
Certificate certificate = Certificate.createSelfSigned(domainName, certPassword);
// create Active Directory application
ActiveDirectoryApplication activeDirectoryApplication = authenticated.activeDirectoryApplications()
.define(name)
.withSignOnUrl("https://github.com/Azure/azure-sdk-for-java/" + name)
// password credentials definition
.definePasswordCredential("password")
.withPasswordValue("[email protected]")
.withDuration(Duration.standardDays(700))
.attach()
// certificate credentials definition
.defineCertificateCredential("cert")
.withAsymmetricX509Certificate()
.withPublicKey(Files.readAllBytes(Paths.get(certificate.getCerPath())))
.withDuration(Duration.standardDays(100))
.attach()
.create();
System.out.println(activeDirectoryApplication.id() + " - " + activeDirectoryApplication.applicationId());
return activeDirectoryApplication;
}
示例2: main
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
/**
* Main entry point.
*
* @param args the parameters
*/
public static void main(String[] args) {
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
Azure.Authenticated authenticated = Azure.configure()
.withLogLevel(LogLevel.BODY)
.authenticate(credentials);
runSample(authenticated, credentials.defaultSubscriptionId());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
开发者ID:Azure-Samples,项目名称:aad-java-manage-users-groups-and-roles,代码行数:20,代码来源:ManageUsersGroupsAndRoles.java
示例3: main
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
/**
* Main entry point.
* @param args the parameters
*/
public static void main(String[] args) {
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
Azure.Authenticated authenticated = Azure.configure()
.withLogLevel(LogLevel.BODY)
.authenticate(credFile);
String defaultSubscriptionId = authenticated.subscriptions().list().get(0).subscriptionId();
runSample(authenticated, defaultSubscriptionId);
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
示例4: runSample
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
/**
* Main function which runs the actual sample.
* @param authenticated instance of Authenticated
* @param defaultSubscriptionId default subscription id
* @return true if sample runs successfully
*/
public static boolean runSample(Azure.Authenticated authenticated, String defaultSubscriptionId) {
ActiveDirectoryApplication activeDirectoryApplication = null;
try {
String authFileName = "myAuthFile.azureauth";
String authFilePath = Paths.get(getBasePath(), authFileName).toString();
activeDirectoryApplication =
createActiveDirectoryApplication(authenticated);
ServicePrincipal servicePrincipal =
createServicePrincipalWithRoleForApplicationAndExportToFile(
authenticated,
activeDirectoryApplication,
BuiltInRole.CONTRIBUTOR,
defaultSubscriptionId,
authFilePath);
SdkContext.sleep(15000);
useAuthFile(authFilePath);
manageApplication(authenticated, activeDirectoryApplication);
manageServicePrincipal(authenticated, servicePrincipal);
return true;
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
} finally {
if (activeDirectoryApplication != null) {
// this will delete Service Principal as well
authenticated.activeDirectoryApplications().deleteById(activeDirectoryApplication.id());
}
}
return false;
}
示例5: createServicePrincipalWithRoleForApplicationAndExportToFile
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
private static ServicePrincipal createServicePrincipalWithRoleForApplicationAndExportToFile(
Azure.Authenticated authenticated,
ActiveDirectoryApplication activeDirectoryApplication,
BuiltInRole role,
String subscriptionId,
String authFilePath) throws Exception {
String name = SdkContext.randomResourceName("sp-sample", 20);
//create a self-sighed certificate
String domainName = name + ".com";
String certPassword = "StrongPass!12";
Certificate certificate = Certificate.createSelfSigned(domainName, certPassword);
// create a Service Principal and assign it to a subscription with the role Contributor
return authenticated.servicePrincipals()
.define("name")
.withExistingApplication(activeDirectoryApplication)
// password credentials definition
.definePasswordCredential("ServicePrincipalAzureSample")
.withPasswordValue("StrongPass!12")
.attach()
// certificate credentials definition
.defineCertificateCredential("spcert")
.withAsymmetricX509Certificate()
.withPublicKey(Files.readAllBytes(Paths.get(certificate.getCerPath())))
.withDuration(Duration.standardDays(7))
// export the credentials to the file
.withAuthFileToExport(new FileOutputStream(authFilePath))
.withPrivateKeyFile(certificate.getPfxPath())
.withPrivateKeyPassword(certPassword)
.attach()
.withNewRoleInSubscription(role, subscriptionId)
.create();
}
示例6: manageApplication
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
private static void manageApplication(Azure.Authenticated authenticated, ActiveDirectoryApplication activeDirectoryApplication) {
activeDirectoryApplication.update()
// add another password credentials
.definePasswordCredential("password-1")
.withPasswordValue("[email protected]")
.withDuration(Duration.standardDays(700))
.attach()
// add a reply url
.withReplyUrl("http://localhost:8080")
.apply();
}
示例7: main
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
/**
* Main entry point.
*
* @param args the parameters
*/
public static void main(String[] args) {
try {
final File credFile = new File(System.getenv("AZURE_AUTH_LOCATION"));
ApplicationTokenCredentials credentials = ApplicationTokenCredentials.fromFile(credFile);
Azure.Authenticated authenticated = Azure.configure()
.withLogLevel(LogLevel.BASIC)
.authenticate(credentials);
runSample(authenticated, credentials.defaultSubscriptionId(), credentials.environment());
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
示例8: testGetAuthObjFromServerId
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
@Test
public void testGetAuthObjFromServerId() {
final AzureAuthHelper helper = new AzureAuthHelper(mojo);
/**
* serverId is null
*/
Azure.Authenticated auth = helper.getAuthObjFromServerId(null, null);
assertNull(auth);
clearInvocations(mojo);
/**
* settings is null
*/
auth = helper.getAuthObjFromServerId(null, "serverId");
assertNull(auth);
clearInvocations(mojo);
// Setup
final AzureAuthHelper helperSpy = spy(helper);
when(settings.getServer(any(String.class))).thenReturn(server);
/**
* ApplicationTokenCredentials is null
*/
doReturn(null).when(helperSpy).getAppTokenCredentialsFromServer(server);
auth = helper.getAuthObjFromServerId(settings, "serverId");
assertNull(auth);
verify(settings, times(1)).getServer(any(String.class));
verifyNoMoreInteractions(settings);
clearInvocations(settings);
/**
* success
*/
doReturn(credentials).when(helperSpy).getAppTokenCredentialsFromServer(server);
doReturn(configurable).when(helperSpy).azureConfigure();
when(configurable.authenticate(any(ApplicationTokenCredentials.class))).thenReturn(authenticated);
auth = helperSpy.getAuthObjFromServerId(settings, "serverId");
assertSame(authenticated, auth);
}
示例9: testGetAuthObjFromFile
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
@Test
public void testGetAuthObjFromFile() throws Exception {
final AzureAuthHelper helper = new AzureAuthHelper(mojo);
/**
* authFile is null
*/
Azure.Authenticated auth = helper.getAuthObjFromFile(null);
assertNull(auth);
clearInvocations(mojo);
/**
* authFile does not exist
*/
when(file.exists()).thenReturn(false);
auth = helper.getAuthObjFromFile(file);
assertNull(auth);
clearInvocations(mojo);
// Setup
final AzureAuthHelper helperSpy = spy(helper);
/**
* read authFile exception
*/
when(file.exists()).thenReturn(true);
doReturn(configurable).when(helperSpy).azureConfigure();
when(configurable.authenticate(any(File.class))).thenThrow(new IOException("Fail to read file."));
auth = helperSpy.getAuthObjFromFile(file);
assertNull(auth);
/**
* success
*/
when(file.exists()).thenReturn(true);
doReturn(configurable).when(helperSpy).azureConfigure();
when(configurable.authenticate(any(File.class))).thenReturn(authenticated);
auth = helperSpy.getAuthObjFromFile(file);
assertSame(authenticated, auth);
}
示例10: manageServicePrincipal
import com.microsoft.azure.management.Azure; //导入方法依赖的package包/类
private static void manageServicePrincipal(Azure.Authenticated authenticated, ServicePrincipal servicePrincipal) {
servicePrincipal.update()
.withoutCredential("ServicePrincipalAzureSample")
.withoutRole(servicePrincipal.roleAssignments().iterator().next())
.apply();
}