java - 从 MS Azure Active Directory 获取用户组

标签 java azure active-directory

我正在尝试获取用户所属的所有组。当我运行下面的代码时,出现 405 错误。我没有正确调用资源吗?如下:https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/users-operations#GetUsersMemberships

 @RequestMapping(value="/groups", method = { RequestMethod.GET, RequestMethod.POST })
public JSONArray getMembersOf(HttpServletRequest httpRequest) {
    try {
           HttpSession session = httpRequest.getSession();
           AuthenticationResult result =
               (AuthenticationResult) session.getAttribute(AuthHelper.PRINCIPAL_SESSION_NAME);
           String accessToken = result.getAccessToken();
           String tenant = session.getServletContext().getInitParameter("tenant");
           URL url =
               new URL(String.format("https://graph.windows.net/%s/users/userId@abc.onmicrosoft.com/getMemberGroups?api-version=2013-04-05",
                                     tenant, accessToken));
           HttpURLConnection conn = (HttpURLConnection) url.openConnection();
           // Set the appropriate header fields in the request header.
           conn.setRequestProperty("api-version", "2013-04-05");
           conn.setRequestProperty("Authorization", accessToken);
           conn.setRequestProperty("Accept", "application/json;odata=minimalmetadata");
           String goodRespStr = HttpClientHelper.getResponseStringFromConn(conn, true);
           System.out.println("REsponse is --------------->>>>>  "+goodRespStr);
       } catch (MalformedURLException e) {
           e.printStackTrace();
       } catch (IOException e) {
           e.printStackTrace();
       }

错误:

java.io.IOException: Server returned HTTP response code: 405 for URL: https://graph.windows.net/abc.onmicrosoft.com/users/userId@abc.onmicrosoft.com/getMemberGroups?api-version=2013-04-05

最佳答案

根据您的代码,根据我的理解,我认为您想要获取包含用户所属组的对象 ID 的集合,即 Azure AD REST API Get Member Groups for Users 。服务器返回的错误代码似乎意味着 Method Not allowed ,您可以引用 HTTP RFC doc10.4.6 405 Method Not Allowed 部分。

我认为该问题可能是由于使用了过时的 api-version 值引起的,请使用 1.6 而不是 2013-04-05 > 在您的代码中然后重试。

如有任何更新,请随时告诉我。

关于java - 从 MS Azure Active Directory 获取用户组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41717261/

相关文章:

powershell - 如何使用Powershell将manager-DN转换为变量内的电子邮件地址

java - 我应该使用哪种类型来表示 Java 中的任意 blob?

java - GWT自动刷新代码跳转至首页

php - 从 PHP Web 应用程序根据 Azure Active Directory 对用户进行身份验证

powershell - 使用 Powershell 编辑/修改 GPO

azure - 'Windows Azure' 和 'AWS Amazon' 的区别?

java - JToggleButton - 如何更改颜色?

java - 我不知道我在这个java递归问题上做错了什么!我在下面发布了练习和我的代码

arrays - 如何使用graph api在azure b2c中创建多个用户?

c# - 在 Azure Key Vault 上存储长字符串