From 893cd81282583e0842eb600988086fd3bc431906 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 9 Jan 2020 10:10:05 -0500 Subject: [PATCH 01/11] Add Tenant class and AutoValue dependency. --- pom.xml | 12 +++ .../java/com/google/firebase/auth/Tenant.java | 75 +++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 src/main/java/com/google/firebase/auth/Tenant.java diff --git a/pom.xml b/pom.xml index 3a89e361d..e0e07bd1c 100644 --- a/pom.xml +++ b/pom.xml @@ -321,6 +321,13 @@ 1.7 1.7 + + + com.google.auto.value + auto-value + 1.7 + + @@ -426,6 +433,11 @@ + + com.google.auto.value + auto-value-annotations + 1.7 + com.google.guava guava diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java new file mode 100644 index 000000000..bfd4985ec --- /dev/null +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -0,0 +1,75 @@ +/* + * Copyright 2019 Google LLC + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.firebase.auth; + +import com.google.auto.value.AutoValue; + +/** + * Contains metadata associated with a Firebase tenant. + * + *

Instances of this class are immutable and thread safe. + */ +@AutoValue +public abstract class Tenant { + + /** + * Returns the ID of this tenant. + * + * @return a non-empty tenant ID string. + */ + public abstract String getTenantId(); + + /** + * Returns the display name of this tenant. + * + * @return a non-empty display name string. + */ + public abstract String getDisplayName(); + + /** + * Returns whether to allow email/password user authentication. + * + * @return true if a user can be authenticated using an email and password, and false otherwise. + */ + public abstract boolean isPasswordSignUpAllowed(); + + /** + * Returns whether to enable email link user authentication. + * + * @return true if a user can be authenticated using an email link, and false otherwise. + */ + public abstract boolean isEmailLinkSignInEnabled(); + + /** Returns a tenant builder. */ + public static Builder newBuilder() { + return new AutoValue_Tenant.Builder(); + } + + @AutoValue.Builder + abstract static class Builder { + public abstract Builder setTenantId(String tenantId); + + public abstract Builder setDisplayName(String displayName); + + public abstract Builder setPasswordSignUpAllowed( + boolean requirePasswordForEmailLinkSignIn); + + public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); + + public abstract Tenant build(); + } +} \ No newline at end of file From a3668e5f3fdad9eeff38943e4a2e1589f7958251 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 9 Jan 2020 10:35:25 -0500 Subject: [PATCH 02/11] Fix javadoc comments in Tenant class and add newline char to end of file. --- src/main/java/com/google/firebase/auth/Tenant.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index bfd4985ec..618d39640 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -54,11 +54,16 @@ public abstract class Tenant { */ public abstract boolean isEmailLinkSignInEnabled(); - /** Returns a tenant builder. */ + /** + * Returns a tenant builder. + */ public static Builder newBuilder() { return new AutoValue_Tenant.Builder(); } + /** + * Builder class used to construct a tenant. + */ @AutoValue.Builder abstract static class Builder { public abstract Builder setTenantId(String tenantId); @@ -72,4 +77,4 @@ public abstract Builder setPasswordSignUpAllowed( public abstract Tenant build(); } -} \ No newline at end of file +} From 1044c78c2b126b01f885b61f2b39f8ee3220e934 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Thu, 12 Dec 2019 14:17:08 -0800 Subject: [PATCH 03/11] Fixing some failing RTDB tests --- .../firebase/database/FirebaseDatabaseTest.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java index 74e835884..2e3072773 100644 --- a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java +++ b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java @@ -23,6 +23,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.fail; +import com.google.auth.oauth2.GoogleCredentials; import com.google.common.base.Strings; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; @@ -33,6 +34,7 @@ import com.google.firebase.database.util.EmulatorHelper; import com.google.firebase.testing.ServiceAccount; import com.google.firebase.testing.TestUtils; +import java.io.IOException; import java.util.List; import org.junit.Test; @@ -194,7 +196,7 @@ public void testInitAfterAppDelete() { } @Test - public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() { + public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() throws IOException { List testCases = ImmutableList.of( // cases where the env var is ignored because the supplied DB URL is a valid emulator URL @@ -210,6 +212,11 @@ public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() { new CustomTestCase("https://test.firebaseio.com?ns=valid-namespace", "localhost:90", "http://localhost:90", "valid-namespace") ); + + GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()); + FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(credentials) + .build(); for (CustomTestCase tc : testCases) { try { FirebaseApp app = FirebaseApp.initializeApp(); @@ -230,7 +237,7 @@ public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() { } @Test - public void testDbUrlIsEmulatorUrlForDbRefWithPath() { + public void testDbUrlIsEmulatorUrlForDbRefWithPath() throws IOException { List testCases = ImmutableList.of( new CustomTestCase("http://my-custom-hosted-emulator.com:80?ns=dummy-ns", @@ -247,9 +254,13 @@ public void testDbUrlIsEmulatorUrlForDbRefWithPath() { "http://localhost:8080", "valid-namespace", "/a/b/c/d") ); + GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()); + FirebaseOptions options = FirebaseOptions.builder() + .setCredentials(credentials) + .build(); for (CustomTestCase tc : testCases) { try { - FirebaseApp app = FirebaseApp.initializeApp(); + FirebaseApp app = FirebaseApp.initializeApp(options); TestUtils.setEnvironmentVariables( ImmutableMap.of(EmulatorHelper.FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR, Strings.nullToEmpty(tc.envVariableUrl))); From 70c840e222466d129b2e4ce6103370f3e557c4f0 Mon Sep 17 00:00:00 2001 From: hiranya911 Date: Thu, 12 Dec 2019 14:22:42 -0800 Subject: [PATCH 04/11] Using explicit options --- .../java/com/google/firebase/database/FirebaseDatabaseTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java index 2e3072773..f30183256 100644 --- a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java +++ b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java @@ -219,7 +219,7 @@ public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() throws IOExceptio .build(); for (CustomTestCase tc : testCases) { try { - FirebaseApp app = FirebaseApp.initializeApp(); + FirebaseApp app = FirebaseApp.initializeApp(options); TestUtils.setEnvironmentVariables( ImmutableMap.of(EmulatorHelper.FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR, Strings.nullToEmpty(tc.envVariableUrl))); From 53667ea61fe3f6d43faf5534c63e59a6e3f07a45 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Tue, 14 Jan 2020 11:31:02 -0500 Subject: [PATCH 05/11] Fix indenting in pom.xml. --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index e0e07bd1c..e8d9032ce 100644 --- a/pom.xml +++ b/pom.xml @@ -322,11 +322,11 @@ 1.7 1.7 - - com.google.auto.value - auto-value - 1.7 - + + com.google.auto.value + auto-value + 1.7 + From 78faaaa6cb0294f034930668645b027184e67fae Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Tue, 21 Jan 2020 10:25:50 -0500 Subject: [PATCH 06/11] Rename isPasswordSignUpAllowed to isPasswordSignInAllowed. --- src/main/java/com/google/firebase/auth/Tenant.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index 618d39640..85f1a3010 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -20,7 +20,7 @@ /** * Contains metadata associated with a Firebase tenant. - * + * *

Instances of this class are immutable and thread safe. */ @AutoValue @@ -45,7 +45,7 @@ public abstract class Tenant { * * @return true if a user can be authenticated using an email and password, and false otherwise. */ - public abstract boolean isPasswordSignUpAllowed(); + public abstract boolean isPasswordSignInAllowed(); /** * Returns whether to enable email link user authentication. @@ -70,8 +70,7 @@ abstract static class Builder { public abstract Builder setDisplayName(String displayName); - public abstract Builder setPasswordSignUpAllowed( - boolean requirePasswordForEmailLinkSignIn); + public abstract Builder setPasswordSignInAllowed(boolean allowPasswordSignIn); public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); From 2cc8dc540a51a3982035161c598eb20480af3d3b Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 23 Jan 2020 10:26:10 -0500 Subject: [PATCH 07/11] Use JSON deserialization to construct Tenant and add CreateRequest and UpdateRequest autovalue classes. --- .../java/com/google/firebase/auth/Tenant.java | 131 +++++++++++++----- 1 file changed, 95 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index 85f1a3010..11ada1046 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -16,6 +16,7 @@ package com.google.firebase.auth; +import com.google.api.client.util.Key; import com.google.auto.value.AutoValue; /** @@ -23,57 +24,115 @@ * *

Instances of this class are immutable and thread safe. */ -@AutoValue -public abstract class Tenant { +public class Tenant { - /** - * Returns the ID of this tenant. - * - * @return a non-empty tenant ID string. - */ - public abstract String getTenantId(); + @Key("tenantId") + private String tenantId; - /** - * Returns the display name of this tenant. - * - * @return a non-empty display name string. - */ - public abstract String getDisplayName(); + @Key("displayName") + private String displayName; - /** - * Returns whether to allow email/password user authentication. - * - * @return true if a user can be authenticated using an email and password, and false otherwise. - */ - public abstract boolean isPasswordSignInAllowed(); + @Key("allowPasswordSignup") + private String passwordSignInAllowed; + + @Key("enableEmailLinkSignin") + private String emailLinkSignInEnabled; /** - * Returns whether to enable email link user authentication. - * - * @return true if a user can be authenticated using an email link, and false otherwise. + * Class used to hold the information needs to make a tenant create request. */ - public abstract boolean isEmailLinkSignInEnabled(); + @AutoValue + public abstract static class CreateRequest { - /** - * Returns a tenant builder. + /** + * Returns the display name of this tenant. + * + * @return a non-empty display name string. + */ + public abstract String getDisplayName(); + + /** + * Returns whether to allow email/password user authentication. + * + * @return true if a user can be authenticated using an email and password, and false otherwise. + */ + public abstract boolean isPasswordSignInAllowed(); + + /** + * Returns whether to enable email link user authentication. + * + * @return true if a user can be authenticated using an email link, and false otherwise. + */ + public abstract boolean isEmailLinkSignInEnabled(); + + /** + * Returns a builder for a tenant create request. + */ + public static Builder newBuilder() { + return new AutoValue_Tenant_CreateRequest.Builder(); + } + + /** + * Builder class used to construct a create request. */ - public static Builder newBuilder() { - return new AutoValue_Tenant.Builder(); + @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(); + } } /** - * Builder class used to construct a tenant. + * Class used to hold the information needs to make a tenant update request. */ - @AutoValue.Builder - abstract static class Builder { - public abstract Builder setTenantId(String tenantId); + @AutoValue + public abstract static class UpdateRequest { - public abstract Builder setDisplayName(String displayName); + /** + * Returns the display name of this tenant. + * + * @return a non-empty display name string. + */ + public abstract String getDisplayName(); + + /** + * Returns whether to allow email/password user authentication. + * + * @return true if a user can be authenticated using an email and password, and false otherwise. + */ + public abstract boolean isPasswordSignInAllowed(); + + /** + * Returns whether to enable email link user authentication. + * + * @return true if a user can be authenticated using an email link, and false otherwise. + */ + public abstract boolean isEmailLinkSignInEnabled(); + + /** + * Returns a builder for a tenant update request. + */ + public static Builder newBuilder() { + return new AutoValue_Tenant_UpdateRequest.Builder(); + } + + /** + * 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 setPasswordSignInAllowed(boolean allowPasswordSignIn); - public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); + public abstract Builder setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); - public abstract Tenant build(); + public abstract UpdateRequest build(); + } } } From fcf1b717950f8bd447b1503a09d87a7511f4c5b5 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 23 Jan 2020 14:21:26 -0500 Subject: [PATCH 08/11] Make Tenant class final. --- src/main/java/com/google/firebase/auth/Tenant.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index 11ada1046..98ccf518a 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -24,7 +24,7 @@ * *

Instances of this class are immutable and thread safe. */ -public class Tenant { +public class final Tenant { @Key("tenantId") private String tenantId; @@ -39,7 +39,7 @@ public class Tenant { private String emailLinkSignInEnabled; /** - * Class used to hold the information needs to make a tenant create request. + * Class used to hold the information needs to make a tenant create request. */ @AutoValue public abstract static class CreateRequest { From 40258ab0fd242c8815ad2c41c46540e822be2f36 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 23 Jan 2020 14:30:45 -0500 Subject: [PATCH 09/11] Fix Tenant's final modifier. --- src/main/java/com/google/firebase/auth/Tenant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index 98ccf518a..adcd5eb48 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -24,7 +24,7 @@ * *

Instances of this class are immutable and thread safe. */ -public class final Tenant { +public final class Tenant { @Key("tenantId") private String tenantId; From 94a7a14745d5bf3b17a5daa0547cd6fc60e9fed2 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 23 Jan 2020 15:02:24 -0500 Subject: [PATCH 10/11] Update copyright notice to 2020. --- src/main/java/com/google/firebase/auth/Tenant.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/google/firebase/auth/Tenant.java b/src/main/java/com/google/firebase/auth/Tenant.java index adcd5eb48..a3e1471a3 100644 --- a/src/main/java/com/google/firebase/auth/Tenant.java +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -1,5 +1,5 @@ /* - * Copyright 2019 Google LLC + * Copyright 2020 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. From fd229c134bf71c25b7a7be3486a9c66d4d28eee6 Mon Sep 17 00:00:00 2001 From: Micah Stairs Date: Thu, 30 Jan 2020 11:52:00 -0500 Subject: [PATCH 11/11] Fix merge conflicts with FirebaseDatabaseTest. --- .../database/FirebaseDatabaseTest.java | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java index f30183256..ba7816173 100644 --- a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java +++ b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java @@ -39,12 +39,16 @@ import org.junit.Test; public class FirebaseDatabaseTest { - - private static FirebaseOptions firebaseOptions = + + private static final FirebaseOptions firebaseOptions = new FirebaseOptions.Builder() .setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream())) .setDatabaseUrl("https://firebase-db-test.firebaseio.com") .build(); + private static final FirebaseOptions firebaseOptionsWithoutDatabaseUrl = + new FirebaseOptions.Builder() + .setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream())) + .build(); @Test public void testGetInstance() { @@ -213,13 +217,9 @@ public void testDbUrlIsEmulatorUrlWhenSettingOptionsManually() throws IOExceptio "http://localhost:90", "valid-namespace") ); - GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()); - FirebaseOptions options = FirebaseOptions.builder() - .setCredentials(credentials) - .build(); for (CustomTestCase tc : testCases) { try { - FirebaseApp app = FirebaseApp.initializeApp(options); + FirebaseApp app = FirebaseApp.initializeApp(firebaseOptionsWithoutDatabaseUrl); TestUtils.setEnvironmentVariables( ImmutableMap.of(EmulatorHelper.FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR, Strings.nullToEmpty(tc.envVariableUrl))); @@ -254,13 +254,9 @@ public void testDbUrlIsEmulatorUrlForDbRefWithPath() throws IOException { "http://localhost:8080", "valid-namespace", "/a/b/c/d") ); - GoogleCredentials credentials = GoogleCredentials.fromStream(ServiceAccount.EDITOR.asStream()); - FirebaseOptions options = FirebaseOptions.builder() - .setCredentials(credentials) - .build(); for (CustomTestCase tc : testCases) { try { - FirebaseApp app = FirebaseApp.initializeApp(options); + FirebaseApp app = FirebaseApp.initializeApp(firebaseOptionsWithoutDatabaseUrl); TestUtils.setEnvironmentVariables( ImmutableMap.of(EmulatorHelper.FIREBASE_RTDB_EMULATOR_HOST_ENV_VAR, Strings.nullToEmpty(tc.envVariableUrl)));