From 8e6855a203ddb3cbd6a0d5ce8afe93b1c77f19c6 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Fri, 20 Jan 2017 17:59:58 +0530 Subject: [PATCH] Adding DEFAULT_DEVICE_USER on adding user --- .../service/impl/UserManagementServiceImpl.java | 15 +++++++++++++-- .../mgt/common/DeviceManagementConstants.java | 7 ------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 0390e5b13df..42aa120a85f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -77,6 +77,9 @@ public class UserManagementServiceImpl implements UserManagementService { private static final String API_BASE_PATH = "/users"; private static final Log log = LogFactory.getLog(UserManagementServiceImpl.class); + private static final String DEFAULT_DEVICE_USER = "Internal/devicemgt-user"; + private static final String DEFAULT_DEVICE_ADMIN = "Internal/devicemgt-admin"; + @POST @Override public Response addUser(UserInfo userInfo) { @@ -100,8 +103,14 @@ public class UserManagementServiceImpl implements UserManagementService { this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), userInfo.getEmailAddress()); // calling addUser method of carbon user api + List tmpRoles = new ArrayList<>(); + tmpRoles.add(DEFAULT_DEVICE_USER); + tmpRoles.addAll(Arrays.asList(userInfo.getRoles())); + String[] roles = new String[tmpRoles.size()]; + tmpRoles.toArray(roles); + userStoreManager.addUser(userInfo.getUsername(), initialUserPassword, - userInfo.getRoles(), defaultUserClaims, null); + roles, defaultUserClaims, null); // Outputting debug message upon successful addition of user if (log.isDebugEnabled()) { log.debug("User '" + userInfo.getUsername() + "' has successfully been added."); @@ -211,7 +220,9 @@ public class UserManagementServiceImpl implements UserManagementService { log.debug("User credential of username: " + username + " has been changed"); } List currentRoles = this.getFilteredRoles(userStoreManager, username); - List newRoles = Arrays.asList(userInfo.getRoles()); + List newRoles = new ArrayList<>(); + newRoles.add(DEFAULT_DEVICE_USER); + newRoles.addAll(Arrays.asList(userInfo.getRoles())); List rolesToAdd = new ArrayList<>(newRoles); List rolesToDelete = new ArrayList<>(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java index 1366a937141..ba0d3d59eda 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManagementConstants.java @@ -91,11 +91,4 @@ public final class DeviceManagementConstants { public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; } - public static final class Users { - private Users() { - throw new AssertionError(); - } - public static final String DEFAULT_DEVICE_USER = "Internal/devicemgt-user"; - public static final String DEFAULT_DEVICE_ADMIN = "Internal/devicemgt-admin"; - } }