将批量用户从本地数据库上载到java中的azure b2c active directory

watbbzwu  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(346)

我正在尝试用java制作一个控制台应用程序,通过它我想将100000多个用户迁移到azureadb2c。
为此,我们使用graph api。
我创建了一个json格式的文件,其中包含一个用户列表,如下所示:

{
  "users": [
    {
      "displayName": "Amanda Polly",
      "givenName": "Amanda",
      "surname": "Polly",
      "extension_user_type": "user",
      "identities": [
        {
          "signInType": "emailAddress",
          "issuerAssignedId": "amandapolly@gmail.com"
        }
      ],
      "extension_timezone": "PST",
      "extension_locale": "en-US",
      "extension_tenant": "EG1234"
    },
    {
      "displayName": "Lowa Doe",
      "givenName": "Lowa",
      "surname": "Doe",
      "extension_user_type": "user",
      "identities": [
        {
          "signInType": "userName",
          "issuerAssignedId": "lowadow123"
        }
      ],
      "extension_timezone": "PST",
      "extension_locale": "en-US",
      "extension_tenant": "EG1234"
    }
   ]
}

我有这个在一个(点)json文件,我要用这个文件和创建用户在b2c活动目录使用图形api,需要帮助启动。

vqlkdk9b

vqlkdk9b1#

用户graph api并发送post请求,如下所示
设置所有字段,然后像这样计算。

User createNewUser = new User();
        createNewUser.displayName = displayName;

        if (givenName.equals(null) || givenName.isEmpty() || givenName.equals("") || givenName.equals(" ")) {
            LOG.warn("givenName is empty");
        } else {
            createNewUser.givenName = givenName;
        }

        if (surname.equals(null) || surname.isEmpty() || surname.equals("") || surname.equals(" ")) {
            LOG.warn("surname is empty");
        } else {
            createNewUser.surname = surname;
        }

        final LinkedList<ObjectIdentity> identitiesList = new LinkedList<ObjectIdentity>();
        ObjectIdentity identities = new ObjectIdentity();

        identities.signInType = signInType;
        identities.issuerAssignedId = issuerAssignedId;
        identities.issuer = "controlme.onmicrosoft.com";
        identitiesList.add(identities);

        createNewUser.identities = identitiesList;

        PasswordProfile passwordProfile = new PasswordProfile();
        passwordProfile.password = generatePassword(15);
        passwordProfile.forceChangePasswordNextSignIn = false;

        createNewUser.passwordProfile = passwordProfile;
        createNewUser.passwordPolicies = "DisablePasswordExpiration";

User buildUserRequest = graphClient.users()
                .buildRequest()
                .post(createNewUser);

相关问题