List of usage examples for javax.servlet.http HttpServletRequest getRemoteUser
public String getRemoteUser();
null
if the user has not been authenticated. From source file:de.fhg.fokus.openride.services.rider.search.SearchService.java
@GET @Produces("text/json") public Response getSearches(@Context HttpServletRequest request) { List<RiderUndertakesRideEntity> activeRides = riderUndertakesRideControllerBean .getActiveRideRequests(request.getRemoteUser()); Search s;// ww w .j a v a2 s . co m ArrayList<Search> searches = new ArrayList<Search>(); //FIXME: either adapt the DB or the Search-Class for (RiderUndertakesRideEntity r : activeRides) { if (r != null) { s = new Search(r.getRiderrouteId() != null ? r.getRiderrouteId() : -1, r.getRideId() != null ? r.getRideId().getRideId() : -1, r.getStartpt() != null ? r.getStartpt().getX() : null, r.getStartpt() != null ? r.getStartpt().getY() : null, r.getEndpt() != null ? r.getEndpt().getX() : null, r.getEndpt() != null ? r.getEndpt().getY() : null, r.getStarttimeLatest() != null ? r.getStarttimeLatest().getTime() : null, StringEscapeUtils.escapeHtml(r.getComment()), Math.round((r.getStarttimeLatest().getTime() - r.getStarttimeEarliest().getTime()) / 1000 / 60), r.getNoPassengers(), false, r.getStarttimeEarliest() != null ? r.getStarttimeEarliest().getTime() : null, r.getPrice(), StringEscapeUtils.escapeHtml(r.getStartptAddress()), StringEscapeUtils.escapeHtml(r.getEndptAddress())); s.setUpdated(riderUndertakesRideControllerBean.isRideUpdated(r.getRiderrouteId())); searches.add(s); } } ArrayList list = new ArrayList(); list.add(new Search()); XStream x = Utils.getJasonXStreamer(list); Response response = Response.ok(x.toXML(searches)).build(); return response; }
From source file:de.fhg.fokus.openride.services.rider.search.SearchService.java
@GET @Produces("text/json") @Path("inactive") public Response getInactiveSearches(@Context HttpServletRequest request) { List<RiderUndertakesRideEntity> activeRides = riderUndertakesRideControllerBean .getInactiveRideRequests(request.getRemoteUser()); Search s;// ww w. j a v a 2 s . c om ArrayList<Search> searches = new ArrayList<Search>(); //FIXME: either adapt the DB or the Search-Class for (RiderUndertakesRideEntity r : activeRides) { if (r != null) { s = new Search(r.getRiderrouteId() != null ? r.getRiderrouteId() : -1, r.getRideId() != null ? r.getRideId().getRideId() : -1, r.getStartpt() != null ? r.getStartpt().getX() : null, r.getStartpt() != null ? r.getStartpt().getY() : null, r.getEndpt() != null ? r.getEndpt().getX() : null, r.getEndpt() != null ? r.getEndpt().getY() : null, r.getStarttimeLatest() != null ? r.getStarttimeLatest().getTime() : null, StringEscapeUtils.escapeHtml(r.getComment()), Math.round((r.getStarttimeLatest().getTime() - r.getStarttimeEarliest().getTime()) / 1000 / 60), r.getNoPassengers(), false, r.getStarttimeEarliest() != null ? r.getStarttimeEarliest().getTime() : null, r.getPrice(), StringEscapeUtils.escapeHtml(r.getStartptAddress()), StringEscapeUtils.escapeHtml(r.getEndptAddress())); s.setUpdated(riderUndertakesRideControllerBean.isRideUpdated(r.getRiderrouteId())); searches.add(s); } } ArrayList list = new ArrayList(); list.add(new Search()); XStream x = Utils.getJasonXStreamer(list); Response response = Response.ok(x.toXML(searches)).build(); return response; }
From source file:eu.europa.ec.fisheries.uvms.spatial.rest.resources.secured.AreaResource.java
@GET @Produces({ MediaType.APPLICATION_JSON }) @Path("/layers") @Interceptors(value = { ExceptionInterceptor.class }) public Response getSystemAreaLayerMapping(@Context HttpServletRequest request, @HeaderParam(AuthConstants.HTTP_HEADER_SCOPE_NAME) String scopeName, @HeaderParam(AuthConstants.HTTP_HEADER_ROLE_NAME) String roleName) throws ServiceException { final String username = request.getRemoteUser(); Collection<String> permittedLayersNames = ServiceLayerUtils.getUserPermittedLayersNames(usmService, username, roleName, scopeName); return createSuccessResponse(areaTypeService.listSystemAreaLayerMapping(permittedLayersNames)); }
From source file:eu.europa.ec.fisheries.uvms.spatial.rest.resources.secured.AreaResource.java
@GET @Produces({ MediaType.APPLICATION_JSON }) @Path("/locationlayers") @Interceptors(value = { ExceptionInterceptor.class }) public Response getSystemAreaAndLocationLayerMapping(@Context HttpServletRequest request, @HeaderParam(AuthConstants.HTTP_HEADER_SCOPE_NAME) String scopeName, @HeaderParam(AuthConstants.HTTP_HEADER_ROLE_NAME) String roleName) throws ServiceException { final String username = request.getRemoteUser(); Collection<String> permittedLayersNames = ServiceLayerUtils.getUserPermittedLayersNames(usmService, username, roleName, scopeName); return createSuccessResponse(areaTypeService.listSystemAreaAndLocationLayerMapping(permittedLayersNames)); }
From source file:com.ikon.servlet.admin.CssServlet.java
@Override @SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = WebUtils.getString(request, "action"); String userId = request.getRemoteUser(); updateSessionManager(request);//from w ww . jav a2s . c o m try { if (ServletFileUpload.isMultipartContent(request)) { FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Css css = new Css(); css.setActive(false); for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("action")) { action = item.getString("UTF-8"); } else if (item.getFieldName().equals("css_id")) { if (!item.getString("UTF-8").isEmpty()) { css.setId(new Long(item.getString("UTF-8")).longValue()); } } else if (item.getFieldName().equals("css_name")) { css.setName(item.getString("UTF-8")); } else if (item.getFieldName().equals("css_context")) { css.setContext(item.getString("UTF-8")); } else if (item.getFieldName().equals("css_content")) { css.setContent(item.getString("UTF-8")); } else if (item.getFieldName().equals("css_active")) { css.setActive(true); } } } if (action.equals("edit")) { CssDAO.getInstance().update(css); // Activity log UserActivity.log(userId, "ADMIN_CSS_UPDATE", String.valueOf(css.getId()), null, css.getName()); } else if (action.equals("delete")) { String name = WebUtils.getString(request, "css_name"); CssDAO.getInstance().delete(css.getId()); // Activity log UserActivity.log(userId, "ADMIN_CSS_DELETE", String.valueOf(css.getId()), null, name); } else if (action.equals("create")) { long id = CssDAO.getInstance().create(css); // Activity log UserActivity.log(userId, "ADMIN_CSS_CREATE", String.valueOf(id), null, css.getName()); } } list(userId, request, response); } catch (FileUploadException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }
From source file:org.kuali.rice.ken.web.spring.NotificationController.java
/** * This method takes an action on the message delivery - dismisses it with the action/cause that comes from the * UI layer//from ww w . j a v a2 s . c om * @param action the action or cause of the dismissal * @param message the message to display to the user * @param request the HttpServletRequest * @param response the HttpServletResponse * @return an appropriate ModelAndView */ private ModelAndView dismissMessage(String action, String message, HttpServletRequest request, HttpServletResponse response) { String view = "NotificationDetail"; String principalNm = request.getRemoteUser(); String messageDeliveryId = request .getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.MSG_DELIVERY_ID); String command = request.getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.COMMAND); String standaloneWindow = request .getParameter(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW); if (messageDeliveryId == null) { throw new RuntimeException("A null messageDeliveryId was provided."); } LOG.debug("messageDeliveryId: " + messageDeliveryId); LOG.debug("command: " + command); /** * We can get the notification object given a workflow ID or a notification * Id. This method might be called either from a workflow action list or * as a link from a message deliverer endpoint such as an email message. */ NotificationMessageDelivery delivery = messageDeliveryService .getNotificationMessageDelivery(Long.decode(messageDeliveryId)); if (delivery == null) { throw new RuntimeException("Could not find message delivery with id " + messageDeliveryId); } NotificationBo notification = delivery.getNotification(); /* * dismiss the message delivery */ Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(principalNm); notificationService.dismissNotificationMessageDelivery(delivery.getId(), principal.getPrincipalId(), action); List<NotificationSenderBo> senders = notification.getSenders(); List<NotificationRecipientBo> recipients = notification.getRecipients(); String contenthtml = Util.transformContent(notification); // first check to see if this is a standalone window, b/c if it is, we'll want to close if (standaloneWindow != null && standaloneWindow.equals("true")) { view = "NotificationActionTakenCloseWindow"; } else { // otherwise check to see if the details need to be rendered in line (no stuff around them) if (command != null && command.equals(NotificationConstants.NOTIFICATION_DETAIL_VIEWS.INLINE)) { view = "NotificationDetailInline"; } } Map<String, Object> model = new HashMap<String, Object>(); model.put("notification", notification); model.put("message", message); model.put("senders", senders); model.put("recipients", recipients); model.put("contenthtml", contenthtml); model.put("messageDeliveryId", messageDeliveryId); model.put("command", command); model.put(NotificationConstants.NOTIFICATION_CONTROLLER_CONSTANTS.STANDALONE_WINDOW, standaloneWindow); return new ModelAndView(view, model); }
From source file:org.opennms.web.controller.event.EventController.java
public ModelAndView createFavorite(HttpServletRequest request, HttpServletResponse response) throws Exception { String error = null;//from w w w . java2s . co m try { OnmsFilterFavorite favorite = favoriteService.createFavorite(request.getRemoteUser(), request.getParameter("favoriteName"), FilterUtil.toFilterURL(request.getParameterValues("filter")), OnmsFilterFavorite.Page.EVENT); if (favorite != null) { ModelAndView successView = list(request, favorite); // success //Comment out as per request //AlertTag.addAlertToRequest(successView, "Favorite was created successfully", AlertType.SUCCESS); return successView; } error = "An error occured while creating the favorite"; } catch (FilterFavoriteService.FilterFavoriteException ex) { error = ex.getMessage(); } ModelAndView errorView = list(request, (OnmsFilterFavorite) null); AlertTag.addAlertToRequest(errorView, error, AlertType.ERROR); return errorView; }
From source file:org.scigap.iucig.controller.ScienceDisciplineController.java
@ResponseBody @RequestMapping(value = "/updateScienceDiscipline", method = RequestMethod.POST) public void updateScienceDiscipline(@RequestBody ScienceDiscipline discipline, HttpServletRequest request) throws Exception { try {//from w ww . j a v a 2s. com String remoteUser; if (request != null) { remoteUser = request.getRemoteUser(); } else { throw new Exception("Remote user is null"); } int primarySubDisId = 0; int secondarySubDisId = 0; int tertiarySubDisId = 0; String urlParameters = "user=" + remoteUser; if (discipline != null) { Map<String, String> primarySubDisc = discipline.getPrimarySubDisc(); if (primarySubDisc != null && !primarySubDisc.isEmpty()) { for (String key : primarySubDisc.keySet()) { if (key.equals("id")) { primarySubDisId = Integer.valueOf(primarySubDisc.get(key)); urlParameters += "&discipline1=" + primarySubDisId; } } } else { Map<String, Object> primaryDiscipline = discipline.getPrimaryDisc(); if (primaryDiscipline != null && !primaryDiscipline.isEmpty()) { Object subdisciplines = primaryDiscipline.get("subdisciplines"); if (subdisciplines instanceof ArrayList) { for (int i = 0; i < ((ArrayList) subdisciplines).size(); i++) { Object disc = ((ArrayList) subdisciplines).get(i); if (disc instanceof HashMap) { if (((HashMap) disc).get("name").equals("Other / Unspecified")) { primarySubDisId = Integer.valueOf((((HashMap) disc).get("id")).toString()); } } } urlParameters += "&discipline1=" + primarySubDisId; } } } Map<String, String> secondarySubDisc = discipline.getSecondarySubDisc(); if (secondarySubDisc != null && !secondarySubDisc.isEmpty()) { for (String key : secondarySubDisc.keySet()) { if (key.equals("id")) { secondarySubDisId = Integer.valueOf(secondarySubDisc.get(key)); urlParameters += "&discipline2=" + secondarySubDisId; } } } else { Map<String, Object> secondaryDisc = discipline.getSecondaryDisc(); if (secondaryDisc != null && !secondaryDisc.isEmpty()) { Object subdisciplines = secondaryDisc.get("subdisciplines"); if (subdisciplines instanceof ArrayList) { for (int i = 0; i < ((ArrayList) subdisciplines).size(); i++) { Object disc = ((ArrayList) subdisciplines).get(i); if (disc instanceof HashMap) { if (((HashMap) disc).get("name").equals("Other / Unspecified")) { secondarySubDisId = Integer .valueOf((((HashMap) disc).get("id")).toString()); } } } urlParameters += "&discipline2=" + secondarySubDisId; } } } Map<String, String> tertiarySubDisc = discipline.getTertiarySubDisc(); if (tertiarySubDisc != null && !tertiarySubDisc.isEmpty()) { for (String key : tertiarySubDisc.keySet()) { if (key.equals("id")) { tertiarySubDisId = Integer.valueOf(tertiarySubDisc.get(key)); urlParameters += "&discipline3=" + tertiarySubDisId; } } } else { Map<String, Object> tertiaryDisc = discipline.getTertiaryDisc(); if (tertiaryDisc != null && !tertiaryDisc.isEmpty()) { Object subdisciplines = tertiaryDisc.get("subdisciplines"); if (subdisciplines instanceof ArrayList) { for (int i = 0; i < ((ArrayList) subdisciplines).size(); i++) { Object disc = ((ArrayList) subdisciplines).get(i); if (disc instanceof HashMap) { if (((HashMap) disc).get("name").equals("Other / Unspecified")) { tertiarySubDisId = Integer.valueOf((((HashMap) disc).get("id")).toString()); } } } urlParameters += "&discipline3=" + tertiarySubDisId; } } } URL obj = new URL(SCIENCE_DISCIPLINE_URL + "discipline/"); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); con.setDoInput(true); con.setDoOutput(true); con.setUseCaches(false); urlParameters += "&date=" + discipline.getDate() + "&source=cybergateway&commit=Update&cluster=" + discipline.getCluster(); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + SCIENCE_DISCIPLINE_URL); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.pkrete.locationservice.admin.controller.mvc.LocationController.java
@RequestMapping(method = { RequestMethod.GET, RequestMethod.POST }) public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception, ServletException, IOException { HttpSession session = request.getSession(); User user = (User) session.getAttribute("user"); if (user == null) { user = usersService.getUser(request.getRemoteUser()); session.setAttribute("user", user); }//w w w . j a v a2s. c o m /** * If user is administrator and index parameter is present in the URL, * recreate search index. */ if (request.isUserInRole(UserGroup.ADMIN.toString()) && request.getParameter("index") != null) { locationsService.recreateSearchIndex(); } /* Id of the selected library */ String idLibrary = request.getParameter("select_library"); /* Id of the selected collection */ String idCollection = request.getParameter("select_collection"); /* Id of the selected shelf */ String idShelf = request.getParameter("select_shelf"); if (idLibrary == null && idCollection != null) { int temp = this.locationsService.getLibraryId(idCollection); idLibrary = temp == 0 ? null : Integer.toString(temp); } if (idShelf != null) { if (idCollection == null) { int temp = this.locationsService.getCollectionId(idShelf); idCollection = temp == 0 ? null : Integer.toString(temp); } if (idLibrary == null) { int temp = this.locationsService.getLibraryId(idCollection); idLibrary = temp == 0 ? null : Integer.toString(temp); } } if (request.getParameter("btn_add_library") != null) { return new ModelAndView("redirect:addlibrary.htm"); } else if (request.getParameter("btn_edit_library") != null && idLibrary != null) { return new ModelAndView("redirect:editlibrary.htm?select_library=" + idLibrary); } else if (request.getParameter("btn_delete_library") != null && idLibrary != null) { if (idLibrary != null) { Library temp = locationsService.getLibraryToBeDeleted(this.converterService.strToInt(idLibrary), user.getOwner()); if (!locationsService.delete(temp)) { throw new Exception("Deleting library failed."); } idLibrary = null; idCollection = null; idShelf = null; } } else if (request.getParameter("btn_add_collection") != null && idLibrary != null) { return new ModelAndView("redirect:addcollection.htm?select_library=" + idLibrary); } else if (request.getParameter("btn_edit_collection") != null && idCollection != null) { return new ModelAndView("redirect:editcollection.htm?select_library=" + idLibrary + "&select_collection=" + idCollection); } else if (request.getParameter("btn_delete_collection") != null && idCollection != null) { if (idCollection != null) { LibraryCollection temp = locationsService .getCollectionToBeDeleted(this.converterService.strToInt(idCollection), user.getOwner()); if (!locationsService.delete(temp)) { throw new Exception("Deleting collection failed."); } idCollection = null; idShelf = null; } } else if (request.getParameter("btn_add_shelf") != null && idCollection != null) { return new ModelAndView( "redirect:addshelf.htm?select_library=" + idLibrary + "&select_collection=" + idCollection); } else if (request.getParameter("btn_edit_shelf") != null && idShelf != null) { return new ModelAndView("redirect:editshelf.htm?select_library=" + idLibrary + "&select_collection=" + idCollection + "&select_shelf=" + idShelf); } else if (request.getParameter("btn_delete_shelf") != null && idShelf != null) { if (idCollection != null) { Shelf temp = locationsService.getShelfToBeDeleted(this.converterService.strToInt(idShelf), user.getOwner()); if (!locationsService.delete(temp)) { throw new Exception("Deleting shelf failed."); } idShelf = null; } } /* Model that is returned together with the view */ Map<String, Object> model = new HashMap<String, Object>(); /* Load list of all the libraries that the user is allowed to see from DB */ List<SimpleLocation> libraries = locationsService.getlLibraries(user.getOwner()); List<SimpleLocation> collections = new ArrayList<SimpleLocation>(); List<SimpleLocation> shelves = new ArrayList<SimpleLocation>(); if (!libraries.isEmpty()) { /* If no library is selected, select the first library on the list */ if (idLibrary == null) { idLibrary = Integer.toString(libraries.get(0).getLocationId()); } /* Load the collections of the selected library */ collections = locationsService.getCollectionsByLibraryId(this.converterService.strToInt(idLibrary), user.getOwner()); if (!collections.isEmpty()) { /* If no collection is selected or selected library has changed, */ /* select the first collection on the list */ if (idCollection == null || request.getParameter("btn_list_library") != null) { idCollection = Integer.toString(collections.get(0).getLocationId()); } /* Load the shelves of the selected collection */ shelves = locationsService.getShelvesByCollectionId(this.converterService.strToInt(idCollection), user.getOwner()); } } model.put("owner", UsersUtil.getUser(request, usersService).getOwner().getCode()); model.put("libraries", libraries); model.put("collections", collections); model.put("shelves", shelves); model.put("libraryId", idLibrary); model.put("collectionId", idCollection); model.put("shelfId", idShelf); if (request.isUserInRole(UserGroup.ADMIN.toString())) { model.put("isAdmin", ""); } return new ModelAndView("location", "model", model); }
From source file:com.ikon.servlet.admin.ReportServlet.java
@SuppressWarnings("unchecked") public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { log.debug("doPost({}, {})", request, response); request.setCharacterEncoding("UTF-8"); String action = ""; String userId = request.getRemoteUser(); updateSessionManager(request);//from w w w. j a v a 2 s . com try { if (ServletFileUpload.isMultipartContent(request)) { InputStream is = null; FileItemFactory factory = new DiskFileItemFactory(); ServletFileUpload upload = new ServletFileUpload(factory); List<FileItem> items = upload.parseRequest(request); Report rp = new Report(); for (Iterator<FileItem> it = items.iterator(); it.hasNext();) { FileItem item = it.next(); if (item.isFormField()) { if (item.getFieldName().equals("action")) { action = item.getString("UTF-8"); } else if (item.getFieldName().equals("rp_id")) { rp.setId(Integer.parseInt(item.getString("UTF-8"))); } else if (item.getFieldName().equals("rp_name")) { rp.setName(item.getString("UTF-8")); } else if (item.getFieldName().equals("rp_active")) { rp.setActive(true); } } else { is = item.getInputStream(); rp.setFileName(FilenameUtils.getName(item.getName())); rp.setFileMime(MimeTypeConfig.mimeTypes.getContentType(item.getName())); rp.setFileContent(SecureStore.b64Encode(IOUtils.toByteArray(is))); is.close(); } } if (action.equals("create")) { long id = ReportDAO.create(rp); // Activity log UserActivity.log(userId, "ADMIN_REPORT_CREATE", Long.toString(id), null, rp.toString()); list(userId, request, response); } else if (action.equals("edit")) { Report tmp = ReportDAO.findByPk(rp.getId()); tmp.setActive(rp.isActive()); tmp.setFileContent(rp.getFileContent()); tmp.setFileMime(rp.getFileMime()); tmp.setFileName(rp.getFileName()); tmp.setName(rp.getName()); ReportDAO.update(tmp); // Activity log UserActivity.log(userId, "ADMIN_REPORT_EDIT", Long.toString(rp.getId()), null, rp.toString()); list(userId, request, response); } else if (action.equals("delete")) { ReportDAO.delete(rp.getId()); // Activity log UserActivity.log(userId, "ADMIN_REPORT_DELETE", Long.toString(rp.getId()), null, null); list(userId, request, response); } } } catch (DatabaseException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } catch (FileUploadException e) { log.error(e.getMessage(), e); sendErrorRedirect(request, response, e); } }