使用GraphAPI SDK查询用户组成员失败

问题描述 投票:0回答:1

我正在升级我拥有的应用程序的各种依赖项,该应用程序查询 GraphAPI 以获取一些用户详细信息。我正在从 GraphAPI 版本 5.x 升级到 6.5.x(最新),并且查询组成员身份似乎无法正常工作(似乎在 5.x 中工作)。

我的代码如下:

    public List<Group> fetchGroupMemberships(String userId) {
        if (StringUtils.isEmpty(userId)) {
            log.warn("Cannot fetch group memberships for null user or a user with an empty/null id...");
            return List.of();
        }
        var groupMemberPage = client.users()
                .byUserId(userId)
                .memberOf()
                .get();

        var fetched = new ArrayList<Group>();
        while (groupMemberPage != null) {
            var groups = groupMemberPage.getValue() != null ? groupMemberPage.getValue()
                    .stream()
                    .filter(object -> object instanceof Group)
                    .map(object -> (Group) object)
                    .toList() : null;
            if (CollectionUtils.isNotEmpty(groups)) {
                log.debug("Appending groups {} to existing list...", groups);
                fetched.addAll(groups);
            }
            var odataNext = groupMemberPage.getOdataNextLink();
            if (StringUtils.isEmpty(odataNext)) {
                log.debug("No more groups to fetch. Breaking...");
                break;
            } else {
                log.debug("Fetching next page of groups...");
                groupMemberPage = client.users()
                        .byUserId(userId)
                        .withUrl(odataNext)
                        .memberOf()
                        .get();
            }
        }
        return fetched;
    }

如您所见,我传入一个

userId
并使用它简单地查询该用户的成员资格。但是,当我这样做时,会发生以下异常:

java.lang.IllegalStateException: Not a JSON Array: {"@odata.type":"#microsoft.graph.group","id":"<uuid-of-group>","deletedDateTime":null,"classification":null,"createdDateTime":null,"creationOptions":[],"description":null,"displayName":null,"expirationDateTime":null,"groupTypes":[],"isAssignableToRole":null,"mail":null,"mailEnabled":null,"mailNickname":null,"membershipRule":null,"membershipRuleProcessingState":null,"onPremisesDomainName":null,"onPremisesLastSyncDateTime":null,"onPremisesNetBiosName":null,"onPremisesSamAccountName":null,"onPremisesSecurityIdentifier":null,"onPremisesSyncEnabled":null,"preferredDataLocation":null,"preferredLanguage":null,"proxyAddresses":[],"renewedDateTime":null,"resourceBehaviorOptions":[],"resourceProvisioningOptions":[],"securityEnabled":null,"securityIdentifier":null,"theme":null,"uniqueName":null,"visibility":null,"onPremisesProvisioningErrors":[],"serviceProvisioningErrors":[]}
    at com.google.gson.JsonElement.getAsJsonArray(JsonElement.java:117)
    at com.microsoft.kiota.serialization.JsonParseNode.iterateOnArray(JsonParseNode.java:167)
    at com.microsoft.kiota.serialization.JsonParseNode.getUntypedValue(JsonParseNode.java:245)
    at com.microsoft.kiota.serialization.JsonParseNode.tryGetAnything(JsonParseNode.java:317)
    at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:299)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:213)
    at com.microsoft.kiota.serialization.JsonParseNode.lambda$getCollectionOfObjectValues$1(JsonParseNode.java:195)
    at com.microsoft.kiota.serialization.JsonParseNode.iterateOnArray(JsonParseNode.java:175)
    at com.microsoft.kiota.serialization.JsonParseNode.getCollectionOfObjectValues(JsonParseNode.java:195)
    at com.microsoft.graph.models.DirectoryObjectCollectionResponse.lambda$getFieldDeserializers$0(DirectoryObjectCollectionResponse.java:34)
    at com.microsoft.kiota.serialization.JsonParseNode.assignFieldValues(JsonParseNode.java:297)
    at com.microsoft.kiota.serialization.JsonParseNode.getObjectValue(JsonParseNode.java:213)
    at com.microsoft.kiota.http.OkHttpRequestAdapter.send(OkHttpRequestAdapter.java:296)
    at com.microsoft.graph.users.item.memberof.MemberOfRequestBuilder.get(MemberOfRequestBuilder.java:110)
    at com.microsoft.graph.users.item.memberof.MemberOfRequestBuilder.get(MemberOfRequestBuilder.java:96)

据我所知,客户端似乎无法解析 JSON 响应,但我无法理解为什么会出现这种情况。我正在使用官方文档中提到的方法,可以在here找到。

我可以简单地回滚到我知道有效的最新版本(5.x),但我想了解我面临的问题。作为参考,我认为它可能与this有关,但我不是100%确定。

如有任何帮助,我们将不胜感激!

java spring-boot azure microsoft-graph-api azure-ad-graph-api
1个回答
0
投票

1.12.0 中具有 azure-identity 的 microsoft-graph 6.6.0 版本已修复该问题。

<dependency>
    <groupId>com.microsoft.graph</groupId>
    <artifactId>microsoft-graph</artifactId>
    <version>6.6.0</version>
</dependency>
<dependency>
    <groupId>com.microsoft.graph</groupId>
    <artifactId>microsoft-graph-beta</artifactId>
    <version>6.6.0</version>
</dependency>
<dependency>
    <groupId>com.azure</groupId>
    <artifactId>azure-identity</artifactId>
    <version>1.12.0</version>
</dependency>
© www.soinside.com 2019 - 2024. All rights reserved.