From b7082d396c37fc9761c910d099e3384e1786d672 Mon Sep 17 00:00:00 2001 From: Madhavi Gayathri Date: Thu, 25 Apr 2024 10:37:41 +0530 Subject: [PATCH] Fix mobile grant issues. --- .../oauth2/grant/mobile/MobileGrant.java | 23 ++++++++++--------- sample-outbound-connector/pom.xml | 16 +++++++++++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java b/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java index b4858da6a..4b9f75f2d 100644 --- a/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java +++ b/oauth2/custom-grant/src/main/java/org/wso2/sample/identity/oauth2/grant/mobile/MobileGrant.java @@ -30,6 +30,8 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; /** * New grant type for Identity Server @@ -158,22 +160,21 @@ public boolean validateScope(OAuthTokenReqMessageContext tokReqMsgCtx) /** - * TODO - * * You need to implement how to validate the mobile number * - * @param mobileNumber - * @return + * @param mobileNumber Mobile number of the user. + * @return true if the mobile number is valid, otherwise false. */ private boolean isValidMobileNumber(String mobileNumber){ - // just demo validation - - if(mobileNumber.startsWith("033")){ - return true; - } - - return false; + // Regular expression to match 10 digits, with optional country code + String pattern = "^(\\+\\d{1,3})?\\d{10}$"; + // Create a Pattern object + Pattern r = Pattern.compile(pattern); + // Create Matcher object + Matcher m = r.matcher(mobileNumber); + // Check if the pattern matches + return m.matches(); } @Override diff --git a/sample-outbound-connector/pom.xml b/sample-outbound-connector/pom.xml index 46aed4265..d2dcde9b3 100644 --- a/sample-outbound-connector/pom.xml +++ b/sample-outbound-connector/pom.xml @@ -132,7 +132,7 @@ wso2-nexus WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ + https://maven.wso2.org/nexus/content/groups/wso2-public/ true daily @@ -142,13 +142,25 @@ wso2.releases WSO2 internal Repository - http://maven.wso2.org/nexus/content/repositories/releases/ + https://maven.wso2.org/nexus/content/repositories/releases/ true daily ignore + + wso2.snapshots + Apache Snapshot Repository + https://maven.wso2.org/nexus/content/repositories/snapshots/ + + true + daily + + + false + +