diff --git a/server/src/org/tsqlt/runner/server/CredentialValidator.java b/server/src/org/tsqlt/runner/server/CredentialValidator.java new file mode 100644 index 0000000..f463a42 --- /dev/null +++ b/server/src/org/tsqlt/runner/server/CredentialValidator.java @@ -0,0 +1,14 @@ +package org.tsqlt.runner.server; + +import org.jetbrains.annotations.NotNull; +import org.tsqlt.runner.common.PropertyNames; + +import java.util.Map; + +public abstract class CredentialValidator { + protected boolean needsWindowsAuthentication(@NotNull Map properties) { + boolean useWinAuth = properties.containsKey(PropertyNames.WINDOWS_AUTH) + ? Boolean.parseBoolean(properties.get(PropertyNames.WINDOWS_AUTH)) : false; + return useWinAuth; + } +} diff --git a/server/src/org/tsqlt/runner/server/DomainUserValidator.java b/server/src/org/tsqlt/runner/server/DomainUserValidator.java index b084ede..c5b6474 100644 --- a/server/src/org/tsqlt/runner/server/DomainUserValidator.java +++ b/server/src/org/tsqlt/runner/server/DomainUserValidator.java @@ -6,13 +6,11 @@ import java.util.Map; -public class DomainUserValidator implements Validator { +public class DomainUserValidator extends CredentialValidator implements Validator { @Override public InvalidProperty hasErrors(@NotNull Map properties) { - boolean useWinAuth = properties.containsKey(PropertyNames.WINDOWS_AUTH) - ? Boolean.parseBoolean(properties.get(PropertyNames.WINDOWS_AUTH)) : false; - if (useWinAuth) return null; + if (needsWindowsAuthentication(properties)) return null; String user = properties.get(PropertyNames.USER_DOMAIN); if (user == null || user.trim().isEmpty()) @@ -26,3 +24,4 @@ public InvalidProperty hasErrors(@NotNull Map properties) { return null; } } + diff --git a/server/src/org/tsqlt/runner/server/PasswordValidator.java b/server/src/org/tsqlt/runner/server/PasswordValidator.java index 6f69a92..584f48f 100644 --- a/server/src/org/tsqlt/runner/server/PasswordValidator.java +++ b/server/src/org/tsqlt/runner/server/PasswordValidator.java @@ -5,9 +5,12 @@ import java.util.Map; -public class PasswordValidator implements Validator { +public class PasswordValidator extends CredentialValidator implements Validator { @Override public InvalidProperty hasErrors(Map properties) { + if (needsWindowsAuthentication(properties)) + return null; + String password = properties.get(PropertyNames.USER_PASSWORD); if (password == null || password.isEmpty()) return new InvalidProperty(PropertyNames.USER_PASSWORD, "You need to specify a password for the user");