Example usage for javax.servlet.http HttpServletRequest isUserInRole

List of usage examples for javax.servlet.http HttpServletRequest isUserInRole

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest isUserInRole.

Prototype

public boolean isUserInRole(String role);

Source Link

Document

Returns a boolean indicating whether the authenticated user is included in the specified logical "role".

Usage

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

@RequestMapping(value = "editFunction", method = RequestMethod.POST)
public String editFunction(@Valid @ModelAttribute FireEngineAbbreviationModel changedFireEngineAbbreviation,
        BindingResult bindingResult, Model model, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        String errorMessage = "";
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            errorMessage += fieldError.getField() + " ist ungltig!";
        }/* w ww .ja  v  a 2 s  . co  m*/
        model.addAttribute("errorMessage", errorMessage);
        return "forward:funktionen";
    }

    if (request.isUserInRole("ROLE_GLOBAL_ADMIN")) {
        FireEngineAbbreviationModel fireEngineAbbreviation = fireEngineAbbreviationRepository
                .findById(changedFireEngineAbbreviation.getId());

        if (fireEngineAbbreviation == null) {
            model.addAttribute("errorMessage", "Diese Fahrzeugfunktion kann nicht bearbeitet werden!");
        } else {
            fireEngineAbbreviation.setDescription(changedFireEngineAbbreviation.getDescription());
            fireEngineAbbreviation.setAbbreviation(changedFireEngineAbbreviation.getAbbreviation());
            fireEngineAbbreviation.setOperatingLife(changedFireEngineAbbreviation.getOperatingLife());
            fireEngineAbbreviationRepository.save(fireEngineAbbreviation);
            model.addAttribute("message", "Fahrzeugfunktion " + changedFireEngineAbbreviation.getDescription()
                    + " wurde erfolgreich gendert.");
        }
        return "forward:funktionen";

    } else {
        FireEngineAbbreviationModel fireEngineAbbreviation = fireEngineAbbreviationRepository
                .findById(changedFireEngineAbbreviation.getId());

        if (fireEngineAbbreviation == null) {
            model.addAttribute("errorMessage", "Diese Fahrzeugfunktion kann nicht bearbeitet werden!");
            System.out.println("Falsche Fahrzeugfunktion!");
        } else {
            fireEngineAbbreviation.setDescription(changedFireEngineAbbreviation.getDescription());
            fireEngineAbbreviation.setAbbreviation(changedFireEngineAbbreviation.getAbbreviation());
            fireEngineAbbreviation.setOperatingLife(changedFireEngineAbbreviation.getOperatingLife());
            fireEngineAbbreviationRepository.save(fireEngineAbbreviation);
            model.addAttribute("message", "Fahrzeugfunktion " + changedFireEngineAbbreviation.getDescription()
                    + " wurde erfolgreich gendert!");
        }
        return "forward:funktionen";
    }
}

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

@RequestMapping(value = "editFireBrigade", method = RequestMethod.POST)
public String editFireBrigade(@Valid @ModelAttribute FireBrigadeModel changedFireBrigade,
        BindingResult bindingResult, Model model, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        String errorMessage = "";
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            errorMessage += fieldError.getField() + " ist ungltig!";
        }//from   w  ww  .j av a2s .c o m
        model.addAttribute("errorMessage", errorMessage);
        return "forward:feuerwehr";
    }

    if (request.isUserInRole("ROLE_GLOBAL_ADMIN")) {
        FireBrigadeModel fireBrigade = fireBrigadeRepository.findById(changedFireBrigade.getId());

        if (fireBrigade == null) {
            model.addAttribute("errorMessage", "Diese Feuerwehr kann nicht bearbeitet werden!");
        } else {
            fireBrigade.setName(changedFireBrigade.getName());
            fireBrigade.setPostalCode(changedFireBrigade.getPostalCode());
            fireBrigade.setPostTown(changedFireBrigade.getPostTown());
            fireBrigade.setStreetName(changedFireBrigade.getStreetName());
            fireBrigadeRepository.save(fireBrigade);
            model.addAttribute("message",
                    "Feuerwehr " + changedFireBrigade.getName() + " wurde erfolgreich gendert.");
        }
        return "forward:feuerwehr";

    } else {
        FireBrigadeModel fireBrigade = fireBrigadeRepository.findByIdAndName(changedFireBrigade.getId(),
                getSessionFireBrigade().getName());

        if (fireBrigade == null) {
            model.addAttribute("errorMessage", "Diese Feuerwehr kann nicht bearbeitet werden!");
            System.out.println("Falsche Feuerwehr!");
        } else {
            fireBrigade.setName(changedFireBrigade.getName());
            fireBrigade.setPostalCode(changedFireBrigade.getPostalCode());
            fireBrigade.setPostTown(changedFireBrigade.getPostTown());
            fireBrigade.setStreetName(changedFireBrigade.getStreetName());
            fireBrigadeRepository.save(fireBrigade);
            model.addAttribute("message",
                    "Feuerwehr " + changedFireBrigade.getName() + " wurde erfolgreich gendert!");
            new SecurityContextLogoutHandler().logout(request, null, null);
            return "redirect:login";
        }
        return "forward:feuerwehr";
    }
}

From source file:com.pkrete.locationservice.admin.controller.mvc.IllustrationController.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    Owner owner = UsersUtil.getUser(request, usersService).getOwner();
    /* Model that is returned together with the view */
    java.util.Map<String, Object> model = new HashMap<String, Object>();
    String imageId = request.getParameter("select_image");
    String mapId = request.getParameter("select_map");

    if (request.getParameter("btn_add_img") != null) {
        return new ModelAndView("redirect:addimage.htm");
    } else if (request.getParameter("btn_edit_img") != null && imageId != null) {
        return new ModelAndView("redirect:editimage.htm?imageId=" + imageId);
    } else if (request.getParameter("btn_delete_img") != null && imageId != null) {
        if (!imagesService.delete(this.converterService.strToInt(imageId), owner)) {
            model.put("errorMsgImg", this.messageSource.getMessage("error.image.delete", null, null));
        }/*from   w  w  w .  j  a v  a  2  s .  c o  m*/
    } else if (request.getParameter("btn_add_map") != null) {
        return new ModelAndView("redirect:addmap.htm");
    } else if (request.getParameter("btn_edit_map") != null && mapId != null) {
        return new ModelAndView("redirect:editmap.htm?mapId=" + mapId);
    } else if (request.getParameter("btn_delete_map") != null && mapId != null) {
        if (!mapsService.delete(this.converterService.strToInt(mapId), owner)) {
            model.put("errorMsgMap", this.messageSource.getMessage("error.map.delete", null, null));
        }
    }

    if (request.isUserInRole(UserGroup.ADMIN.toString())) {
        model.put("isAdmin", "");
    }

    model.put("images", imagesService.get(owner));
    model.put("maps", mapsService.get(owner));
    return new ModelAndView("illustration", "model", model);
}

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

@RequestMapping(value = "editFireFighter", method = RequestMethod.POST)
public String editFireFighter(@Valid @ModelAttribute FireFighterModel changedFireFighter,
        BindingResult bindingResult, Model model, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        String errorMessage = "";
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            errorMessage = fieldError.getField() + " ist ungltig!";
        }//from   w  w  w . ja  v  a2  s  .c o  m
        model.addAttribute("errorMessage", errorMessage);
        return "forward:mitglieder";
    }

    if (request.isUserInRole("ROLE_GLOBAL_ADMIN")) {
        FireFighterModel fireFighter = fireFighterRepository.findById(changedFireFighter.getId());

        if (fireFighter == null) {
            model.addAttribute("errorMessage", "Dieses Mitglied kann nicht bearbeitet werden!");
        } else {
            fireFighter.setTitle(changedFireFighter.getTitle());
            fireFighter.setName(changedFireFighter.getName());
            fireFighter.setSurname(changedFireFighter.getSurname());
            fireFighter.setRank(changedFireFighter.getRank());
            fireFighter.setFireBrigade(changedFireFighter.getFireBrigade());
            fireFighter.setFireFighterStatus(changedFireFighter.getFireFighterStatus());
            fireFighter.setStreetName(changedFireFighter.getStreetName());
            fireFighter.setPostalCode(changedFireFighter.getPostalCode());
            fireFighter.setPostTown(changedFireFighter.getPostTown());
            fireFighter.setGender(changedFireFighter.getGender());
            fireFighter.setDayOfBirth(changedFireFighter.getDayOfBirth());
            fireFighterRepository.save(fireFighter);
            model.addAttribute("message", "Mitglied " + changedFireFighter.getName() + " "
                    + changedFireFighter.getSurname() + " " + "wurde gendert.");
        }
        return "forward:mitglieder";

    } else {
        FireFighterModel fireFighter = fireFighterRepository.findByFireBrigadeAndId(getSessionFireBrigade(),
                changedFireFighter.getId());

        if (fireFighter == null) {
            model.addAttribute("errorMessage", "Dieses Mitglied kann nicht bearbeitet werden!");
            System.out.println("Falsches Mitglied!");
        } else {
            fireFighter.setTitle(changedFireFighter.getTitle());
            fireFighter.setName(changedFireFighter.getName());
            fireFighter.setSurname(changedFireFighter.getSurname());
            fireFighter.setRank(changedFireFighter.getRank());
            fireFighter.setFireBrigade(getSessionFireBrigade());
            fireFighter.setFireFighterStatus(changedFireFighter.getFireFighterStatus());
            fireFighter.setStreetName(changedFireFighter.getStreetName());
            fireFighter.setPostalCode(changedFireFighter.getPostalCode());
            fireFighter.setPostTown(changedFireFighter.getPostTown());
            fireFighter.setGender(changedFireFighter.getGender());
            fireFighter.setDayOfBirth(changedFireFighter.getDayOfBirth());
            fireFighterRepository.save(fireFighter);
            model.addAttribute("message", "Mitglied " + changedFireFighter.getName() + " "
                    + changedFireFighter.getSurname() + " " + "wurde gendert.");
        }
        return "forward:mitglieder";
    }
}

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

@RequestMapping(value = "editFireEngine", method = RequestMethod.POST)
public String editFireEngine(@Valid @ModelAttribute FireEngineModel changedFireEngine,
        BindingResult bindingResult, Model model, HttpServletRequest request) {
    if (bindingResult.hasErrors()) {
        String errorMessage = "";
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            errorMessage = fieldError.getField() + " is invalid";
        }/*w w w .ja  v  a 2  s  . c o m*/
        model.addAttribute("errorMessage", errorMessage);
        return "forward:fahrzeuge";
    }

    if (changedFireEngine.getActive() == null) {
        changedFireEngine.setActive(false);
    }

    if (request.isUserInRole("ROLE_GLOBAL_ADMIN")) {
        FireEngineModel fireEngine = fireEngineRepository.findById(changedFireEngine.getId());

        if (fireEngine == null) {
            model.addAttribute("errorMessage", "Diese Fahrzeug kann nicht bearbeitet werden!");
        } else {
            fireEngine.setModel(changedFireEngine.getModel());
            fireEngine.setLicensePlate(changedFireEngine.getLicensePlate());
            fireEngine.setPerformance(changedFireEngine.getPerformance());
            fireEngine.setBuildYear(changedFireEngine.getBuildYear());
            fireEngine.setActive(changedFireEngine.getActive());
            fireEngine.setAbbreviation(changedFireEngine.getAbbreviation());
            fireEngine.setFireBrigade(changedFireEngine.getFireBrigade());
            fireEngineRepository.save(fireEngine);
            model.addAttribute("message", "Fahrzeug " + changedFireEngine.getModel() + " " + "wurde gendert.");
        }
        return "forward:fahrzeuge";

    } else {
        FireEngineModel fireEngine = fireEngineRepository.findByFireBrigadeAndId(getSessionFireBrigade(),
                changedFireEngine.getId());

        if (fireEngine == null) {
            model.addAttribute("errorMessage", "Dieses Fahrzeug kann nicht bearbeitet werden!");
            System.out.println("Falsches Fahrzeug!");
        } else {
            fireEngine.setModel(changedFireEngine.getModel());
            fireEngine.setLicensePlate(changedFireEngine.getLicensePlate());
            fireEngine.setPerformance(changedFireEngine.getPerformance());
            fireEngine.setBuildYear(changedFireEngine.getBuildYear());
            fireEngine.setActive(changedFireEngine.getActive());
            fireEngine.setAbbreviation(changedFireEngine.getAbbreviation());
            fireEngine.setFireBrigade(getSessionFireBrigade());
            fireEngineRepository.save(fireEngine);
            model.addAttribute("message", "Fahrzeug " + changedFireEngine.getModel() + " " + "wurde gendert.");
        }
        return "forward:fahrzeuge";
    }
}

From source file:at.fh.swenga.firefighters.controller.FireFighterController.java

@RequestMapping(value = "addFireEngine", method = RequestMethod.POST)
public String addFireEngine(@Valid @ModelAttribute FireEngineModel newFireEngine, BindingResult bindingResult,
        Model model, HttpServletRequest request) {
    System.out.println(newFireEngine);
    if (bindingResult.hasErrors()) {
        String errorMessage = "";
        for (FieldError fieldError : bindingResult.getFieldErrors()) {
            errorMessage = fieldError.getField() + " ist falsch";
        }/*ww  w  .j  a  v a2  s. com*/
        model.addAttribute("errorMessage", errorMessage);
        return "forward:fahrzeuge";
    }
    if (newFireEngine.getActive() == null) {
        newFireEngine.setActive(false);
    }

    if (!request.isUserInRole("ROLE_GLOBAL_ADMIN")) {
        newFireEngine.setFireBrigade(getSessionFireBrigade());
    }
    fireEngineRepository.save(newFireEngine);
    model.addAttribute("message", "Fahrzeug " + newFireEngine.getModel() + " hinzugefgt.");

    return "forward:fahrzeuge";
}

From source file:org.lamsfoundation.lams.admin.web.action.UserBasicListAction.java

public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {

    service = AdminServiceProxy.getService(getServlet().getServletContext());
    HttpSession session = SessionManager.getSession();
    if (session != null) {
        UserDTO userDto = (UserDTO) session.getAttribute(AttributeNames.USER);
        if (userDto != null) {
            // get inputs
            Integer userId = userDto.getUserID();
            Integer orgId = WebUtil.readIntParam(request, "orgId", true);
            String potential = WebUtil.readStrParam(request, "potential", true);
            if (orgId != null) {
                if (!StringUtils.equals(potential, "1")) {
                    // list users in org
                    List users = service.getUsersFromOrganisation(orgId);
                    request.setAttribute("users", users);
                } else {
                    // get all potential users of this org instead... filters results according to user's roles
                    // get group
                    Organisation org = (Organisation) service.findById(Organisation.class, orgId);
                    Organisation group;//ww w. j  av a2 s.c  o m
                    if (org != null) {
                        if (org.getOrganisationType().getOrganisationTypeId()
                                .equals(OrganisationType.CLASS_TYPE)) {
                            group = org.getParentOrganisation();
                        } else {
                            group = org;
                        }
                        // get users
                        List users = new ArrayList();
                        if (request.isUserInRole(Role.SYSADMIN) || service.isUserGlobalGroupAdmin()) {
                            users = service.getAllUsers(org.getOrganisationId());
                        } else if (service.isUserInRole(userId, group.getOrganisationId(), Role.GROUP_ADMIN)
                                || service.isUserInRole(userId, group.getOrganisationId(),
                                        Role.GROUP_MANAGER)) {
                            if (group.getCourseAdminCanBrowseAllUsers()) {
                                users = service.getAllUsers(org.getOrganisationId());
                            } else if (org.getOrganisationType().getOrganisationTypeId()
                                    .equals(OrganisationType.CLASS_TYPE)) {
                                users = service.getUsersFromOrganisation(group.getOrganisationId(), orgId);
                            }
                        }
                        request.setAttribute("users", users);
                    }
                }
            }
        }
    }

    return mapping.findForward("basiclist");
}

From source file:com.pkrete.locationservice.admin.controller.mvc.SubjectMatterController.java

@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST })
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws Exception, ServletException, IOException {
    /* Get the current user. */
    Owner owner = UsersUtil.getUser(request, usersService).getOwner();
    /* Model that is returned together with the view */
    Map<String, Object> model = new HashMap<String, Object>();
    /* Id of the selected  subject matter */
    String idSubject = request.getParameter("select_subject");

    if (request.getParameter("btn_add_subject") != null) {
        return new ModelAndView("redirect:addsubjectmatter.htm");
    } else if (request.getParameter("btn_edit_subject") != null && idSubject != null) {
        if (idSubject.matches("^[1-9]{1}[0-9]*$")) {
            return new ModelAndView("redirect:editsubjectmatter.htm?select_subject=" + idSubject);
        }//from   w  w w  . j av a2  s  . co  m
    } else if (request.getParameter("btn_delete_subject") != null && idSubject != null) {
        if (idSubject != null) {
            if (idSubject.matches("^[1-9]{1}[0-9]*$")) {
                SubjectMatter temp = subjectMattersService
                        .getSubjectMatterToBeDeleted(this.converterService.strToInt(idSubject), owner);
                if (temp.getLocations().isEmpty()) {
                    if (!subjectMattersService.delete(temp)) {
                        throw new Exception("Deleting subject matter failed.");
                    }
                    idSubject = null;
                } else {
                    model.put("errorMsg",
                            this.messageSource.getMessage("error.subjectmatter.delete", null, null));
                }
            }
        }
    }

    if (request.isUserInRole(UserGroup.ADMIN.toString())) {
        model.put("isAdmin", "");
    }
    /* Load list of all libraries from DB */
    model.put("subjects", subjectMattersService.getSubjectMattersWithLanguage(owner));

    return new ModelAndView("subjectmatter", "model", model);
}

From source file:org.openamf.AdvancedGateway.java

/**
 * Uses the setting in openamf-config.xml to gets the correct invoker,
 * enforce access control, and store state-beans in the request/session
 * /*from   ww w . ja v  a2  s  .  co  m*/
 * @see org.openamf.DefaultGateway#getServiceInvoker(org.openamf.AMFBody,
 *         javax.servlet.http.HttpServletRequest)
 */
protected ServiceInvoker getServiceInvoker(AMFBody requestBody, HttpServletRequest httpServletRequest)
        throws ServiceInvocationException {

    ServiceInvoker serviceInvoker = null;

    try {
        ServiceConfig serviceConfig = getServiceConfig(requestBody);

        if (serviceConfig == null) {
            throw new AccessDeniedException(
                    "could not find service configuration for '" + requestBody.getServiceName() + "'");
        }

        ServiceRequest request = new ServiceRequest(requestBody, serviceConfig);
        ServiceMethodConfig methodConfig = getMethodConfig(serviceConfig, request);
        // abort if no method config is found. This allows us to restrict
        // access to the service in the openamf configuration.
        if (methodConfig == null) {
            NoSuchMethodException e = new NoSuchMethodException(request.getRequestBody().toString());

            log.warn("Method config not found: " + request.getRequestBody().toString());
            throw e;
        }

        // store methodConfig for later use
        request.setServiceMethodConfig(methodConfig);

        // Check access permissions if there are any in the configuration
        Iterator constraints = methodConfig.getAccessConstraintConfigs();
        if (constraints.hasNext()) {
            boolean accessDenied = true;
            while (accessDenied && constraints.hasNext()) {
                ServiceMethodAccessConstraintConfig constraint = (ServiceMethodAccessConstraintConfig) constraints
                        .next();
                accessDenied = !httpServletRequest.isUserInRole(constraint.getRoleName());
            }
            if (accessDenied) {
                Principal user = httpServletRequest.getUserPrincipal();
                throw new AccessDeniedException((user == null ? "<anonymous user>" : user.getName()));
            }
        }

        addStateBeansToParams(httpServletRequest, request, methodConfig);

        serviceInvoker = ServiceInvoker.load(serviceConfig.getServiceInvokerConfig().getClassName(), request,
                httpServletRequest, getServletContext());

        serviceInvoker.prepare(request);

    } catch (Exception e) {
        throw new ServiceInvocationException(requestBody, e);
    }

    return serviceInvoker;
}

From source file:net.i2cat.csade.life2.backoffice.servlet.UserManagementService.java

/**
 * Funcin que se ejecuta cuando el servlet recibe los datos
 *///from w ww.j  a  v  a2s.  c om
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    ChangablePropertiesManager cpm = new ChangablePropertiesManager(this.getServletContext());
    String operation = request.getParameter("operation");
    PlatformUserManager pum = new PlatformUserManager();
    String data = "";
    if (operation != null && !"".equals(operation)) {
        if (operation.equals("savePicturePreference")) {
            String photo_hor = request.getParameter("photo_hor");
            cpm.saveProperty("photo_hor", photo_hor);

            data = "{ \"message\": \"preferences saved.\" }";
        }
        if (operation.equals("getPicturePreference")) {
            String photo_hor = cpm.getProperty("photo_hor");

            data = "{ \"photo_hor\": \"" + photo_hor + "\"}";
        }

        if (operation.equals("getPlatformUser")) {
            String login = request.getParameter("login");
            try {
                data = pum.getUser(login).toJSON().toString();
            } catch (RemoteException re) {
                data = "{ \"message\": \"Could not not retrieve user with login=" + login + " Reason:"
                        + re.getMessage() + ".\" }";
            } catch (ServiceException se) {
                data = "{ \"message\": \"Could not not retrieve user with login=" + login + " Reason:"
                        + se.getMessage() + ".\" }";
            }
        }
        if (operation.equals("delPlatformUser")) {
            String login = request.getParameter("login");
            try {
                if (!request.isUserInRole("admin"))
                    throw new ServiceException("You are not allowed to delete users");
                if (login != null && login.equals(request.getUserPrincipal().getName()))
                    throw new ServiceException("You cannot delete your own user");
                pum.deleteUser(login);
                data = "{ \"message\": \"User with login " + login + " deleted.\" }";
            } catch (RemoteException re) {
                data = "{ \"message\": \"Could not not delete user with login=" + login + " Reason:"
                        + re.getMessage() + ".\" }";
            } catch (ServiceException se) {
                data = "{ \"message\": \"Could not not delete user with login=" + login + " Reason:"
                        + se.getMessage() + ".\" }";
            }
        }
        if (operation.equals("savePlatformUser")) {
            FileItem uploadedFile = null;
            PlatformUser user = null;
            int res = 0;
            byte[] foto = null;
            try {
                if (!request.isUserInRole("admin"))
                    throw new ServiceException("You are not allowed to upadte users");
                user = new PlatformUser();
                user.setNew(false);
                ServletFileUpload sfu = new ServletFileUpload(new DiskFileItemFactory());
                sfu.setFileSizeMax(329000);
                sfu.setHeaderEncoding("UTF-8");
                @SuppressWarnings("unchecked")
                List<FileItem> items = sfu.parseRequest(request);

                for (FileItem item : items) {
                    if (item.isFormField()) {
                        if (item.getFieldName().equals("login"))
                            user.setLogin(item.getString());
                        if (item.getFieldName().equals("username"))
                            user.setLogin(item.getString());
                        if (item.getFieldName().equals("password")) {
                            user.setPass(item.getString());
                        }
                        if (item.getFieldName().equals("idUser")) {
                            if (item.getString() == null || "".equals(item.getString()))
                                user.setNew(true);
                        }
                        if (item.getFieldName().equals("name")) {
                            byte[] fnb = item.get();
                            String text = PasswordGenerator.utf8Decoder(fnb);
                            user.setName(text);
                        }
                        if (item.getFieldName().equals("email")) {
                            String mail = item.getString();
                            if (MailUtils.isValidEmail(mail))
                                user.setEmail(mail);
                            else
                                throw new ServiceException("El email del usuario es incorrecto");
                        }
                        if (item.getFieldName().equals("telephonenumber"))
                            user.setTelephonenumber(item.getString());
                        if (item.getFieldName().equals("role"))
                            user.setRole(Integer.parseInt(item.getString()));
                        if (item.getFieldName().equals("language"))
                            user.setLanguage(item.getString());
                        if (item.getFieldName().equals("notification_level"))
                            user.setNotification_level(item.getString());
                        if (item.getFieldName().equals("promoter_id"))
                            user.setPromoter_id(item.getString());
                        if (item.getFieldName().equals("user_average_mark"))
                            user.setUser_average_mark(item.getString());
                        if (item.getFieldName().equals("user_votes"))
                            user.setUser_votes(item.getString());
                        if (item.getFieldName().equals("latitude"))
                            user.setHome_area_lat(item.getString());
                        if (item.getFieldName().equals("longitude"))
                            user.setHome_area_lon(item.getString());
                        if (item.getFieldName().equals("enabled"))
                            user.setEnabled(item.getString().equals("0") ? 0 : 1);
                    } else {
                        uploadedFile = item;
                        String inputExtension = FilenameUtils
                                .getExtension(uploadedFile.getName().toLowerCase());
                        if ("jpg".equals(inputExtension) || "gif".equals(inputExtension)
                                || "png".equals(inputExtension)) {
                            InputStream filecontent = item.getInputStream();
                            foto = new byte[(int) uploadedFile.getSize()];
                            filecontent.read(foto, 0, (int) uploadedFile.getSize());

                        }
                        //else
                        //   throw new FileUploadException("Extension not supported. Only jpg,gif or png files are allowed");
                    }
                }
                res = pum.saveUser(user);
                if (foto != null) {
                    //String v=cpm.getProperty("photo_hor");
                    //byte[] resizedPhoto=ImageUtil.resizeImageAsJPG(foto, (v==null || "".equals(v)) ?200:Integer.parseInt(v));
                    pum.uploadFoto(user.getLogin(), foto);
                }
                data = "{ \"message\": \"User with login " + user.getLogin() + " (id=" + res + ") saved.\" }";
            } catch (RemoteException exc) {
                data = "{ \"message\": \"Could not not save user with login=" + user.getLogin() + " Reason:"
                        + exc.getMessage() + ".\" }";
            } catch (ServiceException exc) {
                data = "{ \"message\": \"Could not not save user with login=" + user.getLogin() + " Reason:"
                        + exc.getMessage() + ".\" }";
            } catch (FileUploadException exc) {
                data = "{ \"message\": \"User with login " + user.getLogin() + " (id=" + res
                        + ") saved, but there was a problem uploading picture:" + exc.getMessage() + "\" }";
            }
        }
        if (operation.equals("listPlatformUsers")) {
            JQueryDataTableParamModel param = DataTablesParamUtility.getParam(request);
            try {
                JSONObject jsonResponse = pum.getPlatformUsersJSON(param);
                data = jsonResponse.toString();

            } catch (RemoteException re) {
                data = "{ \"message\": \"Could not not retrieve platform user listing. Reason:"
                        + re.getMessage() + ".\" }";
            } catch (ServiceException se) {
                data = "{ \"message\": \"Could not not retrieve platform user listing.  Reason:"
                        + se.getMessage() + ".\" }";
            }
        }
    }
    response.setContentType("application/json;charset=UTF-8");
    //response.setContentType("application/json");
    response.getWriter().print(data);
    response.getWriter().close();
}