diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 157d73241df..b570adff88a 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -3434,6 +3434,7 @@ public class ApplicationManagerImpl implements ApplicationManager { String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); int deviceTypeId = -1; String appName; + int appNameLength = 20; List appCategories; List unrestrictedRoles; @@ -3445,6 +3446,11 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + if (appName.length() > appNameLength) { + String msg = "Application name must be less than or equal to 20 characters in length."; + log.error(msg); + throw new BadRequestException(msg); + } appCategories = applicationWrapper.getCategories(); if (appCategories == null) { String msg = "Application category can't be null."; @@ -3477,6 +3483,11 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + if (appName.length() > appNameLength) { + String msg = "Application name must be less than or equal to 20 characters in length."; + log.error(msg); + throw new BadRequestException(msg); + } appCategories = webAppWrapper.getCategories(); if (appCategories == null) { String msg = "Web Clip category can't be null."; @@ -3510,6 +3521,11 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + if (appName.length() > appNameLength) { + String msg = "Application name must be less than or equal to 20 characters in length."; + log.error(msg); + throw new BadRequestException(msg); + } appCategories = publicAppWrapper.getCategories(); if (appCategories == null) { String msg = "Application category can't be null."; @@ -3542,6 +3558,11 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + if (appName.length() > appNameLength) { + String msg = "Application name must be less than or equal to 20 characters in length."; + log.error(msg); + throw new BadRequestException(msg); + } appCategories = customAppWrapper.getCategories(); if (appCategories == null) { String msg = "Application category can't be null."; diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java index 3048cc8f1f1..21ad941f69a 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/src/main/java/io/entgra/application/mgt/publisher/api/services/impl/ApplicationManagementPublisherAPIImpl.java @@ -371,19 +371,28 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem if (appName == null) { String msg = "Invalid app name, appName query param cannot be empty/null."; log.error(msg); - return Response.status(Response.Status.BAD_REQUEST).build(); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + if (appName.length() > 20) { + String msg = "Invalid app name, maximum length of the application name should be 20 characters."; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } ApplicationManager applicationManager = APIUtil.getApplicationManager(); if (applicationManager.isExistingAppName(appName, deviceType)) { - return Response.status(Response.Status.CONFLICT).build(); + String msg = "Invalid app name, app name already exists."; + log.error(msg); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); } return Response.status(Response.Status.OK).build(); } catch (BadRequestException e) { - log.error("Found invalid device type to check application existence.", e); - return Response.status(Response.Status.BAD_REQUEST).build(); + String msg = "Found invalid device type to check application existence."; + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); } catch (ApplicationManagementException e) { - log.error("Internal Error occurred while checking the application existence.", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + String msg = "Internal Error occurred while checking the application existence."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } }