diff --git a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java index 7209b2c232e..eeb199ba5ea 100644 --- a/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java +++ b/service/user/internal/src/main/java/org/eclipse/kapua/service/user/internal/UserServiceImpl.java @@ -89,6 +89,7 @@ public User create(UserCreator userCreator) throws KapuaException { ArgumentValidator.notNull(userCreator.getScopeId().getId(), "userCreator.scopeId"); ArgumentValidator.notEmptyOrNull(userCreator.getName(), "userCreator.name"); ArgumentValidator.match(userCreator.getName(), CommonsValidationRegex.NAME_REGEXP, "userCreator.name"); + ArgumentValidator.lengthRange(userCreator.getName(), 3, 255, "userCreator.name"); ArgumentValidator.match(userCreator.getEmail(), CommonsValidationRegex.EMAIL_REGEXP, "userCreator.email"); ArgumentValidator.notNull(userCreator.getStatus(), "userCreator.status"); @@ -96,8 +97,10 @@ public User create(UserCreator userCreator) throws KapuaException { if (userCreator.getUserType() == UserType.EXTERNAL) { if (userCreator.getExternalId() != null) { ArgumentValidator.notEmptyOrNull(userCreator.getExternalId(), "userCreator.externalId"); + ArgumentValidator.lengthRange(userCreator.getExternalId(), 3, 255, "userCreator.externalId"); } else { ArgumentValidator.notEmptyOrNull(userCreator.getExternalUsername(), "userCreator.externalUsername"); + ArgumentValidator.lengthRange(userCreator.getExternalUsername(), 3, 255, "userCreator.externalUsername"); } } else if (userCreator.getUserType() == UserType.INTERNAL) { ArgumentValidator.isEmptyOrNull(userCreator.getExternalId(), "userCreator.externalId"); @@ -159,6 +162,7 @@ public User update(User user) throws KapuaException { ArgumentValidator.notNull(user.getScopeId(), "user.scopeId"); ArgumentValidator.notEmptyOrNull(user.getName(), "user.name"); ArgumentValidator.match(user.getName(), CommonsValidationRegex.NAME_REGEXP, "user.name"); + ArgumentValidator.lengthRange(user.getExternalId(), 3, 255, "user.name"); ArgumentValidator.match(user.getEmail(), CommonsValidationRegex.EMAIL_REGEXP, "user.email"); ArgumentValidator.notNull(user.getStatus(), "user.status"); ArgumentValidator.notNull(user.getUserType(), "user.userType"); @@ -166,8 +170,10 @@ public User update(User user) throws KapuaException { if (user.getUserType() == UserType.EXTERNAL) { if (user.getExternalId() != null) { ArgumentValidator.notEmptyOrNull(user.getExternalId(), "user.externalId"); + ArgumentValidator.lengthRange(user.getExternalId(), 3, 255, "user.externalId"); } else { ArgumentValidator.notEmptyOrNull(user.getExternalUsername(), "user.externalUsername"); + ArgumentValidator.lengthRange(user.getExternalUsername(), 3, 255, "user.externalUsername"); } } else if (user.getUserType() == UserType.INTERNAL) { ArgumentValidator.isEmptyOrNull(user.getExternalId(), "user.externalId"); diff --git a/service/user/internal/src/main/resources/liquibase/2.0.0/user-external_username.xml b/service/user/internal/src/main/resources/liquibase/2.0.0/user-external_username.xml index 78d3f9375ed..e1fa6b1274e 100644 --- a/service/user/internal/src/main/resources/liquibase/2.0.0/user-external_username.xml +++ b/service/user/internal/src/main/resources/liquibase/2.0.0/user-external_username.xml @@ -18,12 +18,46 @@ http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd" logicalFilePath="KapuaDB/changelog-user-2.0.0.xml"> - + + + + + + + + + + + + + + + + + + + - - - + + + + + + + + + + + + + + + + + + +