|
29 | 29 | import com.google.common.base.Strings; |
30 | 30 | import com.google.firebase.FirebaseApp; |
31 | 31 | import com.google.firebase.ImplFirebaseTrampolines; |
| 32 | +import com.google.firebase.auth.FirebaseUserManager.UserImportRequest; |
32 | 33 | import com.google.firebase.auth.ListUsersPage.DefaultUserSource; |
33 | 34 | import com.google.firebase.auth.ListUsersPage.PageFactory; |
34 | 35 | import com.google.firebase.auth.UserRecord.CreateRequest; |
|
42 | 43 | import com.google.firebase.internal.Nullable; |
43 | 44 | import java.io.IOException; |
44 | 45 | import java.security.GeneralSecurityException; |
| 46 | +import java.util.List; |
45 | 47 | import java.util.Map; |
46 | 48 | import java.util.concurrent.atomic.AtomicBoolean; |
47 | 49 |
|
@@ -860,6 +862,86 @@ protected Void execute() throws FirebaseAuthException { |
860 | 862 | }; |
861 | 863 | } |
862 | 864 |
|
| 865 | + /** |
| 866 | + * Imports the provided list of users into Firebase Auth. At most 1000 users can be imported at a |
| 867 | + * time. This operation is optimized for bulk imports and will ignore checks on identifier |
| 868 | + * uniqueness which could result in duplications. |
| 869 | + * |
| 870 | + * <p>{@link UserImportOptions} is required to import users with passwords. See |
| 871 | + * {@link #importUsers(List, UserImportOptions)}. |
| 872 | + * |
| 873 | + * @param users A non-empty list of users to be imported. Length must not exceed 1000. |
| 874 | + * @return A {@link UserImportResult} instance. |
| 875 | + * @throws IllegalArgumentException If the users list is null, empty or has more than 1000 |
| 876 | + * elements. Or if at least one user specifies a password. |
| 877 | + * @throws FirebaseAuthException If an error occurs while importing users. |
| 878 | + */ |
| 879 | + public UserImportResult importUsers(List<ImportUserRecord> users) throws FirebaseAuthException { |
| 880 | + return importUsers(users, null); |
| 881 | + } |
| 882 | + |
| 883 | + /** |
| 884 | + * Imports the provided list of users into Firebase Auth. At most 1000 users can be imported at a |
| 885 | + * time. This operation is optimized for bulk imports and will ignore checks on identifier |
| 886 | + * uniqueness which could result in duplications. |
| 887 | + * |
| 888 | + * @param users A non-empty list of users to be imported. Length must not exceed 1000. |
| 889 | + * @param options a {@link UserImportOptions} instance or null. Required when importing users |
| 890 | + * with passwords. |
| 891 | + * @return A {@link UserImportResult} instance. |
| 892 | + * @throws IllegalArgumentException If the users list is null, empty or has more than 1000 |
| 893 | + * elements. Or if at least one user specifies a password, and options is null. |
| 894 | + * @throws FirebaseAuthException If an error occurs while importing users. |
| 895 | + */ |
| 896 | + public UserImportResult importUsers(List<ImportUserRecord> users, |
| 897 | + @Nullable UserImportOptions options) throws FirebaseAuthException { |
| 898 | + return importUsersOp(users, options).call(); |
| 899 | + } |
| 900 | + |
| 901 | + /** |
| 902 | + * Similar to {@link #importUsers(List)} but performs the operation asynchronously. |
| 903 | + * |
| 904 | + * @param users A non-empty list of users to be imported. Length must not exceed 1000. |
| 905 | + * @return An {@code ApiFuture} which will complete successfully when the user accounts are |
| 906 | + * imported. If an error occurs while importing the users, the future throws a |
| 907 | + * {@link FirebaseAuthException}. |
| 908 | + * @throws IllegalArgumentException If the users list is null, empty or has more than 1000 |
| 909 | + * elements. Or if at least one user specifies a password. |
| 910 | + */ |
| 911 | + public ApiFuture<UserImportResult> importUsersAsync(List<ImportUserRecord> users) { |
| 912 | + return importUsersAsync(users, null); |
| 913 | + } |
| 914 | + |
| 915 | + /** |
| 916 | + * Similar to {@link #importUsers(List, UserImportOptions)} but performs the operation |
| 917 | + * asynchronously. |
| 918 | + * |
| 919 | + * @param users A non-empty list of users to be imported. Length must not exceed 1000. |
| 920 | + * @param options a {@link UserImportOptions} instance or null. Required when importing users |
| 921 | + * with passwords. |
| 922 | + * @return An {@code ApiFuture} which will complete successfully when the user accounts are |
| 923 | + * imported. If an error occurs while importing the users, the future throws a |
| 924 | + * {@link FirebaseAuthException}. |
| 925 | + * @throws IllegalArgumentException If the users list is null, empty or has more than 1000 |
| 926 | + * elements. Or if at least one user specifies a password, and options is null. |
| 927 | + */ |
| 928 | + public ApiFuture<UserImportResult> importUsersAsync(List<ImportUserRecord> users, |
| 929 | + @Nullable UserImportOptions options) { |
| 930 | + return importUsersOp(users, options).callAsync(firebaseApp); |
| 931 | + } |
| 932 | + |
| 933 | + private CallableOperation<UserImportResult, FirebaseAuthException> importUsersOp( |
| 934 | + List<ImportUserRecord> users, UserImportOptions options) { |
| 935 | + checkNotDestroyed(); |
| 936 | + final UserImportRequest request = new UserImportRequest(users, options, jsonFactory); |
| 937 | + return new CallableOperation<UserImportResult, FirebaseAuthException>() { |
| 938 | + @Override |
| 939 | + protected UserImportResult execute() throws FirebaseAuthException { |
| 940 | + return userManager.importUsers(request); |
| 941 | + } |
| 942 | + }; |
| 943 | + } |
| 944 | + |
863 | 945 | @VisibleForTesting |
864 | 946 | FirebaseUserManager getUserManager() { |
865 | 947 | return this.userManager; |
|
0 commit comments