From 0427959f23e615ddef86323c1afd2134b28bcf8b Mon Sep 17 00:00:00 2001 From: osh Date: Thu, 14 Dec 2023 08:40:00 +0530 Subject: [PATCH] Fix reggex issue when configuring wifi --- .../mgt/api/jaxrs/service/impl/MetadataServiceImpl.java | 6 ++++++ .../api/jaxrs/service/impl/util/RequestValidationUtil.java | 3 +++ 2 files changed, 9 insertions(+) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/MetadataServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/MetadataServiceImpl.java index 0cf4f662f1..fcb864c3cc 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/MetadataServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/MetadataServiceImpl.java @@ -95,6 +95,9 @@ public class MetadataServiceImpl implements MetadataService { @PathParam("metaKey") String metaKey) { Metadata metadata; try { + if (metaKey.contains("-")) { + metaKey = metaKey.replace('-', '_'); + } metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey); return Response.status(Response.Status.OK).entity(metadata).build(); } catch (MetadataManagementException e) { @@ -144,6 +147,9 @@ public class MetadataServiceImpl implements MetadataService { public Response deleteMetadataEntry( @PathParam("metaKey") String metaKey) { try { + if (metaKey.contains("-")) { + metaKey = metaKey.replace('-', '_'); + } DeviceMgtAPIUtils.getMetadataManagementService().deleteMetadata(metaKey); return Response.status(Response.Status.OK).entity("Metadata entry is deleted successfully.").build(); } catch (MetadataKeyNotFoundException e) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java index c277cbfe56..5eb474cb32 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/util/RequestValidationUtil.java @@ -805,6 +805,9 @@ public class RequestValidationUtil { new ErrorResponse.ErrorResponseBuilder() .setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build()); } + if (metadata.getMetaKey().contains("-")) { + metadata.setMetaKey(metadata.getMetaKey().replace('-', '_')); + } String regex = "^[a-zA-Z0-9_.]*$"; if (!metadata.getMetaKey().matches(regex)) { String msg = "Request parameter metaKey should only contain period, " +