/** * Delete a Role form User. * * @param username * @param role */ public void deleteRole(String username, String role) { String[] infos = null; StringBuffer userInfoBuffer = new StringBuffer(); String userInfos = (String) users.get(username); // If user already exists, remove the role if (userInfos != null && userInfos.length() > 0) { infos = userInfos.split(","); String password = infos[0]; userInfoBuffer.append(password); for (int i = 1; i < infos.length; i++) { if (infos[i] != null && !infos[i].equals(role)) { userInfoBuffer.append(","); userInfoBuffer.append(infos[i]); } } String newUserInfo = userInfoBuffer.toString(); users.put(username, newUserInfo); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }
/** * Add a user. * * @param username * @param password */ public void addUser(String username, String password) { String[] infos = null; StringBuffer userInfoBuffer = new StringBuffer(); String newPassword = password; // If encryption support is enabled, encrypt password if (encryptionSupport != null && encryptionSupport.getEncryption() != null) { newPassword = encryptionSupport.getEncryption().encryptPassword(password); if (encryptionSupport.getEncryptionPrefix() != null) { newPassword = encryptionSupport.getEncryptionPrefix() + newPassword; } if (encryptionSupport.getEncryptionSuffix() != null) { newPassword = newPassword + encryptionSupport.getEncryptionSuffix(); } } String userInfos = (String) users.get(username); // If user already exists, update password if (userInfos != null && userInfos.length() > 0) { infos = userInfos.split(","); userInfoBuffer.append(newPassword); for (int i = 1; i < infos.length; i++) { userInfoBuffer.append(","); userInfoBuffer.append(infos[i]); } String newUserInfo = userInfoBuffer.toString(); users.put(username, newUserInfo); } else { users.put(username, newPassword); } try { users.save(); } catch (Exception ex) { LOGGER.error("Cannot update users file,", ex); } }