diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index f64d93a78..366d9e997 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -16,8 +16,13 @@ package com.google.firebase.auth; +import static com.google.common.base.Preconditions.checkArgument; + import com.google.api.client.util.Key; -import com.google.auto.value.AutoValue; +import com.google.common.base.Strings; +import com.google.common.collect.ImmutableMap; +import java.util.HashMap; +import java.util.Map; /** * Contains metadata associated with a Firebase tenant. @@ -26,7 +31,7 @@ */ public final class Tenant { - @Key("tenantId") + @Key("name") private String tenantId; @Key("displayName") @@ -55,100 +60,136 @@ public boolean isEmailLinkSignInEnabled() { } /** - * Class used to hold the information needs to make a tenant create request. + * Returns a new {@link UpdateRequest}, which can be used to update the attributes + * of this tenant. + * + * @return a non-null Tenant.UpdateRequest instance. */ - @AutoValue - public abstract static class CreateRequest { + public UpdateRequest updateRequest() { + return new UpdateRequest(getTenantId()); + } + + /** + * A specification class for creating new user accounts. + * + *
Set the initial attributes of the new tenant by calling various setter methods available in
+ * this class. None of the attributes are required.
+ */
+ public static final class CreateRequest {
+
+ private final Map The returned object should be passed to {@link TenantManager#createTenant(CreateRequest)}
+ * to register the tenant information persistently.
*/
- public abstract String getDisplayName();
+ public CreateRequest() { }
/**
- * Returns whether to allow email/password user authentication.
+ * Sets the display name for the new tenant.
*
- * @return true if a user can be authenticated using an email and password, and false otherwise.
+ * @param displayName a non-null, non-empty display name string.
*/
- public abstract boolean isPasswordSignInAllowed();
+ public CreateRequest setDisplayName(String displayName) {
+ checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty");
+ properties.put("displayName", displayName);
+ return this;
+ }
/**
- * Returns whether to enable email link user authentication.
+ * Sets whether to allow email/password user authentication.
*
- * @return true if a user can be authenticated using an email link, and false otherwise.
+ * @param passwordSignInAllowed a boolean indicating whether users can be authenticated using
+ * an email and password, and false otherwise.
*/
- public abstract boolean isEmailLinkSignInEnabled();
+ public CreateRequest setPasswordSignInAllowed(boolean passwordSignInAllowed) {
+ properties.put("allowPasswordSignup", passwordSignInAllowed);
+ return this;
+ }
/**
- * Returns a builder for a tenant create request.
+ * Sets whether to enable email link user authentication.
+ *
+ * @param emailLinkSignInEnabled a boolean indicating whether users can be authenticated using
+ * an email link, and false otherwise.
*/
- public static Builder newBuilder() {
- return new AutoValue_Tenant_CreateRequest.Builder();
+ public CreateRequest setEmailLinkSignInEnabled(boolean emailLinkSignInEnabled) {
+ properties.put("enableEmailLinkSignin", emailLinkSignInEnabled);
+ return this;
}
- /**
- * Builder class used to construct a create request.
- */
- @AutoValue.Builder
- abstract static class Builder {
- public abstract Builder setDisplayName(String displayName);
-
- public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn);
-
- public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn);
-
- public abstract CreateRequest build();
+ Map An instance of this class can be obtained via a {@link Tenant} object, or from a tenant ID
+ * string. Specify the changes to be made to the tenant by calling the various setter methods
+ * available in this class.
*/
- @AutoValue
- public abstract static class UpdateRequest {
+ public static final class UpdateRequest {
+
+ private final Map This method allows updating attributes of a tenant account, without first having to call
+ * {@link TenantManager#getTenant(String)}.
*
- * @return a non-empty display name string.
+ * @param tenantId a non-null, non-empty tenant ID string.
+ * @throws IllegalArgumentException If the tenant ID is null or empty.
*/
- public abstract String getDisplayName();
+ public UpdateRequest(String tenantId) {
+ checkArgument(!Strings.isNullOrEmpty(tenantId), "tenant ID must not be null or empty");
+ properties.put("name", tenantId);
+ }
+
+ String getTenantId() {
+ return (String) properties.get("name");
+ }
/**
- * Returns whether to allow email/password user authentication.
+ * Sets the display name of the existingtenant.
*
- * @return true if a user can be authenticated using an email and password, and false otherwise.
+ * @param displayName a non-null, non-empty display name string.
*/
- public abstract boolean isPasswordSignInAllowed();
+ public UpdateRequest setDisplayName(String displayName) {
+ checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty");
+ properties.put("displayName", displayName);
+ return this;
+ }
/**
- * Returns whether to enable email link user authentication.
+ * Sets whether to allow email/password user authentication.
*
- * @return true if a user can be authenticated using an email link, and false otherwise.
+ * @param passwordSignInAllowed a boolean indicating whether users can be authenticated using
+ * an email and password, and false otherwise.
*/
- public abstract boolean isEmailLinkSignInEnabled();
+ public UpdateRequest setPasswordSignInAllowed(boolean passwordSignInAllowed) {
+ properties.put("allowPasswordSignup", passwordSignInAllowed);
+ return this;
+ }
/**
- * Returns a builder for a tenant update request.
+ * Sets whether to enable email link user authentication.
+ *
+ * @param emailLinkSignInEnabled a boolean indicating whether users can be authenticated using
+ * an email link, and false otherwise.
*/
- public static Builder newBuilder() {
- return new AutoValue_Tenant_UpdateRequest.Builder();
+ public UpdateRequest setEmailLinkSignInEnabled(boolean emailLinkSignInEnabled) {
+ properties.put("enableEmailLinkSignin", emailLinkSignInEnabled);
+ return this;
}
- /**
- * Builder class used to construct a update request.
- */
- @AutoValue.Builder
- abstract static class Builder {
- public abstract Builder setDisplayName(String displayName);
-
- public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn);
-
- public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn);
-
- public abstract UpdateRequest build();
+ Map