使用Java使用用户名和密码连接到Azure广告的方法是什么我使用python打印azure目录的所有用户,但找不到在Java中使用用户名和密码进行连接的方法...
from azure.common.credentials import UserPassCredentials
from azure.graphrbac import GraphRbacManagementClient
credentials = UserPassCredentials("username", "password", resource="https://graph.windows.net")
tenant_id = 'tenant id'
graphrbac_client = GraphRbacManagementClient(credentials,tenant_id)
users = graphrbac_client.users.list()
for user in users:
print(f"Display name={user.display_name}UserPrincipleName={user.user_principal_name}")
任务是通过使用用户名和密码建立连接来打印目录中的所有用户
[Microsoft Graph支持Azure AD Graph公开的所有功能,建议使用Microsoft Graph。
通过Gradle安装依赖项:
将Microsoft-graph-auth的存储库和编译依赖项添加到项目的build.gradle中
repository {
jcenter()
jcenter{
url 'http://oss.jfrog.org/artifactory/oss-snapshot-local'
}
}
dependency {
// Include the sdk as a dependency
compile('com.microsoft.graph:microsoft-graph-auth:0.1.0-SNAPSHOT')
}
这里是一个工作示例供您参考:
public static void main(String [] rags){
UsernamePasswordProvider authProvider = new UsernamePasswordProvider("{client_id}", Arrays.asList("https://graph.microsoft.com/User.Read.All") , "{username}", "{password}", NationalCloud.Global, "{tenant}", "{cient_secret}");
IGraphServiceClient graphClient = GraphServiceClient
.builder()
.authenticationProvider(authProvider)
.buildClient();
IUserCollectionPage userCollectionPage = graphClient.users().buildRequest().get();
List<User> userList=userCollectionPage.getCurrentPage();
}
注:记住要在门户中添加Microsoft graph api权限并授予管理员同意。
参考: