mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 14:46:49 +00:00
feature/Add function which validates UUID strings
This commit is contained in:
parent
a6cd0090f9
commit
0c5936834f
@ -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.**
|
||||
|
||||
@ -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)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user