diff --git a/pom.xml b/pom.xml index aa8d3c8b2..2bac82b77 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..a3e1471a3 --- /dev/null +++ b/src/main/java/com/google/firebase/auth/Tenant.java @@ -0,0 +1,138 @@ +/* + * 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. + * 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.api.client.util.Key; +import com.google.auto.value.AutoValue; + +/** + * Contains metadata associated with a Firebase tenant. + * + *

Instances of this class are immutable and thread safe. + */ +public final class Tenant { + + @Key("tenantId") + private String tenantId; + + @Key("displayName") + private String displayName; + + @Key("allowPasswordSignup") + private String passwordSignInAllowed; + + @Key("enableEmailLinkSignin") + private String emailLinkSignInEnabled; + + /** + * Class used to hold the information needs to make a tenant create request. + */ + @AutoValue + public abstract static class CreateRequest { + + /** + * 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. + */ + @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(); + } + } + + /** + * Class used to hold the information needs to make a tenant update request. + */ + @AutoValue + public abstract static class UpdateRequest { + + /** + * 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 setEmailLinkSignInEnabled(boolean enableEmailLinkSignIn); + + public abstract UpdateRequest build(); + } + } +} diff --git a/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java b/src/test/java/com/google/firebase/database/FirebaseDatabaseTest.java index d8395035e..ba7816173 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,11 +34,12 @@ 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; public class FirebaseDatabaseTest { - + private static final FirebaseOptions firebaseOptions = new FirebaseOptions.Builder() .setCredentials(TestUtils.getCertCredential(ServiceAccount.EDITOR.asStream())) @@ -198,7 +200,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 @@ -235,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",