Skip to content

Commit d76fc20

Browse files
authored
Add Tenant class and its create and update request classes. (#344)
This pull request adds the Tenant class (including it's create/update inner classes) as part of adding multi-tenancy support.
1 parent e30df7d commit d76fc20

File tree

3 files changed

+155
-3
lines changed

3 files changed

+155
-3
lines changed

pom.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,13 @@
321321
<configuration>
322322
<source>1.7</source>
323323
<target>1.7</target>
324+
<annotationProcessorPaths>
325+
<path>
326+
<groupId>com.google.auto.value</groupId>
327+
<artifactId>auto-value</artifactId>
328+
<version>1.7</version>
329+
</path>
330+
</annotationProcessorPaths>
324331
</configuration>
325332
</plugin>
326333
<plugin>
@@ -426,6 +433,11 @@
426433
</dependency>
427434

428435
<!-- Utilities -->
436+
<dependency>
437+
<groupId>com.google.auto.value</groupId>
438+
<artifactId>auto-value-annotations</artifactId>
439+
<version>1.7</version>
440+
</dependency>
429441
<dependency>
430442
<groupId>com.google.guava</groupId>
431443
<artifactId>guava</artifactId>
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.firebase.auth;
18+
19+
import com.google.api.client.util.Key;
20+
import com.google.auto.value.AutoValue;
21+
22+
/**
23+
* Contains metadata associated with a Firebase tenant.
24+
*
25+
* <p>Instances of this class are immutable and thread safe.
26+
*/
27+
public final class Tenant {
28+
29+
@Key("tenantId")
30+
private String tenantId;
31+
32+
@Key("displayName")
33+
private String displayName;
34+
35+
@Key("allowPasswordSignup")
36+
private String passwordSignInAllowed;
37+
38+
@Key("enableEmailLinkSignin")
39+
private String emailLinkSignInEnabled;
40+
41+
/**
42+
* Class used to hold the information needs to make a tenant create request.
43+
*/
44+
@AutoValue
45+
public abstract static class CreateRequest {
46+
47+
/**
48+
* Returns the display name of this tenant.
49+
*
50+
* @return a non-empty display name string.
51+
*/
52+
public abstract String getDisplayName();
53+
54+
/**
55+
* Returns whether to allow email/password user authentication.
56+
*
57+
* @return true if a user can be authenticated using an email and password, and false otherwise.
58+
*/
59+
public abstract boolean isPasswordSignInAllowed();
60+
61+
/**
62+
* Returns whether to enable email link user authentication.
63+
*
64+
* @return true if a user can be authenticated using an email link, and false otherwise.
65+
*/
66+
public abstract boolean isEmailLinkSignInEnabled();
67+
68+
/**
69+
* Returns a builder for a tenant create request.
70+
*/
71+
public static Builder newBuilder() {
72+
return new AutoValue_Tenant_CreateRequest.Builder();
73+
}
74+
75+
/**
76+
* Builder class used to construct a create request.
77+
*/
78+
@AutoValue.Builder
79+
abstract static class Builder {
80+
public abstract Builder setDisplayName(String displayName);
81+
82+
public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn);
83+
84+
public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn);
85+
86+
public abstract CreateRequest build();
87+
}
88+
}
89+
90+
/**
91+
* Class used to hold the information needs to make a tenant update request.
92+
*/
93+
@AutoValue
94+
public abstract static class UpdateRequest {
95+
96+
/**
97+
* Returns the display name of this tenant.
98+
*
99+
* @return a non-empty display name string.
100+
*/
101+
public abstract String getDisplayName();
102+
103+
/**
104+
* Returns whether to allow email/password user authentication.
105+
*
106+
* @return true if a user can be authenticated using an email and password, and false otherwise.
107+
*/
108+
public abstract boolean isPasswordSignInAllowed();
109+
110+
/**
111+
* Returns whether to enable email link user authentication.
112+
*
113+
* @return true if a user can be authenticated using an email link, and false otherwise.
114+
*/
115+
public abstract boolean isEmailLinkSignInEnabled();
116+
117+
/**
118+
* Returns a builder for a tenant update request.
119+
*/
120+
public static Builder newBuilder() {
121+
return new AutoValue_Tenant_UpdateRequest.Builder();
122+
}
123+
124+
/**
125+
* Builder class used to construct a update request.
126+
*/
127+
@AutoValue.Builder
128+
abstract static class Builder {
129+
public abstract Builder setDisplayName(String displayName);
130+
131+
public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn);
132+
133+
public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn);
134+
135+
public abstract UpdateRequest build();
136+
}
137+
}
138+
}

src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import static org.junit.Assert.assertSame;
2424
import static org.junit.Assert.fail;
2525

26+
import com.google.auth.oauth2.GoogleCredentials;
2627
import com.google.common.base.Strings;
2728
import com.google.common.collect.ImmutableList;
2829
import com.google.common.collect.ImmutableMap;
@@ -33,11 +34,12 @@
3334
import com.google.firebase.database.util.EmulatorHelper;
3435
import com.google.firebase.testing.ServiceAccount;
3536
import com.google.firebase.testing.TestUtils;
37+
import java.io.IOException;
3638
import java.util.List;
3739
import org.junit.Test;
3840

3941
public class FirebaseDatabaseTest {
40-
42+
4143
private static final FirebaseOptions firebaseOptions =
4244
new FirebaseOptions.Builder()
4345
.setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream()))
@@ -198,7 +200,7 @@ public void testInitAfterAppDelete() {
198200
}
199201

200202
@Test
201-
public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() {
203+
public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() throws IOException {
202204

203205
List<CustomTestCase> testCases = ImmutableList.of(
204206
// cases where the env var is ignored because the supplied DB URL is a valid emulator URL
@@ -235,7 +237,7 @@ public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() {
235237
}
236238

237239
@Test
238-
public void testDbUrlIsEmulatorUrlForDbRefWithPath() {
240+
public void testDbUrlIsEmulatorUrlForDbRefWithPath() throws IOException {
239241

240242
List<CustomTestCase> testCases = ImmutableList.of(
241243
new CustomTestCase("http://my-custom-hosted-emulator.com:80?ns=dummy-ns",

0 commit comments

Comments
 (0)