/** 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; }