|
16 | 16 |
|
17 | 17 | package com.google.firebase.auth;
|
18 | 18 |
|
| 19 | +import static com.google.common.base.Preconditions.checkArgument; |
| 20 | + |
19 | 21 | import com.google.api.client.util.Key;
|
20 |
| -import com.google.auto.value.AutoValue; |
| 22 | +import com.google.common.base.Strings; |
| 23 | +import com.google.common.collect.ImmutableMap; |
| 24 | +import java.util.HashMap; |
| 25 | +import java.util.Map; |
21 | 26 |
|
22 | 27 | /**
|
23 | 28 | * Contains metadata associated with a Firebase tenant.
|
|
26 | 31 | */
|
27 | 32 | public final class Tenant {
|
28 | 33 |
|
29 |
| - @Key("tenantId") |
| 34 | + @Key("name") |
30 | 35 | private String tenantId;
|
31 | 36 |
|
32 | 37 | @Key("displayName")
|
@@ -55,100 +60,136 @@ public boolean isEmailLinkSignInEnabled() {
|
55 | 60 | }
|
56 | 61 |
|
57 | 62 | /**
|
58 |
| - * Class used to hold the information needs to make a tenant create request. |
| 63 | + * Returns a new {@link UpdateRequest}, which can be used to update the attributes |
| 64 | + * of this tenant. |
| 65 | + * |
| 66 | + * @return a non-null Tenant.UpdateRequest instance. |
59 | 67 | */
|
60 |
| - @AutoValue |
61 |
| - public abstract static class CreateRequest { |
| 68 | + public UpdateRequest updateRequest() { |
| 69 | + return new UpdateRequest(getTenantId()); |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * A specification class for creating new user accounts. |
| 74 | + * |
| 75 | + * <p>Set the initial attributes of the new tenant by calling various setter methods available in |
| 76 | + * this class. None of the attributes are required. |
| 77 | + */ |
| 78 | + public static final class CreateRequest { |
| 79 | + |
| 80 | + private final Map<String,Object> properties = new HashMap<>(); |
62 | 81 |
|
63 | 82 | /**
|
64 |
| - * Returns the display name of this tenant. |
| 83 | + * Creates a new {@link CreateRequest}, which can be used to create a new tenant. |
65 | 84 | *
|
66 |
| - * @return a non-empty display name string. |
| 85 | + * <p>The returned object should be passed to {@link TenantManager#createTenant(CreateRequest)} |
| 86 | + * to register the tenant information persistently. |
67 | 87 | */
|
68 |
| - public abstract String getDisplayName(); |
| 88 | + public CreateRequest() { } |
69 | 89 |
|
70 | 90 | /**
|
71 |
| - * Returns whether to allow email/password user authentication. |
| 91 | + * Sets the display name for the new tenant. |
72 | 92 | *
|
73 |
| - * @return true if a user can be authenticated using an email and password, and false otherwise. |
| 93 | + * @param displayName a non-null, non-empty display name string. |
74 | 94 | */
|
75 |
| - public abstract boolean isPasswordSignInAllowed(); |
| 95 | + public CreateRequest setDisplayName(String displayName) { |
| 96 | + checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty"); |
| 97 | + properties.put("displayName", displayName); |
| 98 | + return this; |
| 99 | + } |
76 | 100 |
|
77 | 101 | /**
|
78 |
| - * Returns whether to enable email link user authentication. |
| 102 | + * Sets whether to allow email/password user authentication. |
79 | 103 | *
|
80 |
| - * @return true if a user can be authenticated using an email link, and false otherwise. |
| 104 | + * @param passwordSignInAllowed a boolean indicating whether users can be authenticated using |
| 105 | + * an email and password, and false otherwise. |
81 | 106 | */
|
82 |
| - public abstract boolean isEmailLinkSignInEnabled(); |
| 107 | + public CreateRequest setPasswordSignInAllowed(boolean passwordSignInAllowed) { |
| 108 | + properties.put("allowPasswordSignup", passwordSignInAllowed); |
| 109 | + return this; |
| 110 | + } |
83 | 111 |
|
84 | 112 | /**
|
85 |
| - * Returns a builder for a tenant create request. |
| 113 | + * Sets whether to enable email link user authentication. |
| 114 | + * |
| 115 | + * @param emailLinkSignInEnabled a boolean indicating whether users can be authenticated using |
| 116 | + * an email link, and false otherwise. |
86 | 117 | */
|
87 |
| - public static Builder newBuilder() { |
88 |
| - return new AutoValue_Tenant_CreateRequest.Builder(); |
| 118 | + public CreateRequest setEmailLinkSignInEnabled(boolean emailLinkSignInEnabled) { |
| 119 | + properties.put("enableEmailLinkSignin", emailLinkSignInEnabled); |
| 120 | + return this; |
89 | 121 | }
|
90 | 122 |
|
91 |
| - /** |
92 |
| - * Builder class used to construct a create request. |
93 |
| - */ |
94 |
| - @AutoValue.Builder |
95 |
| - abstract static class Builder { |
96 |
| - public abstract Builder setDisplayName(String displayName); |
97 |
| - |
98 |
| - public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn); |
99 |
| - |
100 |
| - public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); |
101 |
| - |
102 |
| - public abstract CreateRequest build(); |
| 123 | + Map<String, Object> getProperties() { |
| 124 | + return ImmutableMap.copyOf(properties); |
103 | 125 | }
|
104 | 126 | }
|
105 | 127 |
|
106 | 128 | /**
|
107 |
| - * Class used to hold the information needs to make a tenant update request. |
| 129 | + * A class for updating the attributes of an existing tenant. |
| 130 | + * |
| 131 | + * <p>An instance of this class can be obtained via a {@link Tenant} object, or from a tenant ID |
| 132 | + * string. Specify the changes to be made to the tenant by calling the various setter methods |
| 133 | + * available in this class. |
108 | 134 | */
|
109 |
| - @AutoValue |
110 |
| - public abstract static class UpdateRequest { |
| 135 | + public static final class UpdateRequest { |
| 136 | + |
| 137 | + private final Map<String,Object> properties = new HashMap<>(); |
111 | 138 |
|
112 | 139 | /**
|
113 |
| - * Returns the display name of this tenant. |
| 140 | + * Creates a new {@link UpdateRequest}, which can be used to update the attributes of the |
| 141 | + * of the tenant identified by the specified tenant ID. |
| 142 | + * |
| 143 | + * <p>This method allows updating attributes of a tenant account, without first having to call |
| 144 | + * {@link TenantManager#getTenant(String)}. |
114 | 145 | *
|
115 |
| - * @return a non-empty display name string. |
| 146 | + * @param tenantId a non-null, non-empty tenant ID string. |
| 147 | + * @throws IllegalArgumentException If the tenant ID is null or empty. |
116 | 148 | */
|
117 |
| - public abstract String getDisplayName(); |
| 149 | + public UpdateRequest(String tenantId) { |
| 150 | + checkArgument(!Strings.isNullOrEmpty(tenantId), "tenant ID must not be null or empty"); |
| 151 | + properties.put("name", tenantId); |
| 152 | + } |
| 153 | + |
| 154 | + String getTenantId() { |
| 155 | + return (String) properties.get("name"); |
| 156 | + } |
118 | 157 |
|
119 | 158 | /**
|
120 |
| - * Returns whether to allow email/password user authentication. |
| 159 | + * Sets the display name of the existingtenant. |
121 | 160 | *
|
122 |
| - * @return true if a user can be authenticated using an email and password, and false otherwise. |
| 161 | + * @param displayName a non-null, non-empty display name string. |
123 | 162 | */
|
124 |
| - public abstract boolean isPasswordSignInAllowed(); |
| 163 | + public UpdateRequest setDisplayName(String displayName) { |
| 164 | + checkArgument(!Strings.isNullOrEmpty(displayName), "display name must not be null or empty"); |
| 165 | + properties.put("displayName", displayName); |
| 166 | + return this; |
| 167 | + } |
125 | 168 |
|
126 | 169 | /**
|
127 |
| - * Returns whether to enable email link user authentication. |
| 170 | + * Sets whether to allow email/password user authentication. |
128 | 171 | *
|
129 |
| - * @return true if a user can be authenticated using an email link, and false otherwise. |
| 172 | + * @param passwordSignInAllowed a boolean indicating whether users can be authenticated using |
| 173 | + * an email and password, and false otherwise. |
130 | 174 | */
|
131 |
| - public abstract boolean isEmailLinkSignInEnabled(); |
| 175 | + public UpdateRequest setPasswordSignInAllowed(boolean passwordSignInAllowed) { |
| 176 | + properties.put("allowPasswordSignup", passwordSignInAllowed); |
| 177 | + return this; |
| 178 | + } |
132 | 179 |
|
133 | 180 | /**
|
134 |
| - * Returns a builder for a tenant update request. |
| 181 | + * Sets whether to enable email link user authentication. |
| 182 | + * |
| 183 | + * @param emailLinkSignInEnabled a boolean indicating whether users can be authenticated using |
| 184 | + * an email link, and false otherwise. |
135 | 185 | */
|
136 |
| - public static Builder newBuilder() { |
137 |
| - return new AutoValue_Tenant_UpdateRequest.Builder(); |
| 186 | + public UpdateRequest setEmailLinkSignInEnabled(boolean emailLinkSignInEnabled) { |
| 187 | + properties.put("enableEmailLinkSignin", emailLinkSignInEnabled); |
| 188 | + return this; |
138 | 189 | }
|
139 | 190 |
|
140 |
| - /** |
141 |
| - * Builder class used to construct a update request. |
142 |
| - */ |
143 |
| - @AutoValue.Builder |
144 |
| - abstract static class Builder { |
145 |
| - public abstract Builder setDisplayName(String displayName); |
146 |
| - |
147 |
| - public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn); |
148 |
| - |
149 |
| - public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); |
150 |
| - |
151 |
| - public abstract UpdateRequest build(); |
| 191 | + Map<String, Object> getProperties() { |
| 192 | + return ImmutableMap.copyOf(properties); |
152 | 193 | }
|
153 | 194 | }
|
154 | 195 | }
|
0 commit comments