Browse Source

[Improve]Use hibernate validation framework (#4) (#8467)

* [Improve]Use hibernate validation framework
Improve email verification method
Support domain name verification
* Email is at least a second-level domain name
3.0.0/version-upgrade
Kirs 3 years ago committed by GitHub
parent
commit
0ef49b4a98
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      dolphinscheduler-api/pom.xml
  2. 13
      dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java
  3. 2
      dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java
  4. 7
      dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java
  5. 3
      dolphinscheduler-dist/release-docs/LICENSE
  6. 7
      pom.xml
  7. 3
      tools/dependencies/known-dependencies.txt

4
dolphinscheduler-api/pom.xml

@ -216,6 +216,10 @@
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-aws</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>

13
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/utils/CheckUtils.java

@ -26,6 +26,7 @@ import org.apache.dolphinscheduler.common.utils.TaskParametersUtils;
import org.apache.dolphinscheduler.dao.entity.TaskDefinition;
import org.apache.commons.lang.StringUtils;
import org.hibernate.validator.internal.constraintvalidators.bv.EmailValidator;
import java.text.MessageFormat;
import java.util.HashMap;
@ -59,11 +60,17 @@ public class CheckUtils {
* @return true if email regex valid, otherwise return false
*/
public static boolean checkEmail(String email) {
if (StringUtils.isEmpty(email)) {
if (StringUtils.isBlank(email)) {
return false;
}
return email.length() > 5 && email.length() <= 40 && regexChecks(email, Constants.REGEX_MAIL_NAME);
EmailValidator emailValidator = new EmailValidator();
if (!emailValidator.isValid(email, null)) {
return false;
}
//Email is at least a second-level domain name
int indexDomain = email.lastIndexOf("@");
String domainString = email.substring(indexDomain);
return domainString.contains(".");
}
/**

2
dolphinscheduler-api/src/test/java/org/apache/dolphinscheduler/api/utils/CheckUtilsTest.java

@ -63,6 +63,8 @@ public class CheckUtilsTest {
public void testCheckEmail() {
assertTrue(CheckUtils.checkEmail("test01@gmail.com"));
assertFalse(CheckUtils.checkEmail("test01@gmail"));
assertFalse(CheckUtils.checkEmail("test01@gmail."));
assertTrue(CheckUtils.checkEmail("test01@gmail.edu.cn"));
}
/**

7
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/Constants.java

@ -253,12 +253,7 @@ public final class Constants {
* user name regex
*/
public static final Pattern REGEX_USER_NAME = Pattern.compile("^[a-zA-Z0-9._-]{3,39}$");
/**
* email regex
*/
public static final Pattern REGEX_MAIL_NAME = Pattern.compile("^([a-z0-9A-Z]+[_|\\-|\\.]?)+[a-z0-9A-Z]@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$");
/**
* read permission
*/

3
dolphinscheduler-dist/release-docs/LICENSE vendored

@ -432,6 +432,9 @@ The text of each license is also included at licenses/LICENSE-[project].txt.
logging-interceptor 3.14.9 https://mvnrepository.com/artifact/com.squareup.okhttp3/logging-interceptor/3.14.9, Apache 2.0
okhttp 3.14.3 https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp/3.14.3, Apache 2.0
okio 1.17.2 https://mvnrepository.com/artifact/com.squareup.okio/okio/1.17.2, Apache 2.0
hibernate-validator 6.2.2.Final https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator/6.2.2.Final, Apache 2.0
jakarta.validation-api 2.0.2 https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api/2.0.2, Apache 2.0
jboss-logging:jar 3.4.2.Final https://mvnrepository.com/artifact/org.jboss.logging/jboss-logging/3.4.2.Final, Apache 2.0
========================================================================
BSD licenses

7
pom.xml

@ -128,6 +128,7 @@
<exec-maven-plugin.version>3.0.0</exec-maven-plugin.version>
<janino.version>3.1.6</janino.version>
<kubernetes.version>5.8.0</kubernetes.version>
<hibernate.validator.version>6.2.2.Final</hibernate.validator.version>
<docker.hub>apache</docker.hub>
<docker.repo>${project.name}</docker.repo>
@ -923,6 +924,12 @@
<artifactId>kubernetes-client</artifactId>
<version>${kubernetes.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate.validator/hibernate-validator -->
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate.validator.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

3
tools/dependencies/known-dependencies.txt

@ -75,6 +75,7 @@ hadoop-yarn-api-2.7.3.jar
hadoop-yarn-client-2.7.3.jar
hadoop-yarn-common-2.7.3.jar
hadoop-yarn-server-common-2.7.3.jar
hibernate-validator-6.2.2.Final.jar
hive-common-2.1.0.jar
hive-jdbc-2.1.0.jar
hive-metastore-2.1.0.jar
@ -100,6 +101,7 @@ jackson-module-parameter-names-2.12.5.jar
jackson-xc-1.9.13.jar
jakarta.annotation-api-1.3.5.jar
jakarta.servlet-api-4.0.4.jar
jakarta.validation-api-2.0.2.jar
jakarta.websocket-api-1.1.2.jar
jamon-runtime-2.3.1.jar
java-xmlbuilder-0.4.jar
@ -112,6 +114,7 @@ javax.mail-1.6.2.jar
javolution-5.5.1.jar
jaxb-api-2.3.1.jar
jaxb-impl-2.2.3-1.jar
jboss-logging-3.4.2.Final.jar
jdo-api-3.0.1.jar
jersey-client-1.9.jar
jersey-core-1.9.jar

Loading…
Cancel
Save