From 0c725c8fc11dfb0b8f4b731be720cc70c147fc18 Mon Sep 17 00:00:00 2001 From: lucio lelii Date: Mon, 24 Oct 2022 12:49:34 +0200 Subject: [PATCH] check on empty token added --- .../gcube/common/security/secrets/GCubeSecret.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/gcube/common/security/secrets/GCubeSecret.java b/src/main/java/org/gcube/common/security/secrets/GCubeSecret.java index 02c3b3f..01aee8f 100644 --- a/src/main/java/org/gcube/common/security/secrets/GCubeSecret.java +++ b/src/main/java/org/gcube/common/security/secrets/GCubeSecret.java @@ -9,22 +9,25 @@ import org.gcube.common.authorization.client.Constants; import org.gcube.common.authorization.library.AuthorizationEntry; import org.gcube.common.authorization.library.ClientType; import org.gcube.common.security.Owner; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Luca Frosini (ISTI - CNR) */ public class GCubeSecret extends Secret { - public static final String GCUBE_TOKEN_REGEX = "^([a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}-[a-fA-F0-9]{8,9}){1}$"; + public static final String GCUBE_TOKEN_REGEX = "([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(-[0-9]+)?"; private String gcubeToken; private Owner owner; private String context; public GCubeSecret(String gcubeToken) { - Objects.requireNonNull(gcubeToken); - if(!Pattern.matches(GCubeSecret.GCUBE_TOKEN_REGEX, gcubeToken)) - throw new RuntimeException("The GUCBE token must comply with the regex " + GCUBE_TOKEN_REGEX); + if( gcubeToken == null || gcubeToken.isEmpty()) + throw new RuntimeException("Invalid token: is null or empty"); + if(!Pattern.matches(GCUBE_TOKEN_REGEX, gcubeToken)) + throw new RuntimeException("Invalid token: the gCube token must comply with the regex " + GCUBE_TOKEN_REGEX); this.gcubeToken = gcubeToken; }