public SystemUser update( SystemUserVO systemUserVO, String[] roleNames, String[] groupNames, Database db) throws ConstraintException, SystemException { SystemUser systemUser = getSystemUserWithName(systemUserVO.getUserName(), db); systemUserVO.setUserName(systemUser.getUserName()); if (roleNames != null) { systemUser.getRoles().clear(); for (int i = 0; i < roleNames.length; i++) { Role role = RoleController.getController().getRoleWithName(roleNames[i], db); systemUser.getRoles().add(role); role.getSystemUsers().add(systemUser); } } if (groupNames != null) { systemUser.getGroups().clear(); for (int i = 0; i < groupNames.length; i++) { Group group = GroupController.getController().getGroupWithName(groupNames[i], db); systemUser.getGroups().add(group); group.getSystemUsers().add(systemUser); } } systemUserVO.setPassword(systemUser.getPassword()); systemUser.setValueObject(systemUserVO); return systemUser; }
public SystemUser update( SystemUserVO systemUserVO, String oldPassword, String[] roleNames, String[] groupNames, Database db) throws ConstraintException, SystemException, Exception { logger.info("systemUserVO:" + systemUserVO.getUserName()); logger.info("oldPassword:"******"newPassword:"******"roleNames:" + roleNames); logger.info("groupNames:" + groupNames); if (CmsPropertyHandler.getUsePasswordEncryption()) { String password = systemUserVO.getPassword(); try { byte[] encryptedPassRaw = DigestUtils.sha(password); String encryptedPass = new String(new Base64().encode(encryptedPassRaw), "ASCII"); password = encryptedPass; systemUserVO.setPassword(password); byte[] encryptedOldPasswordRaw = DigestUtils.sha(oldPassword); String encryptedOldPassword = new String(new Base64().encode(encryptedOldPasswordRaw), "ASCII"); oldPassword = encryptedOldPassword; } catch (Exception e) { logger.error("Error generating password:"******"Wrong user or password."); systemUserVO.setUserName(systemUser.getUserName()); if (roleNames != null) { systemUser.getRoles().clear(); for (int i = 0; i < roleNames.length; i++) { Role role = RoleController.getController().getRoleWithName(roleNames[i], db); systemUser.getRoles().add(role); role.getSystemUsers().add(systemUser); } } if (groupNames != null) { systemUser.getGroups().clear(); for (int i = 0; i < groupNames.length; i++) { Group group = GroupController.getController().getGroupWithName(groupNames[i], db); systemUser.getGroups().add(group); group.getSystemUsers().add(systemUser); } } // systemUserVO.setPassword(systemUser.getPassword()); systemUser.setValueObject(systemUserVO); return systemUser; }
/** Registers a new system user. */ public Boolean createUser( final String principalName, String firstName, String lastName, String email, String userName, String password, List roleNames, List groupNames) { if (!ServerNodeController.getController().getIsIPAllowed(getRequest())) { logger.error( "A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct."); return new Boolean(false); } Boolean status = new Boolean(true); logger.info("***************************************"); logger.info("Creating user through webservice......."); logger.info("***************************************"); try { initializePrincipal(principalName); SystemUserVO systemUserVO = new SystemUserVO(); systemUserVO.setFirstName(firstName); systemUserVO.setLastName(lastName); systemUserVO.setEmail(email); systemUserVO.setUserName(userName); systemUserVO.setPassword(password); Object[] roleNamesArray = roleNames.toArray(); Object[] groupNamesArray = groupNames.toArray(); String[] roles = new String[roleNamesArray.length]; String[] groups = new String[groupNamesArray.length]; for (int i = 0; i < roleNamesArray.length; i++) roles[i] = "" + roleNamesArray[i]; for (int i = 0; i < groupNamesArray.length; i++) groups[i] = "" + groupNamesArray[i]; userControllerProxy.createUser(systemUserVO); userControllerProxy.updateUser(systemUserVO, roles, groups); } catch (Exception e) { status = new Boolean(false); logger.error( "En error occurred when we tried to create a new contentVersion:" + e.getMessage(), e); } updateCaches(); return status; }
/** Updates a system user. */ public StatusBean updateUser( final String principalName, final Object[] inputsArray, String[] roleNames, String[] groupNames) { if (!ServerNodeController.getController().getIsIPAllowed(getRequest())) { logger.error( "A client with IP " + getRequest().getRemoteAddr() + " was denied access to the webservice. Could be a hack attempt or you have just not configured the allowed IP-addresses correct."); return new StatusBean(false, "You are not allowed to talk to this service"); } StatusBean statusBean = new StatusBean(true, "ok"); logger.info("***************************************"); logger.info("Updating user through webservice......."); logger.info("***************************************"); try { final DynamicWebserviceSerializer serializer = new DynamicWebserviceSerializer(); List users = (List) serializer.deserialize(inputsArray); logger.info("users:" + users); initializePrincipal(principalName); Iterator usersIterator = users.iterator(); while (usersIterator.hasNext()) { Map userMap = (Map) usersIterator.next(); Boolean isPasswordChangeOperation = (Boolean) userMap.get("isPasswordChangeOperation"); Boolean isPasswordResetOperation = (Boolean) userMap.get("isPasswordResetOperation"); String firstName = (String) userMap.get("firstName"); String lastName = (String) userMap.get("lastName"); String email = (String) userMap.get("email"); String userName = (String) userMap.get("userName"); String password = (String) userMap.get("password"); String oldPassword = (String) userMap.get("oldPassword"); if (isPasswordChangeOperation) { logger.info("isPasswordChangeOperation"); logger.info("userName:"******"oldPassword:"******"password:"******"isPasswordResetOperation"); userControllerProxy.updateUserPassword(userName); } else { logger.info("isUserUpdateOperation"); SystemUserVO systemUserVO = new SystemUserVO(); systemUserVO.setEmail(email); systemUserVO.setFirstName(firstName); systemUserVO.setLastName(lastName); systemUserVO.setPassword(password); systemUserVO.setUserName(userName); if (roleNames != null && roleNames.length == 0) roleNames = null; if (groupNames != null && groupNames.length == 0) groupNames = null; userControllerProxy.updateUser(systemUserVO, oldPassword, roleNames, groupNames); } } } catch (Throwable e) { statusBean.setStatus(false); statusBean.setMessage( "En error occurred when we tried to update one or more users:" + e.getMessage()); logger.error( "En error occurred when we tried to update one or more users:" + e.getMessage(), e); } updateCaches(); return statusBean; }