将批量用户上传从本地数据库移至Azure B2C活动目录中,使用JAVA。

huangapple go评论77阅读模式
英文:

move bulk users upload from local db to azure b2c active directory in JAVA

问题

我正在尝试创建一个 Java 控制台应用程序,通过该应用程序,我想将超过 100,000 个用户迁移到 Azure AD B2C。

我们将使用 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"
    }
   ]
}

我将这个内容保存在一个(dot)json文件中,我需要使用这个文件,并使用 Graph API 在 B2C 活动目录中创建用户。在开始时需要帮助。

英文:

I am trying to make a console app in java through which I want to migrate more than 100000 users to Azure AD B2C.

We are using Graph API for this purpose.

I have created a JSON format file which has a list of users, looks like below :

{
  "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"
    }
   ]
}

I have this in a (dot)json file, i have to use this file and create users in b2c active directory using graph API, need help in starting.

答案1

得分: 1

以下是翻译好的部分:

用户图形 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);
英文:

User graph api and send a post request, like this

Set all the fields and then work it out like this.

User createNewUser = new User();
        createNewUser.displayName = displayName;
        
        if (givenName.equals(null) || givenName.isEmpty() || givenName.equals(&quot;&quot;) || givenName.equals(&quot; &quot;)) {
            LOG.warn(&quot;givenName is empty&quot;);
        } else {
            createNewUser.givenName = givenName;
        }
        
        if (surname.equals(null) || surname.isEmpty() || surname.equals(&quot;&quot;) || surname.equals(&quot; &quot;)) {
            LOG.warn(&quot;surname is empty&quot;);
        } else {
            createNewUser.surname = surname;
        }
        
        final LinkedList&lt;ObjectIdentity&gt; identitiesList = new LinkedList&lt;ObjectIdentity&gt;();
        ObjectIdentity identities = new ObjectIdentity();
        
        identities.signInType = signInType;
        identities.issuerAssignedId = issuerAssignedId;
        identities.issuer = &quot;controlme.onmicrosoft.com&quot;;
        identitiesList.add(identities);

        createNewUser.identities = identitiesList;

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

        createNewUser.passwordProfile = passwordProfile;
        createNewUser.passwordPolicies = &quot;DisablePasswordExpiration&quot;;
    

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

huangapple
  • 本文由 发表于 2020年8月20日 13:23:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63498770.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定