removed Apache Email Validator (#2945)
* removed Apache Email Validator * improvements Email Validator regex * refactored Email Validator
This commit is contained in:
		
							parent
							
								
									eaff2406db
								
							
						
					
					
						commit
						7a555fca8d
					
				
							
								
								
									
										82
									
								
								dao/pom.xml
									
									
									
									
									
								
							
							
						
						
									
										82
									
								
								dao/pom.xml
									
									
									
									
									
								
							@ -91,26 +91,26 @@
 | 
			
		||||
            <artifactId>mockito-all</artifactId>
 | 
			
		||||
            <scope>test</scope>
 | 
			
		||||
        </dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.apache.commons</groupId>
 | 
			
		||||
			<artifactId>commons-lang3</artifactId>
 | 
			
		||||
		</dependency>        
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>commons-validator</groupId>
 | 
			
		||||
			<artifactId>commons-validator</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>com.fasterxml.jackson.core</groupId>
 | 
			
		||||
			<artifactId>jackson-databind</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.apache.commons</groupId>
 | 
			
		||||
            <artifactId>commons-lang3</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>commons-collections</groupId>
 | 
			
		||||
            <artifactId>commons-collections</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.fasterxml.jackson.core</groupId>
 | 
			
		||||
            <artifactId>jackson-databind</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework</groupId>
 | 
			
		||||
            <artifactId>spring-context</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework</groupId>
 | 
			
		||||
			<artifactId>spring-tx</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework</groupId>
 | 
			
		||||
            <artifactId>spring-tx</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>org.springframework</groupId>
 | 
			
		||||
            <artifactId>spring-web</artifactId>
 | 
			
		||||
@ -120,24 +120,24 @@
 | 
			
		||||
            <groupId>org.springframework.security</groupId>
 | 
			
		||||
            <artifactId>spring-security-oauth2-client</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
			<artifactId>cassandra-driver-core</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
			<artifactId>cassandra-driver-mapping</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
			<artifactId>cassandra-driver-extras</artifactId>
 | 
			
		||||
		</dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
            <artifactId>cassandra-driver-core</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
            <artifactId>cassandra-driver-mapping</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.datastax.cassandra</groupId>
 | 
			
		||||
            <artifactId>cassandra-driver-extras</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>io.takari.junit</groupId>
 | 
			
		||||
            <artifactId>takari-cpsuite</artifactId>
 | 
			
		||||
            <scope>test</scope>
 | 
			
		||||
        </dependency>        
 | 
			
		||||
		<dependency>
 | 
			
		||||
        </dependency>
 | 
			
		||||
        <dependency>
 | 
			
		||||
            <groupId>com.google.guava</groupId>
 | 
			
		||||
            <artifactId>guava</artifactId>
 | 
			
		||||
        </dependency>
 | 
			
		||||
@ -215,18 +215,18 @@
 | 
			
		||||
                    </includes>
 | 
			
		||||
                </configuration>
 | 
			
		||||
            </plugin>
 | 
			
		||||
		    <plugin>
 | 
			
		||||
		       <groupId>org.apache.maven.plugins</groupId>
 | 
			
		||||
		       <artifactId>maven-jar-plugin</artifactId>
 | 
			
		||||
            <plugin>
 | 
			
		||||
                <groupId>org.apache.maven.plugins</groupId>
 | 
			
		||||
                <artifactId>maven-jar-plugin</artifactId>
 | 
			
		||||
                <version>${jar-plugin.version}</version>
 | 
			
		||||
		       <executions>
 | 
			
		||||
		         <execution>
 | 
			
		||||
		           <goals>
 | 
			
		||||
		             <goal>test-jar</goal>
 | 
			
		||||
		           </goals>
 | 
			
		||||
		         </execution>
 | 
			
		||||
		       </executions>
 | 
			
		||||
		    </plugin>
 | 
			
		||||
                <executions>
 | 
			
		||||
                    <execution>
 | 
			
		||||
                        <goals>
 | 
			
		||||
                            <goal>test-jar</goal>
 | 
			
		||||
                        </goals>
 | 
			
		||||
                    </execution>
 | 
			
		||||
                </executions>
 | 
			
		||||
            </plugin>
 | 
			
		||||
        </plugins>
 | 
			
		||||
    </build>
 | 
			
		||||
</project>
 | 
			
		||||
 | 
			
		||||
@ -17,7 +17,6 @@ package org.thingsboard.server.dao.service;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.apache.commons.validator.routines.EmailValidator;
 | 
			
		||||
import org.thingsboard.server.common.data.BaseData;
 | 
			
		||||
import org.thingsboard.server.common.data.id.TenantId;
 | 
			
		||||
import org.thingsboard.server.dao.exception.DataValidationException;
 | 
			
		||||
@ -26,11 +25,13 @@ import java.util.HashSet;
 | 
			
		||||
import java.util.Iterator;
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.function.Function;
 | 
			
		||||
import java.util.regex.Matcher;
 | 
			
		||||
import java.util.regex.Pattern;
 | 
			
		||||
 | 
			
		||||
@Slf4j
 | 
			
		||||
public abstract class DataValidator<D extends BaseData<?>> {
 | 
			
		||||
 | 
			
		||||
    private static EmailValidator emailValidator = EmailValidator.getInstance();
 | 
			
		||||
    private static final Pattern EMAIL_PATTERN =
 | 
			
		||||
            Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
 | 
			
		||||
 | 
			
		||||
    public void validate(D data, Function<D, TenantId> tenantIdFunction) {
 | 
			
		||||
        try {
 | 
			
		||||
@ -64,11 +65,20 @@ public abstract class DataValidator<D extends BaseData<?>> {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static void validateEmail(String email) {
 | 
			
		||||
        if (!emailValidator.isValid(email)) {
 | 
			
		||||
        if (!doValidateEmail(email)) {
 | 
			
		||||
            throw new DataValidationException("Invalid email address format '" + email + "'!");
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private static boolean doValidateEmail(String email) {
 | 
			
		||||
        if (email == null) {
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Matcher emailMatcher = EMAIL_PATTERN.matcher(email);
 | 
			
		||||
        return emailMatcher.matches();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected static void validateJsonStructure(JsonNode expectedNode, JsonNode actualNode) {
 | 
			
		||||
        Set<String> expectedFields = new HashSet<>();
 | 
			
		||||
        Iterator<String> fieldsIterator = expectedNode.fieldNames();
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										6
									
								
								pom.xml
									
									
									
									
									
								
							@ -55,7 +55,6 @@
 | 
			
		||||
        <guava.version>28.2-jre</guava.version>
 | 
			
		||||
        <caffeine.version>2.6.1</caffeine.version>
 | 
			
		||||
        <commons-lang3.version>3.4</commons-lang3.version>
 | 
			
		||||
        <commons-validator.version>1.6</commons-validator.version>
 | 
			
		||||
        <commons-io.version>2.5</commons-io.version>
 | 
			
		||||
        <commons-csv.version>1.4</commons-csv.version>
 | 
			
		||||
        <jackson.version>2.10.2</jackson.version>
 | 
			
		||||
@ -1075,11 +1074,6 @@
 | 
			
		||||
                <artifactId>commons-lang3</artifactId>
 | 
			
		||||
                <version>${commons-lang3.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>commons-validator</groupId>
 | 
			
		||||
                <artifactId>commons-validator</artifactId>
 | 
			
		||||
                <version>${commons-validator.version}</version>
 | 
			
		||||
            </dependency>
 | 
			
		||||
            <dependency>
 | 
			
		||||
                <groupId>commons-io</groupId>
 | 
			
		||||
                <artifactId>commons-io</artifactId>
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user