implemented phone checks and sms checks
This commit is contained in:
@@ -2,6 +2,7 @@ package com.safeqr.app.qrcode.entity;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
@@ -30,4 +31,8 @@ public class PhoneEntity {
|
|||||||
private UUID qrCodeId;
|
private UUID qrCodeId;
|
||||||
|
|
||||||
private String phone;
|
private String phone;
|
||||||
|
|
||||||
|
@JsonInclude(JsonInclude.Include.NON_EMPTY)
|
||||||
|
@Column(name = "remarks")
|
||||||
|
private String remarks;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,6 +38,6 @@ public final class PhoneModel extends QRCodeModel<PhoneEntity> {
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String retrieveClassification() {
|
public String retrieveClassification() {
|
||||||
return "";
|
return phoneVerificationService.checkPhoneNumber(details);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,8 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.safeqr.app.constants.CommonConstants.*;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class PhoneVerificationService {
|
public class PhoneVerificationService {
|
||||||
private final PhoneRepository phoneRepository;
|
private final PhoneRepository phoneRepository;
|
||||||
@@ -48,4 +50,30 @@ public class PhoneVerificationService {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String checkPhoneNumber(PhoneEntity phoneEntity) {
|
||||||
|
// Remove any spaces, dashes, parentheses, and trim the ends
|
||||||
|
String phoneNumber = phoneEntity.getPhone().replaceAll("[\\s\\-()]", "").trim();
|
||||||
|
|
||||||
|
// Check if the number starts with +65 or just 65
|
||||||
|
if (phoneNumber.startsWith("+65")) {
|
||||||
|
phoneNumber = phoneNumber.substring(3); // Remove the "+65"
|
||||||
|
} else if (phoneNumber.startsWith("65")) {
|
||||||
|
phoneNumber = phoneNumber.substring(2); // Remove the "65"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a valid Singapore mobile or landline number
|
||||||
|
if (phoneNumber.matches("^[689]\\d{7}$")) {
|
||||||
|
if (phoneNumber.startsWith("8") || phoneNumber.startsWith("9")) {
|
||||||
|
phoneEntity.setRemarks("Singapore mobile number - This number has not been scanned for scam. Please do not divulge your personal information.");
|
||||||
|
} else if (phoneNumber.startsWith("6")) {
|
||||||
|
phoneEntity.setRemarks("Singapore landline number - This phone number has not been scanned for scam. Please do not divulge your personal information.");
|
||||||
|
}
|
||||||
|
return CLASSIFY_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it doesn't match mobile or landline pattern
|
||||||
|
phoneEntity.setRemarks("Warning: This is either an overseas number or an invalid Singapore number. Please exercise caution.");
|
||||||
|
return CLASSIFY_WARNING;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package com.safeqr.app.qrcode.service;
|
|||||||
|
|
||||||
import com.safeqr.app.exceptions.InvalidFormatExceptions;
|
import com.safeqr.app.exceptions.InvalidFormatExceptions;
|
||||||
import com.safeqr.app.exceptions.ResourceNotFoundExceptions;
|
import com.safeqr.app.exceptions.ResourceNotFoundExceptions;
|
||||||
|
import com.safeqr.app.qrcode.entity.PhoneEntity;
|
||||||
import com.safeqr.app.qrcode.entity.SMSEntity;
|
import com.safeqr.app.qrcode.entity.SMSEntity;
|
||||||
import com.safeqr.app.qrcode.repository.SMSRepository;
|
import com.safeqr.app.qrcode.repository.SMSRepository;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -12,8 +13,7 @@ import org.springframework.transaction.annotation.Transactional;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import static com.safeqr.app.constants.CommonConstants.CLASSIFY_SAFE;
|
import static com.safeqr.app.constants.CommonConstants.*;
|
||||||
import static com.safeqr.app.constants.CommonConstants.CLASSIFY_WARNING;
|
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
public class SMSVerificationService {
|
public class SMSVerificationService {
|
||||||
@@ -84,7 +84,6 @@ public class SMSVerificationService {
|
|||||||
throw new InvalidFormatExceptions("Invalid SMSTO format. Expected format: SMSTO:<phone>:<message>");
|
throw new InvalidFormatExceptions("Invalid SMSTO format. Expected format: SMSTO:<phone>:<message>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@Transactional
|
|
||||||
public String getClassification (SMSEntity smsEntity) {
|
public String getClassification (SMSEntity smsEntity) {
|
||||||
|
|
||||||
String lowerCaseSms = smsEntity.getMessage().toLowerCase();
|
String lowerCaseSms = smsEntity.getMessage().toLowerCase();
|
||||||
@@ -105,8 +104,28 @@ public class SMSVerificationService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// If no phishing keywords are found
|
// If no phishing keywords are found, sent for local phone number checks
|
||||||
return CLASSIFY_SAFE;
|
return checkPhoneNumber(smsEntity.getPhone());
|
||||||
|
}
|
||||||
|
|
||||||
|
private String checkPhoneNumber(String phoneNumber) {
|
||||||
|
// Remove any spaces, dashes, parentheses, and trim the ends
|
||||||
|
phoneNumber = phoneNumber.replaceAll("[\\s\\-()]", "").trim();
|
||||||
|
|
||||||
|
// Check if the number starts with +65 or just 65
|
||||||
|
if (phoneNumber.startsWith("+65")) {
|
||||||
|
phoneNumber = phoneNumber.substring(3); // Remove the "+65"
|
||||||
|
} else if (phoneNumber.startsWith("65")) {
|
||||||
|
phoneNumber = phoneNumber.substring(2); // Remove the "65"
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a valid Singapore mobile or landline number
|
||||||
|
if (phoneNumber.matches("^[689]\\d{7}$") && (phoneNumber.startsWith("8") || phoneNumber.startsWith("9"))) {
|
||||||
|
return CLASSIFY_SAFE;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it doesn't match mobile
|
||||||
|
return CLASSIFY_UNSAFE;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user