-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into s3-gcs-external-urls
- Loading branch information
Showing
63 changed files
with
3,924 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package auth; | ||
|
||
public class GuestAuthenticationConfigs { | ||
public static final String GUEST_ENABLED_CONFIG_PATH = "auth.guest.enabled"; | ||
public static final String GUEST_USER_CONFIG_PATH = "auth.guest.user"; | ||
public static final String GUEST_PATH_CONFIG_PATH = "auth.guest.path"; | ||
public static final String DEFAULT_GUEST_USER_NAME = "guest"; | ||
public static final String DEFAULT_GUEST_PATH = "/public"; | ||
|
||
private Boolean isEnabled = false; | ||
private String guestUser = | ||
DEFAULT_GUEST_USER_NAME; // Default if not defined but guest auth is enabled. | ||
private String guestPath = | ||
DEFAULT_GUEST_PATH; // The path for initial access to login as guest and bypass login page. | ||
|
||
public GuestAuthenticationConfigs(final com.typesafe.config.Config configs) { | ||
if (configs.hasPath(GUEST_ENABLED_CONFIG_PATH) | ||
&& configs.getBoolean(GUEST_ENABLED_CONFIG_PATH)) { | ||
isEnabled = true; | ||
} | ||
if (configs.hasPath(GUEST_USER_CONFIG_PATH)) { | ||
guestUser = configs.getString(GUEST_USER_CONFIG_PATH); | ||
} | ||
if (configs.hasPath(GUEST_PATH_CONFIG_PATH)) { | ||
guestPath = configs.getString(GUEST_PATH_CONFIG_PATH); | ||
} | ||
} | ||
|
||
public boolean isGuestEnabled() { | ||
return isEnabled; | ||
} | ||
|
||
public String getGuestUser() { | ||
return guestUser; | ||
} | ||
|
||
public String getGuestPath() { | ||
return guestPath; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
datahub-frontend/test/security/GuestAuthenticationConfigsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package security; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
import auth.GuestAuthenticationConfigs; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junitpioneer.jupiter.ClearEnvironmentVariable; | ||
import org.junitpioneer.jupiter.SetEnvironmentVariable; | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_METHOD) | ||
@SetEnvironmentVariable(key = "DATAHUB_SECRET", value = "test") | ||
@SetEnvironmentVariable(key = "KAFKA_BOOTSTRAP_SERVER", value = "") | ||
@SetEnvironmentVariable(key = "DATAHUB_ANALYTICS_ENABLED", value = "false") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_ENABLED", value = "true") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_JIT_PROVISIONING_ENABLED", value = "false") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_CLIENT_ID", value = "testclient") | ||
@SetEnvironmentVariable(key = "AUTH_OIDC_CLIENT_SECRET", value = "testsecret") | ||
@SetEnvironmentVariable(key = "AUTH_VERBOSE_LOGGING", value = "true") | ||
class GuestAuthenticationConfigsTest { | ||
|
||
@BeforeEach | ||
@ClearEnvironmentVariable(key = "GUEST_AUTHENTICATION_ENABLED") | ||
@ClearEnvironmentVariable(key = "GUEST_AUTHENTICATION_USER") | ||
@ClearEnvironmentVariable(key = "GUEST_AUTHENTICATION_PATH") | ||
public void clearConfigCache() { | ||
ConfigFactory.invalidateCaches(); | ||
} | ||
|
||
@Test | ||
public void testGuestConfigDisabled() { | ||
Config config = ConfigFactory.load(); | ||
GuestAuthenticationConfigs guestAuthConfig = new GuestAuthenticationConfigs(config); | ||
assertFalse(guestAuthConfig.isGuestEnabled()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "GUEST_AUTHENTICATION_ENABLED", value = "true") | ||
public void testGuestConfigEnabled() { | ||
Config config = ConfigFactory.load(); | ||
GuestAuthenticationConfigs guestAuthConfig = new GuestAuthenticationConfigs(config); | ||
assertTrue(guestAuthConfig.isGuestEnabled()); | ||
assertEquals("guest", guestAuthConfig.getGuestUser()); | ||
assertEquals("/public", guestAuthConfig.getGuestPath()); | ||
} | ||
|
||
@Test | ||
@SetEnvironmentVariable(key = "GUEST_AUTHENTICATION_ENABLED", value = "true") | ||
@SetEnvironmentVariable(key = "GUEST_AUTHENTICATION_USER", value = "publicUser") | ||
@SetEnvironmentVariable(key = "GUEST_AUTHENTICATION_PATH", value = "/publicPath") | ||
public void testGuestConfigWithUserEnabled() { | ||
Config config = ConfigFactory.load(); | ||
GuestAuthenticationConfigs guestAuthConfig = new GuestAuthenticationConfigs(config); | ||
assertTrue(guestAuthConfig.isGuestEnabled()); | ||
assertEquals("publicUser", guestAuthConfig.getGuestUser()); | ||
assertEquals("/publicPath", guestAuthConfig.getGuestPath()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.