List of usage examples for javax.servlet.http HttpServletRequest getLocalAddr
public String getLocalAddr();
From source file:se.vgregion.portal.requestlogger.RequestLoggerController.java
private Map<String, String> getRequestInfo(PortletRequest request) { Map<String, String> requestResult = new TreeMap<String, String>(); HttpServletRequest httpRequest = PortalUtil.getHttpServletRequest(request); requestResult.put("RemoteUser", httpRequest.getRemoteUser()); requestResult.put("P3P.USER_LOGIN_ID", getRemoteUserId(request)); requestResult.put("RemoteAddr", httpRequest.getRemoteAddr()); requestResult.put("RemoteHost", httpRequest.getRemoteHost()); requestResult.put("RemotePort", String.valueOf(httpRequest.getRemotePort())); requestResult.put("AuthType", httpRequest.getAuthType()); requestResult.put("CharacterEncoding", httpRequest.getCharacterEncoding()); requestResult.put("ContentLength", String.valueOf(httpRequest.getContentLength())); requestResult.put("ContentType", httpRequest.getContentType()); requestResult.put("ContextPath", httpRequest.getContextPath()); requestResult.put("LocalAddr", httpRequest.getLocalAddr()); requestResult.put("Locale", httpRequest.getLocale().toString()); requestResult.put("LocalName", httpRequest.getLocalName()); requestResult.put("LocalPort", String.valueOf(httpRequest.getLocalPort())); requestResult.put("Method", httpRequest.getMethod()); requestResult.put("PathInfo", httpRequest.getPathInfo()); requestResult.put("PathTranslated", httpRequest.getPathTranslated()); requestResult.put("Protocol", httpRequest.getProtocol()); requestResult.put("QueryString", httpRequest.getQueryString()); requestResult.put("RequestedSessionId", httpRequest.getRequestedSessionId()); requestResult.put("RequestURI", httpRequest.getRequestURI()); requestResult.put("Scheme", httpRequest.getScheme()); requestResult.put("ServerName", httpRequest.getServerName()); requestResult.put("ServerPort", String.valueOf(httpRequest.getServerPort())); requestResult.put("ServletPath", httpRequest.getServletPath()); return requestResult; }
From source file:com.jd.survey.web.settings.SurveyDefinitionPageController.java
@RequestMapping(method = RequestMethod.PUT, produces = "text/html") public String update(@RequestParam(value = "_proceed", required = false) String proceed, @Valid SurveyDefinitionPage surveyDefinitionPage, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("update(): handles PUT"); try {/*from w w w . jav a 2s .c o m*/ User user = userService.user_findByLogin(principal.getName()); if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionPage.getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( surveyDefinitionPage.getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, surveyDefinitionPage, user); return "settings/surveyDefinitionPages/update"; } //validate VisibilityExpression boolean isValid = true; ParserContext ctx = new ParserContext(); ctx.setStrongTyping(true); ctx.addInput("surveyDefinition", SurveyDefinition.class); uiModel.asMap().clear(); surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_merge(surveyDefinitionPage); return "settings/surveyDefinitionPages/saved"; } else { return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( surveyDefinitionPage.getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionPageController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/fork", method = RequestMethod.POST, produces = "text/html") public String updateSkipAndBranckLogic(@RequestParam(value = "_proceed", required = false) String proceed, @Valid SurveyDefinitionPage surveyDefinitionPage, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {/*from ww w . jav a2s .c om*/ User user = userService.user_findByLogin(principal.getName()); if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionPage.getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( surveyDefinitionPage.getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { uiModel.asMap().clear(); surveySettingsService.surveyDefinitionPage_updateSkipAndBranckLogic(surveyDefinitionPage); return "settings/surveyDefinitionPages/saved"; } else { return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( surveyDefinitionPage.getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.QuestionColumnLabelController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", params = "form", produces = "text/html") public String updateForm(@PathVariable("id") Long questionId, Principal principal, HttpServletRequest httpServletRequest, Model uiModel) { log.info("updateForm(): questionId=" + questionId); try {/* ww w. j av a 2 s .c om*/ String login = principal.getName(); User user = userService.user_findByLogin(login); Question question = surveySettingsService.question_findById(questionId); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(question.getPage().getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( question.getPage().getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } SortedSet<QuestionColumnLabel> ColumnLabels = question.getColumnLabels(); log.info("initial set size" + ColumnLabels.size()); for (int i = 1; i <= EMPTY_OPTIONS_COUNT; i++) { log.info("adding to set" + i); ColumnLabels .add(new QuestionColumnLabel(question, (short) (question.getColumnLabels().size() + i))); } question.setColumnLabels(ColumnLabels); uiModel.addAttribute("question", question); return "settings/questionCols/update"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.SurveyDefinitionPageController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(@RequestParam(value = "_proceed", required = false) String proceed, @Valid SurveyDefinitionPage surveyDefinitionPage, BindingResult bindingResult, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {/* w ww. j a v a 2 s . c o m*/ User user = userService.user_findByLogin(principal.getName()); if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinitionPage.getSurveyDefinition().getId(), user) && !securityService.userBelongsToDepartment( surveyDefinitionPage.getSurveyDefinition().getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { if (bindingResult.hasErrors()) { populateEditForm(uiModel, surveyDefinitionPage, user); return "settings/surveyDefinitionPages/create"; } uiModel.asMap().clear(); surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_merge(surveyDefinitionPage); return "settings/surveyDefinitionPages/saved"; } else { return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( surveyDefinitionPage.getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:gr.forth.ics.isl.Index.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./* w w w . java2 s .co m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); String id = request.getParameter("id"); String sourceFile = request.getParameter("sourceFile"); // String sourceFilename = request.getParameter("sourceFilename"); String generator = request.getParameter("generator"); String uuidSize = request.getParameter("uuidSize"); String outputFormat = request.getParameter("output"); int uuidSizeInt = 2; if (uuidSize != null) { try { uuidSizeInt = Integer.parseInt(uuidSize); } catch (NumberFormatException ex) { } } Mapper map = new Mapper(); try { String serverIP = request.getLocalAddr(); if (serverIP.equals("0:0:0:0:0:0:0:1")) {//Localhost serverIP = "localhost"; } System.out.println("http://" + serverIP + ":" + request.getLocalPort() + "/3MEditor/Services?id=" + id + "&output=text/xml&method=export"); X3MLEngine engine = map.engine("http://" + serverIP + ":" + request.getLocalPort() + "/3MEditor/Services?id=" + id + "&output=text/xml&method=export"); X3MLEngine.Output output = engine.execute(map.documentFromString(sourceFile), map.policy(generator, uuidSizeInt)); if (X3MLEngine.exceptionMessagesList.length() > 0) { out.println(X3MLEngine.exceptionMessagesList .replaceAll("(?<!\\A)eu\\.delving\\.x3ml\\.X3MLEngine\\$X3MLException:", "\n$0")); } if (outputFormat == null || outputFormat.equals("RDF/XML")) { OutputStream os = new WriterOutputStream(out); PrintStream ps = new PrintStream(os); output.writeXML(ps); } else if (outputFormat.equals("N-triples")) { out.println(output.toString()); } else if (outputFormat.equals("Turtle")) { OutputStream os = new WriterOutputStream(out); PrintStream ps = new PrintStream(os); output.write(ps, "text/turtle"); } } catch (X3MLEngine.X3MLException ex) { ex.printStackTrace(out); } catch (Exception ex) { ex.printStackTrace(out); } out.close(); }
From source file:nl.b3p.kaartenbalie.service.servlet.GeneralServlet.java
private static boolean checkValidIpAddress(HttpServletRequest request, User user) { /* ip adressen van user die bij pcode hoort worden gechecked dit hoeven dus niet perse de ip adressen te zijn van de user waarmee nu wordt ingelogd, bijvoorbeeld via ldap of andere username dan die aan gebruikerscode is gekoppeld */ String remoteAddress = request.getRemoteAddr(); String forwardedFor = request.getHeader("X-Forwarded-For"); if (forwardedFor != null) { remoteAddress = forwardedFor;//from www. j a v a2 s.c om } String remoteAddressDesc = remoteAddress + (forwardedFor == null ? "" : " (proxy: " + request.getRemoteAddr() + ")"); /* remoteaddress controleren tegen ip adressen van user. * Ip ranges mogen ook via een asterisk */ for (String ipAddress : (Set<String>) user.getIps()) { log.debug("Controleren ip: " + ipAddress + " tegen: " + remoteAddressDesc); if (ipAddress.contains("*")) { if (isRemoteAddressWithinIpRange(ipAddress, remoteAddress)) { return true; } } if (ipAddress.equalsIgnoreCase(remoteAddress) || ipAddress.equalsIgnoreCase("0.0.0.0") || ipAddress.equalsIgnoreCase("::")) { return true; } } /* lokale verzoeken mogen ook */ String localAddress = request.getLocalAddr(); if (remoteAddress.equalsIgnoreCase(localAddress)) { log.debug("Toegang vanaf lokaal adres toegestaan: lokaal adres " + localAddress + ", remote adres: " + remoteAddressDesc); return true; } log.info("IP adres " + remoteAddressDesc + " niet toegestaan voor gebruiker " + user.getName()); return false; }
From source file:com.jd.survey.web.settings.QuestionOptionController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(method = RequestMethod.POST, produces = "text/html") public String createPost(Question question, BindingResult bindingResult, @RequestParam(value = "_proceed", required = false) String proceed, Principal principal, Model uiModel, HttpServletRequest httpServletRequest) { log.info("create(): handles " + RequestMethod.POST.toString()); try {//from w w w . ja v a 2 s . c o m log.info("-------------------------------------------------"); String login = principal.getName(); User user = userService.user_findByLogin(login); SurveyDefinition surveyDefinition = surveySettingsService.question_findById(question.getId()).getPage() .getSurveyDefinition(); if (!securityService.userIsAuthorizedToManageSurvey(surveyDefinition.getId(), user) && !securityService.userBelongsToDepartment(surveyDefinition.getDepartment().getId(), user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } if (proceed != null) { boolean hasNoOptions = true; boolean isValid = true; int i = 0; for (QuestionOption questionOption : question.getOptionsList2()) { //if the value or text is not null and not a blank string if ((questionOption.getValue() != null && questionOption.getText() != null) && (questionOption.getValue().trim().length() > 0 || questionOption.getText().trim().length() > 0)) { hasNoOptions = false; //validate the length if (questionOption.getValue().trim().length() == 0 || questionOption.getValue().trim().length() > 5) { bindingResult.rejectValue("optionsList2[" + i + "].value", "nullvalue"); isValid = false; } //validate the length if (questionOption.getText().trim().length() == 0 || questionOption.getText().trim().length() > 250) { bindingResult.rejectValue("optionsList2[" + i + "].text", "nullvalue"); isValid = false; } } i++; } if (hasNoOptions) { isValid = false; bindingResult.rejectValue("optionsList2[" + 0 + "].value", "nullValueEntered"); //re-populate the place holders for options for (int j = 1; j <= EMPTY_OPTIONS_COUNT; j++) { question.getOptions() .add(new QuestionOption(question, (short) (question.getOptions().size() + j))); } } if (!isValid) { return "settings/questionOptions/update"; } else { question = surveySettingsService.question_updateOptions(question); return "settings/questionOptions/saved"; } } //cancel button handler else { question = surveySettingsService.question_updateOptions(question); return "redirect:/settings/surveyDefinitions/" + encodeUrlPathSegment( question.getPage().getSurveyDefinition().getId().toString(), httpServletRequest); } } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }
From source file:com.jd.survey.web.settings.QuestionController.java
@Secured({ "ROLE_ADMIN", "ROLE_SURVEY_ADMIN" }) @RequestMapping(value = "/{id}", produces = "text/html") public String show(@PathVariable("id") Long id, HttpServletRequest httpServletRequest, Principal principal, Model uiModel) {//from w w w .j a va 2 s .com log.info("show(): id=" + id); try { String login = principal.getName(); User user = userService.user_findByLogin(login); //SurveyDefinitionPage surveyDefinitionPage = surveySettingsService.surveyDefinitionPage_findById(id); //Check if the user is authorized if (!securityService.userIsAuthorizedToManageSurvey(id, user)) { log.warn("Unauthorized access to url path " + httpServletRequest.getPathInfo() + " attempted by user login:" + principal.getName() + "from IP:" + httpServletRequest.getLocalAddr()); return "accessDenied"; } uiModel.addAttribute("question", surveySettingsService.question_findById(id)); uiModel.addAttribute("itemId", id); return "settings/questions/show"; } catch (Exception e) { log.error(e.getMessage(), e); throw (new RuntimeException(e)); } }