feature/Add function which validates UUID strings

This commit is contained in:
Marko Milić 2022-12-16 09:09:11 +01:00
parent a6cd0090f9
commit 0c5936834f
2 changed files with 14 additions and 2 deletions

View File

@ -112,8 +112,9 @@ import javassist.{ClassPool, LoaderClassPath}
import javassist.expr.{ExprEditor, MethodCall}
import org.apache.commons.io.IOUtils
import org.apache.commons.lang3.StringUtils
import java.security.AccessControlException
import java.util.regex.Pattern
import code.users.Users
import scala.collection.mutable
@ -3482,6 +3483,17 @@ object APIUtil extends MdcLoggable with CustomJsonFormats{
*/
def generateUUID(): String = UUID.randomUUID().toString
/**
* This function validates UUID (Universally Unique Identifier) strings
* @param value a string we're trying to validate
* @return false in case the string doesn't represent a UUID, true in case the string represents a UUID
*/
def checkIfStringIsUUID(value: String): Boolean = {
Pattern.compile("^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
.matcher(value).matches()
}
def mockedDataText(isMockedData: Boolean) =
if (isMockedData)
"""**NOTE: This endpoint currently only returns example data.**

View File

@ -381,7 +381,7 @@ object Consent {
}
def getConsentsJwtValueByConsentId(consentId: String): Option[String] = {
ControlHelpers.tryo(UUID.fromString(consentId)).isDefined match {
APIUtil.checkIfStringIsUUID(consentId) match {
case true => // String is a UUID
Consents.consentProvider.vend.getConsentByConsentId(consentId) match {
case Full(consent) => Some(consent.jsonWebToken)