Adding DEFAULT_DEVICE_USER on adding user

revert-70aa11f8
Rasika Perera 8 years ago
parent 5ce413012e
commit 8e6855a203

@ -77,6 +77,9 @@ public class UserManagementServiceImpl implements UserManagementService {
private static final String API_BASE_PATH = "/users"; private static final String API_BASE_PATH = "/users";
private static final Log log = LogFactory.getLog(UserManagementServiceImpl.class); 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 @POST
@Override @Override
public Response addUser(UserInfo userInfo) { public Response addUser(UserInfo userInfo) {
@ -100,8 +103,14 @@ public class UserManagementServiceImpl implements UserManagementService {
this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(), this.buildDefaultUserClaims(userInfo.getFirstname(), userInfo.getLastname(),
userInfo.getEmailAddress()); userInfo.getEmailAddress());
// calling addUser method of carbon user api // calling addUser method of carbon user api
List<String> 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, userStoreManager.addUser(userInfo.getUsername(), initialUserPassword,
userInfo.getRoles(), defaultUserClaims, null); roles, defaultUserClaims, null);
// Outputting debug message upon successful addition of user // Outputting debug message upon successful addition of user
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("User '" + userInfo.getUsername() + "' has successfully been added."); 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"); log.debug("User credential of username: " + username + " has been changed");
} }
List<String> currentRoles = this.getFilteredRoles(userStoreManager, username); List<String> currentRoles = this.getFilteredRoles(userStoreManager, username);
List<String> newRoles = Arrays.asList(userInfo.getRoles()); List<String> newRoles = new ArrayList<>();
newRoles.add(DEFAULT_DEVICE_USER);
newRoles.addAll(Arrays.asList(userInfo.getRoles()));
List<String> rolesToAdd = new ArrayList<>(newRoles); List<String> rolesToAdd = new ArrayList<>(newRoles);
List<String> rolesToDelete = new ArrayList<>(); List<String> rolesToDelete = new ArrayList<>();

@ -91,11 +91,4 @@ public final class DeviceManagementConstants {
public static final String DB_TYPE_POSTGRESQL = "PostgreSQL"; 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";
}
} }

Loading…
Cancel
Save