Skip to content
Snippets Groups Projects
Unverified Commit 0847b3d7 authored by Richard Cordovano's avatar Richard Cordovano Committed by GitHub
Browse files

Merge pull request #1861 from raman-bt/6172-cr-attrib-validation

6172: Validation of correlation attribute value not happening correctly
parents 41b388ee 416a2bf0
No related branches found
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<dependency org="joda-time" name="joda-time" rev="2.4" /> <dependency org="joda-time" name="joda-time" rev="2.4" />
<dependency org="com.google.guava" name="guava" rev="19.0"/> <dependency org="com.google.guava" name="guava" rev="19.0"/>
<dependency org="org.apache.commons" name="commons-lang3" rev="3.0"/> <dependency org="org.apache.commons" name="commons-lang3" rev="3.0"/>
<dependency org="commons-validator" name="commons-validator" rev="1.6"/>
<dependency org="com.google.code.gson" name="gson" rev="2.8.5"/> <dependency org="com.google.code.gson" name="gson" rev="2.8.5"/>
......
...@@ -114,7 +114,7 @@ ...@@ -114,7 +114,7 @@
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4"> <java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/4">
<compilation-unit> <compilation-unit>
<package-root>src</package-root> <package-root>src</package-root>
<classpath mode="compile">lib;lib/diffutils-1.2.1.jar;lib/junit-4.8.2.jar;lib/postgresql-9.4-1201.jdbc41.jar;lib/c3p0-0.9.5.jar;lib/mchange-commons-java-0.2.9.jar;lib/c3p0-0.9.5-sources.jar;lib/c3p0-0.9.5-javadoc.jar;lib/joda-time-2.4.jar;lib/commons-lang3-3.0.jar;lib/guava-19.0.jar;lib/SparseBitSet-1.1.jar;lib/gson-2.8.5.jar</classpath> <classpath mode="compile">lib;lib/diffutils-1.2.1.jar;lib/junit-4.8.2.jar;lib/postgresql-9.4-1201.jdbc41.jar;lib/c3p0-0.9.5.jar;lib/mchange-commons-java-0.2.9.jar;lib/c3p0-0.9.5-sources.jar;lib/c3p0-0.9.5-javadoc.jar;lib/joda-time-2.4.jar;lib/commons-lang3-3.0.jar;lib/guava-19.0.jar;lib/SparseBitSet-1.1.jar;lib/gson-2.8.5.jar;lib/commons-validator-1.6.jar</classpath>
<built-to>build</built-to> <built-to>build</built-to>
<source-level>1.8</source-level> <source-level>1.8</source-level>
</compilation-unit> </compilation-unit>
......
...@@ -1315,52 +1315,19 @@ int getAccountTypeId(Account.Type accountType) { ...@@ -1315,52 +1315,19 @@ int getAccountTypeId(Account.Type accountType) {
* *
* @return The normalized account id. * @return The normalized account id.
*/ */
private String normalizeAccountID(Account.Type accountType, String accountUniqueID) { private String normalizeAccountID(Account.Type accountType, String accountUniqueID) throws TskCoreException {
String normailzeAccountID = accountUniqueID; String normailzeAccountID = accountUniqueID;
if (accountType.equals(Account.Type.PHONE)) { if (accountType.equals(Account.Type.PHONE)) {
normailzeAccountID = normalizePhoneNum(accountUniqueID); normailzeAccountID = CommunicationsUtils.normalizePhoneNum(accountUniqueID);
} else if (accountType.equals(Account.Type.EMAIL)) { } else if (accountType.equals(Account.Type.EMAIL)) {
normailzeAccountID = normalizeEmailAddress(accountUniqueID); normailzeAccountID = CommunicationsUtils.normalizeEmailAddress(accountUniqueID);
} }
return normailzeAccountID; return normailzeAccountID;
} }
/**
* Normalize the phone number by removing all non numeric characters, except
* for leading +.
*
* @param phoneNum The phone number to normalize
*
* @return The normalized phone number.
*/
private String normalizePhoneNum(String phoneNum) {
String normailzedPhoneNum = phoneNum.replaceAll("\\D", "");
if (phoneNum.startsWith("+")) {
normailzedPhoneNum = "+" + normailzedPhoneNum;
}
if (normailzedPhoneNum.isEmpty()) {
normailzedPhoneNum = phoneNum;
}
return normailzedPhoneNum;
}
/**
* Normalize the given email address by converting it to lowercase.
*
* @param emailAddress The email address tot normalize
*
* @return The normalized email address.
*/
private String normalizeEmailAddress(String emailAddress) {
String normailzedEmailAddr = emailAddress.toLowerCase();
return normailzedEmailAddr;
}
/** /**
* Builds the SQL for the given CommunicationsFilter. * Builds the SQL for the given CommunicationsFilter.
......
/*
* Sleuth Kit Data Model
*
* Copyright 2020 Basis Technology Corp.
* Contact: carrier <at> sleuthkit <dot> org
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.sleuthkit.datamodel;
import org.apache.commons.validator.routines.EmailValidator;
/**
* Provides general utility methods related to communications artifacts.
*
*/
public final class CommunicationsUtils {
/**
* Empty private constructor.
*/
private CommunicationsUtils() {
}
/**
* Checks if the given string may be a phone number.
* Normalize the phone number by removing all non numeric characters, except
* for leading +.
*
* @param phoneNum The string to check and normalize.
*
* @return The normalized phone number.
*
* @throws TskCoreException If the given string is not a valid phone number.
*
*/
public static String normalizePhoneNum(String phoneNum) throws TskCoreException {
if (phoneNum.matches("\\+?[0-9()\\-\\s]+")) {
return phoneNum.replaceAll("[^0-9\\+]", "");
} else {
throw new TskCoreException(String.format("Input string is not a valid phone number: %s", phoneNum));
}
}
/**
* Checks if the given string is a valid email address.
* Normalizes the given email address by converting it to lowercase.
*
* @param emailAddress The string to be checked and normalized.
*
* @return The normalized email address.
* @throws TskCoreException If the given string is not a valid email address.
*/
public static String normalizeEmailAddress(String emailAddress) throws TskCoreException {
EmailValidator validator = EmailValidator.getInstance(true, true);
if (validator.isValid(emailAddress)) {
return emailAddress.toLowerCase();
} else {
throw new TskCoreException(String.format("Input string is not a valid email address: %s", emailAddress));
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment