|
42 | 42 | import com.google.firebase.internal.Nullable;
|
43 | 43 |
|
44 | 44 | import java.io.IOException;
|
| 45 | +import java.util.Collection; |
| 46 | +import java.util.HashSet; |
45 | 47 | import java.util.List;
|
46 | 48 | import java.util.Map;
|
| 49 | +import java.util.Set; |
47 | 50 | import java.util.concurrent.atomic.AtomicBoolean;
|
48 | 51 |
|
49 | 52 | /**
|
@@ -601,7 +604,82 @@ protected UserRecord execute() throws FirebaseAuthException {
|
601 | 604 | }
|
602 | 605 |
|
603 | 606 | /**
|
604 |
| - * Gets a page of users starting from the specified {@code pageToken}. Page size will be |
| 607 | + * Gets the user data corresponding to the specified identifiers. |
| 608 | + * |
| 609 | + * <p>There are no ordering guarantees; in particular, the nth entry in the users result list is |
| 610 | + * not guaranteed to correspond to the nth entry in the input parameters list. |
| 611 | + * |
| 612 | + * <p>A maximum of 100 identifiers may be specified. If more than 100 identifiers are |
| 613 | + * supplied, this method throws an {@link IllegalArgumentException}. |
| 614 | + * |
| 615 | + * @param identifiers The identifiers used to indicate which user records should be returned. Must |
| 616 | + * have 100 or fewer entries. |
| 617 | + * @return The corresponding user records. |
| 618 | + * @throws IllegalArgumentException If any of the identifiers are invalid or if more than 100 |
| 619 | + * identifiers are specified. |
| 620 | + * @throws NullPointerException If the identifiers parameter is null. |
| 621 | + * @throws FirebaseAuthException If an error occurs while retrieving user data. |
| 622 | + */ |
| 623 | + public GetUsersResult getUsers(@NonNull Collection<UserIdentifier> identifiers) |
| 624 | + throws FirebaseAuthException { |
| 625 | + return getUsersOp(identifiers).call(); |
| 626 | + } |
| 627 | + |
| 628 | + /** |
| 629 | + * Gets the user data corresponding to the specified identifiers. |
| 630 | + * |
| 631 | + * <p>There are no ordering guarantees; in particular, the nth entry in the users result list is |
| 632 | + * not guaranteed to correspond to the nth entry in the input parameters list. |
| 633 | + * |
| 634 | + * <p>A maximum of 100 identifiers may be specified. If more than 100 identifiers are |
| 635 | + * supplied, this method throws an {@link IllegalArgumentException}. |
| 636 | + * |
| 637 | + * @param identifiers The identifiers used to indicate which user records should be returned. |
| 638 | + * Must have 100 or fewer entries. |
| 639 | + * @return An {@code ApiFuture} that resolves to the corresponding user records. |
| 640 | + * @throws IllegalArgumentException If any of the identifiers are invalid or if more than 100 |
| 641 | + * identifiers are specified. |
| 642 | + * @throws NullPointerException If the identifiers parameter is null. |
| 643 | + */ |
| 644 | + public ApiFuture<GetUsersResult> getUsersAsync(@NonNull Collection<UserIdentifier> identifiers) { |
| 645 | + return getUsersOp(identifiers).callAsync(firebaseApp); |
| 646 | + } |
| 647 | + |
| 648 | + private CallableOperation<GetUsersResult, FirebaseAuthException> getUsersOp( |
| 649 | + @NonNull final Collection<UserIdentifier> identifiers) { |
| 650 | + checkNotDestroyed(); |
| 651 | + checkNotNull(identifiers, "identifiers must not be null"); |
| 652 | + checkArgument(identifiers.size() <= FirebaseUserManager.MAX_GET_ACCOUNTS_BATCH_SIZE, |
| 653 | + "identifiers parameter must have <= " + FirebaseUserManager.MAX_GET_ACCOUNTS_BATCH_SIZE |
| 654 | + + " entries."); |
| 655 | + |
| 656 | + final FirebaseUserManager userManager = getUserManager(); |
| 657 | + return new CallableOperation<GetUsersResult, FirebaseAuthException>() { |
| 658 | + @Override |
| 659 | + protected GetUsersResult execute() throws FirebaseAuthException { |
| 660 | + Set<UserRecord> users = userManager.getAccountInfo(identifiers); |
| 661 | + Set<UserIdentifier> notFound = new HashSet<>(); |
| 662 | + for (UserIdentifier id : identifiers) { |
| 663 | + if (!isUserFound(id, users)) { |
| 664 | + notFound.add(id); |
| 665 | + } |
| 666 | + } |
| 667 | + return new GetUsersResult(users, notFound); |
| 668 | + } |
| 669 | + }; |
| 670 | + } |
| 671 | + |
| 672 | + private boolean isUserFound(UserIdentifier id, Collection<UserRecord> userRecords) { |
| 673 | + for (UserRecord userRecord : userRecords) { |
| 674 | + if (id.matches(userRecord)) { |
| 675 | + return true; |
| 676 | + } |
| 677 | + } |
| 678 | + return false; |
| 679 | + } |
| 680 | + |
| 681 | + /** |
| 682 | + * Gets a page of users starting from the specified {@code pageToken}. Page size is |
605 | 683 | * limited to 1000 users.
|
606 | 684 | *
|
607 | 685 | * @param pageToken A non-empty page token string, or null to retrieve the first page of users.
|
@@ -842,8 +920,67 @@ protected Void execute() throws FirebaseAuthException {
|
842 | 920 | }
|
843 | 921 |
|
844 | 922 | /**
|
845 |
| - * Imports the provided list of users into Firebase Auth. At most 1000 users can be imported at a |
846 |
| - * time. This operation is optimized for bulk imports and will ignore checks on identifier |
| 923 | + * Deletes the users specified by the given identifiers. |
| 924 | + * |
| 925 | + * <p>Deleting a non-existing user does not generate an error (the method is idempotent). |
| 926 | + * Non-existing users are considered to be successfully deleted and are therefore included in the |
| 927 | + * DeleteUsersResult.getSuccessCount() value. |
| 928 | + * |
| 929 | + * <p>A maximum of 1000 identifiers may be supplied. If more than 1000 identifiers are |
| 930 | + * supplied, this method throws an {@link IllegalArgumentException}. |
| 931 | + * |
| 932 | + * <p>This API has a rate limit of 1 QPS. Exceeding the limit may result in a quota exceeded |
| 933 | + * error. If you want to delete more than 1000 users, we suggest adding a delay to ensure you |
| 934 | + * don't exceed this limit. |
| 935 | + * |
| 936 | + * @param uids The uids of the users to be deleted. Must have <= 1000 entries. |
| 937 | + * @return The total number of successful/failed deletions, as well as the array of errors that |
| 938 | + * correspond to the failed deletions. |
| 939 | + * @throw IllegalArgumentException If any of the identifiers are invalid or if more than 1000 |
| 940 | + * identifiers are specified. |
| 941 | + * @throws FirebaseAuthException If an error occurs while deleting users. |
| 942 | + */ |
| 943 | + public DeleteUsersResult deleteUsers(List<String> uids) throws FirebaseAuthException { |
| 944 | + return deleteUsersOp(uids).call(); |
| 945 | + } |
| 946 | + |
| 947 | + /** |
| 948 | + * Similar to {@link #deleteUsers(List)} but performs the operation asynchronously. |
| 949 | + * |
| 950 | + * @param uids The uids of the users to be deleted. Must have <= 1000 entries. |
| 951 | + * @return An {@code ApiFuture} that resolves to the total number of successful/failed |
| 952 | + * deletions, as well as the array of errors that correspond to the failed deletions. If an |
| 953 | + * error occurs while deleting the user account, the future throws a |
| 954 | + * {@link FirebaseAuthException}. |
| 955 | + * @throw IllegalArgumentException If any of the identifiers are invalid or if more than 1000 |
| 956 | + * identifiers are specified. |
| 957 | + */ |
| 958 | + public ApiFuture<DeleteUsersResult> deleteUsersAsync(List<String> uids) { |
| 959 | + return deleteUsersOp(uids).callAsync(firebaseApp); |
| 960 | + } |
| 961 | + |
| 962 | + private CallableOperation<DeleteUsersResult, FirebaseAuthException> deleteUsersOp( |
| 963 | + final List<String> uids) { |
| 964 | + checkNotDestroyed(); |
| 965 | + checkNotNull(uids, "uids must not be null"); |
| 966 | + for (String uid : uids) { |
| 967 | + UserRecord.checkUid(uid); |
| 968 | + } |
| 969 | + checkArgument(uids.size() <= FirebaseUserManager.MAX_DELETE_ACCOUNTS_BATCH_SIZE, |
| 970 | + "uids parameter must have <= " + FirebaseUserManager.MAX_DELETE_ACCOUNTS_BATCH_SIZE |
| 971 | + + " entries."); |
| 972 | + final FirebaseUserManager userManager = getUserManager(); |
| 973 | + return new CallableOperation<DeleteUsersResult, FirebaseAuthException>() { |
| 974 | + @Override |
| 975 | + protected DeleteUsersResult execute() throws FirebaseAuthException { |
| 976 | + return userManager.deleteUsers(uids); |
| 977 | + } |
| 978 | + }; |
| 979 | + } |
| 980 | + |
| 981 | + /** |
| 982 | + * Imports the provided list of users into Firebase Auth. You can import a maximum of 1000 users |
| 983 | + * at a time. This operation is optimized for bulk imports and does not check identifier |
847 | 984 | * uniqueness which could result in duplications.
|
848 | 985 | *
|
849 | 986 | * <p>{@link UserImportOptions} is required to import users with passwords. See
|
|
0 commit comments