From 04a4add8eeea1be22a11062f8520aafe74a540e1 Mon Sep 17 00:00:00 2001 From: Eduard Heimbuch Date: Tue, 13 Oct 2020 16:19:00 +0200 Subject: [PATCH] add user converter to global configuration --- .../sonia/scm/config/ScmConfiguration.java | 30 +++++++++++++++++++ scm-ui/ui-types/src/Config.ts | 1 + .../ui-webapp/public/locales/de/config.json | 2 ++ .../ui-webapp/public/locales/en/config.json | 2 ++ .../src/admin/components/form/ConfigForm.tsx | 2 ++ .../admin/components/form/GeneralSettings.tsx | 17 ++++++++++- .../sonia/scm/api/v2/resources/ConfigDto.java | 1 + ...ConfigDtoToScmConfigurationMapperTest.java | 7 +++-- 8 files changed, 58 insertions(+), 4 deletions(-) diff --git a/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java b/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java index 7bb64a9454..86c9e88aa4 100644 --- a/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java +++ b/scm-core/src/main/java/sonia/scm/config/ScmConfiguration.java @@ -181,6 +181,14 @@ public class ScmConfiguration implements Configuration { @XmlElement(name = "xsrf-protection") private boolean enabledXsrfProtection = true; + /** + * Enables user converter. + * + * @since 2.8.0 + */ + @XmlElement(name = "user-converter") + private boolean enabledUserConverter = false; + @XmlElement(name = "namespace-strategy") private String namespaceStrategy = "UsernameNamespaceStrategy"; @@ -227,6 +235,7 @@ public class ScmConfiguration implements Configuration { this.namespaceStrategy = other.namespaceStrategy; this.loginInfoUrl = other.loginInfoUrl; this.releaseFeedUrl = other.releaseFeedUrl; + this.enabledUserConverter = other.enabledUserConverter; } /** @@ -367,6 +376,17 @@ public class ScmConfiguration implements Configuration { return enabledXsrfProtection; } + /** + * Returns {@code true} if the user converter is enabled. + * + * @return {@code true} if the user converter is enabled + * The user converter automatically converts an internal user to external on their first login using an external system like ldap + * @since 2.8.0 + */ + public boolean isEnabledUserConverter() { + return enabledUserConverter; + } + public boolean isEnableProxy() { return enableProxy; } @@ -524,6 +544,16 @@ public class ScmConfiguration implements Configuration { this.enabledXsrfProtection = enabledXsrfProtection; } + /** + * Set {@code true} to enable user converter. + * + * @param enabledUserConverter {@code true} to enable user converter + * @since 2.8.0 + */ + public void setEnabledUserConverter(boolean enabledUserConverter) { + this.enabledUserConverter = enabledUserConverter; + } + public void setNamespaceStrategy(String namespaceStrategy) { this.namespaceStrategy = namespaceStrategy; } diff --git a/scm-ui/ui-types/src/Config.ts b/scm-ui/ui-types/src/Config.ts index 667aa7b199..992dd477d4 100644 --- a/scm-ui/ui-types/src/Config.ts +++ b/scm-ui/ui-types/src/Config.ts @@ -45,6 +45,7 @@ export type Config = { pluginUrl: string; loginAttemptLimitTimeout: number; enabledXsrfProtection: boolean; + enabledUserConverter: boolean; namespaceStrategy: string; loginInfoUrl: string; releaseFeedUrl: string; diff --git a/scm-ui/ui-webapp/public/locales/de/config.json b/scm-ui/ui-webapp/public/locales/de/config.json index ad749c12c8..31a088664f 100644 --- a/scm-ui/ui-webapp/public/locales/de/config.json +++ b/scm-ui/ui-webapp/public/locales/de/config.json @@ -48,6 +48,7 @@ "plugin-url": "Plugin Center URL", "release-feed-url": "Release Feed URL", "enabled-xsrf-protection": "XSRF Protection aktivieren", + "enabled-user-converter": "Benutzer Konverter aktivieren", "namespace-strategy": "Namespace Strategie", "login-info-url": "Login Info URL" }, @@ -79,6 +80,7 @@ "proxyUserHelpText": "Der Benutzername für die Proxy Server Anmeldung.", "proxyExcludesHelpText": "Glob patterns für Hostnamen, die von den Proxy-Einstellungen ausgeschlossen werden sollen.", "enableXsrfProtectionHelpText": "Xsrf Cookie Protection aktivieren. Hinweis: Dieses Feature befindet sich noch im Experimentalstatus.", + "enabledUserConverterHelpText": "Benutzer Konverter aktivieren. Interne Benutzer werden beim Einloggen über ein Fremdsystem zu externen Benutzern konvertiert.", "nameSpaceStrategyHelpText": "Strategie für Namespaces.", "loginInfoUrlHelpText": "URL zu der Login Information (Plugin und Feature Tipps auf der Login Seite). Um die Login Information zu deaktivieren, kann das Feld leer gelassen werden." } diff --git a/scm-ui/ui-webapp/public/locales/en/config.json b/scm-ui/ui-webapp/public/locales/en/config.json index 1150dd4e3d..d98aa173f9 100644 --- a/scm-ui/ui-webapp/public/locales/en/config.json +++ b/scm-ui/ui-webapp/public/locales/en/config.json @@ -48,6 +48,7 @@ "plugin-url": "Plugin Center URL", "release-feed-url": "Release Feed URL", "enabled-xsrf-protection": "Enabled XSRF Protection", + "enabled-user-converter": "Enabled User Converter", "namespace-strategy": "Namespace Strategy", "login-info-url": "Login Info URL" }, @@ -79,6 +80,7 @@ "proxyUserHelpText": "The username for the proxy server authentication.", "proxyExcludesHelpText": "Glob patterns for hostnames, which should be excluded from proxy settings.", "enableXsrfProtectionHelpText": "Enable XSRF Cookie Protection. Note: This feature is still experimental.", + "enabledUserConverterHelpText": "Enable User Converter. Internal users will automatically be converted to external on their first login using an external system.", "nameSpaceStrategyHelpText": "The namespace strategy.", "loginInfoUrlHelpText": "URL to login information (plugin and feature tips at login page). If this is omitted, no login information will be displayed." } diff --git a/scm-ui/ui-webapp/src/admin/components/form/ConfigForm.tsx b/scm-ui/ui-webapp/src/admin/components/form/ConfigForm.tsx index f412acf8e8..e0e3d38f46 100644 --- a/scm-ui/ui-webapp/src/admin/components/form/ConfigForm.tsx +++ b/scm-ui/ui-webapp/src/admin/components/form/ConfigForm.tsx @@ -72,6 +72,7 @@ class ConfigForm extends React.Component { pluginUrl: "", loginAttemptLimitTimeout: 0, enabledXsrfProtection: true, + enabledUserConverter: false, namespaceStrategy: "", loginInfoUrl: "", _links: {} @@ -145,6 +146,7 @@ class ConfigForm extends React.Component { pluginUrl={config.pluginUrl} releaseFeedUrl={config.releaseFeedUrl} enabledXsrfProtection={config.enabledXsrfProtection} + enabledUserConverter={config.enabledUserConverter} namespaceStrategy={config.namespaceStrategy} onChange={(isValid, changedValue, name) => this.onChange(isValid, changedValue, name)} hasUpdatePermission={configUpdatePermission} diff --git a/scm-ui/ui-webapp/src/admin/components/form/GeneralSettings.tsx b/scm-ui/ui-webapp/src/admin/components/form/GeneralSettings.tsx index 580a3546da..1ff315c770 100644 --- a/scm-ui/ui-webapp/src/admin/components/form/GeneralSettings.tsx +++ b/scm-ui/ui-webapp/src/admin/components/form/GeneralSettings.tsx @@ -37,6 +37,7 @@ type Props = WithTranslation & { pluginUrl: string; releaseFeedUrl: string; enabledXsrfProtection: boolean; + enabledUserConverter: boolean; namespaceStrategy: string; namespaceStrategies?: NamespaceStrategies; onChange: (p1: boolean, p2: any, p3: string) => void; @@ -52,6 +53,7 @@ class GeneralSettings extends React.Component { pluginUrl, releaseFeedUrl, enabledXsrfProtection, + enabledUserConverter, anonymousMode, namespaceStrategy, hasUpdatePermission, @@ -129,7 +131,7 @@ class GeneralSettings extends React.Component {
-
+
{ helpText={t("help.releaseFeedUrlHelpText")} />
+
+ +
); @@ -152,6 +164,9 @@ class GeneralSettings extends React.Component { handleEnabledXsrfProtectionChange = (value: boolean) => { this.props.onChange(true, value, "enabledXsrfProtection"); }; + handleEnabledUserConverterChange = (value: boolean) => { + this.props.onChange(true, value, "enabledUserConverter"); + }; handleAnonymousMode = (value: string) => { this.props.onChange(true, value, "anonymousMode"); }; diff --git a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java index bec72a552b..0f18569f94 100644 --- a/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java +++ b/scm-webapp/src/main/java/sonia/scm/api/v2/resources/ConfigDto.java @@ -56,6 +56,7 @@ public class ConfigDto extends HalRepresentation { private String pluginUrl; private long loginAttemptLimitTimeout; private boolean enabledXsrfProtection; + private boolean enabledUserConverter; private String namespaceStrategy; private String loginInfoUrl; private String releaseFeedUrl; diff --git a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ConfigDtoToScmConfigurationMapperTest.java b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ConfigDtoToScmConfigurationMapperTest.java index 3e01a1e4cc..c38987a0b6 100644 --- a/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ConfigDtoToScmConfigurationMapperTest.java +++ b/scm-webapp/src/test/java/sonia/scm/api/v2/resources/ConfigDtoToScmConfigurationMapperTest.java @@ -34,6 +34,7 @@ import sonia.scm.security.AnonymousMode; import java.util.Arrays; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.MockitoAnnotations.initMocks; @@ -42,9 +43,7 @@ public class ConfigDtoToScmConfigurationMapperTest { @InjectMocks private ConfigDtoToScmConfigurationMapperImpl mapper; - private String[] expectedUsers = {"trillian", "arthur"}; - private String[] expectedGroups = {"admin", "plebs"}; - private String[] expectedExcludes = {"ex", "clude"}; + private final String[] expectedExcludes = {"ex", "clude"}; @Before public void init() { @@ -73,6 +72,7 @@ public class ConfigDtoToScmConfigurationMapperTest { assertEquals("https://plug.ins", config.getPluginUrl()); assertEquals(40, config.getLoginAttemptLimitTimeout()); assertTrue(config.isEnabledXsrfProtection()); + assertFalse(config.isEnabledUserConverter()); assertEquals("username", config.getNamespaceStrategy()); assertEquals("https://scm-manager.org/login-info", config.getLoginInfoUrl()); } @@ -113,6 +113,7 @@ public class ConfigDtoToScmConfigurationMapperTest { configDto.setEnabledXsrfProtection(true); configDto.setNamespaceStrategy("username"); configDto.setLoginInfoUrl("https://scm-manager.org/login-info"); + configDto.setEnabledUserConverter(false); return configDto; }