net.tanesha.recaptcha.ReCaptchaResponse Java Examples
The following examples show how to use
net.tanesha.recaptcha.ReCaptchaResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserNewMessageAction.java From entando-components with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void validate() { Message message = this.getMessage(); if (message == null) { return; } super.validate(); if (this.getRecaptchaEnabled()) { String remoteAddr = ServletActionContext.getRequest().getRemoteAddr(); ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); String privateKey = this.getConfigManager().getParam(JpwebdynamicformSystemConstants.RECAPTCHA_PRIVATEKEY_PARAM_NAME); reCaptcha.setPrivateKey(privateKey); ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, this.getRecaptcha_challenge_field(), this.getRecaptcha_response_field()); if (!reCaptchaResponse.isValid()) { this.addFieldError("recaptcha_response_field", this.getText("Errors.webdynamicform.captcha.notValid")); } } }
Example #2
Source File: TopicFormController.java From Spring-MVC-Blueprints with MIT License | 5 votes |
@RequestMapping(value = "/cfs/topic_process_add", method = RequestMethod.POST) public RedirectView submitForAdd( @ModelAttribute("topicForm") @Validated TopicForm topicForm, HttpServletRequest request, BindingResult result, Model model, final RedirectAttributes redirectAttributes, @RequestParam("recaptcha_challenge_field") String challangeField, @RequestParam("recaptcha_response_field") String responseField) { RedirectView redirectView = new RedirectView(); redirectView.setContextRelative(true); redirectView.setUrl("/cfs/topics.html"); if (result.hasErrors()) { redirectView.setUrl("/cfs/topics.html"); } else { redirectAttributes.addFlashAttribute("css", "success"); String remoteAddress = request.getRemoteAddr(); ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer( remoteAddress, challangeField, responseField); if (reCaptchaResponse.isValid()) { redirectAttributes.addFlashAttribute("msg", "New topic added successfully!"); topicService.addTopic(topicForm); redirectView.setUrl("/cfs/topics.html"); } else { redirectView.setUrl("/cfs/topics_add.html"); } } return redirectView; }
Example #3
Source File: ContactController.java From podcastpedia-web with MIT License | 5 votes |
@RequestMapping(method=RequestMethod.POST) public String processContactForm( @ModelAttribute("contactForm") ContactForm contactForm, BindingResult result, Model model, @RequestParam("recaptcha_challenge_field") String challangeField, @RequestParam("recaptcha_response_field") String responseField, ServletRequest servletRequest, SessionStatus sessionStatus ){ LOG.debug("------ processContactForm : form is being validated and processed -----"); contactFormValidator.validate(contactForm, result); String remoteAddress = servletRequest.getRemoteAddr(); ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer( remoteAddress, challangeField, responseField); if(!result.hasErrors() && reCaptchaResponse.isValid()){ contactService.sendContactMessage(contactForm); emailNotificationService.sendContactNotification(contactForm); sessionStatus.setComplete(); return "redirect:/contact?tks=true"; } else { List<String> topics = Utilities.getDisplayValues(ContactTopicType.class); model.addAttribute("topics", topics); model.addAttribute("contactForm", contactForm); if (!reCaptchaResponse.isValid()) { result.rejectValue("invalidRecaptcha", "invalid.captcha"); model.addAttribute("invalidRecaptcha", true); } return "contact_form_def"; } }
Example #4
Source File: SuggestPodcastController.java From podcastpedia-web with MIT License | 5 votes |
/** * * @param addPodcastFormData * @param result * @param model * @param servletRequest * @return */ @RequestMapping(method = RequestMethod.POST) public String processAddPodcastForm( @ModelAttribute("addPodcastForm") SuggestedPodcast addPodcastFormData, BindingResult result, Model model, @RequestParam("recaptcha_challenge_field") String challangeField, @RequestParam("recaptcha_response_field") String responseField, ServletRequest servletRequest, SessionStatus sessionStatus) { LOG.debug("------ processAddPodcastForm : form is being validated and processed -----"); suggestPodcastValidator.validate(addPodcastFormData, result); String remoteAddress = servletRequest.getRemoteAddr(); ReCaptchaResponse reCaptchaResponse = this.reCaptcha.checkAnswer( remoteAddress, challangeField, responseField); if (reCaptchaResponse.isValid() && !result.hasErrors()) { userInteractionService.addSuggestedPodcast(addPodcastFormData); emailNotificationService .sendSuggestPodcastNotification(addPodcastFormData); sessionStatus.setComplete(); return "redirect:/how_can_i_help/add_podcast?tks=true"; } else { model.addAttribute("addPodcastForm", addPodcastFormData); if (!reCaptchaResponse.isValid()) { result.rejectValue("invalidRecaptcha", "invalid.captcha"); model.addAttribute("invalidRecaptcha", true); } return "add_podcast_form_def"; } }
Example #5
Source File: CaptchaAction.java From entando-components with GNU Lesser General Public License v3.0 | 5 votes |
@Override public void validate() { if (this.getRecaptchaAfterEnabled()) { String remoteAddr = ServletActionContext.getRequest().getRemoteAddr(); ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); String privateKey = this.getConfigManager().getParam(JpwebdynamicformSystemConstants.RECAPTCHA_PRIVATEKEY_PARAM_NAME); reCaptcha.setPrivateKey(privateKey); ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, this.getRecaptcha_challenge_field(), this.getRecaptcha_response_field()); if (!reCaptchaResponse.isValid()) { this.addFieldError("recaptcha_response_field", this.getText("Errors.webdynamicform.captcha.notValid")); } } }
Example #6
Source File: ReCaptchaService.java From attic-rave with Apache License 2.0 | 5 votes |
@Override public boolean isValid(HttpServletRequest request) { log.debug("ReCaptcha enabled: {}", captchaEnabled); if (!captchaEnabled) { return true; } if (StringUtils.isBlank(privateKey) || StringUtils.isBlank(publicKey)) { log.error("ReCaptcha service is enabled, however, private or public keys are not defined."); return true; } boolean secure = request.isSecure(); ReCaptcha captcha; if (secure) { captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript); } else { captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript); } String response = request.getParameter(PARAM_CAPTCHA_RESPONSE); String challenge = request.getParameter(PARAM_CAPTCHA_CHALLENGE); String remoteAddress = request.getRemoteAddr(); // validate: ReCaptchaResponse captchaResponse = captcha.checkAnswer(remoteAddress, challenge, response); boolean valid = captchaResponse.isValid(); if (valid) { return true; } log.warn("Invalid captcha response: {}", captchaResponse.getErrorMessage()); return false; }
Example #7
Source File: RecaptchaAction.java From wandora with GNU General Public License v3.0 | 5 votes |
public boolean validateCaptcha(HttpServletRequest request){ String remoteAddr = request.getRemoteAddr(); ReCaptchaImpl reCaptcha = new ReCaptchaImpl(); reCaptcha.setPrivateKey(privateKey); String challenge = request.getParameter("recaptcha_challenge_field"); String uresponse = request.getParameter("recaptcha_response_field"); ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse); return reCaptchaResponse.isValid(); }
Example #8
Source File: MultiController.java From subsonic with GNU General Public License v3.0 | 4 votes |
public ModelAndView recover(HttpServletRequest request, HttpServletResponse response) throws Exception { Map<String, Object> map = new HashMap<String, Object>(); String usernameOrEmail = StringUtils.trimToNull(request.getParameter("usernameOrEmail")); ReCaptcha captcha = ReCaptchaFactory.newSecureReCaptcha("6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH", "6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false); boolean showCaptcha = true; if (usernameOrEmail != null) { map.put("usernameOrEmail", usernameOrEmail); User user = getUserByUsernameOrEmail(usernameOrEmail); String challenge = request.getParameter("recaptcha_challenge_field"); String uresponse = request.getParameter("recaptcha_response_field"); ReCaptchaResponse captchaResponse = captcha.checkAnswer(request.getRemoteAddr(), challenge, uresponse); if (!captchaResponse.isValid()) { map.put("error", "recover.error.invalidcaptcha"); } else if (user == null) { map.put("error", "recover.error.usernotfound"); } else if (user.getEmail() == null) { map.put("error", "recover.error.noemail"); } else { String password = RandomStringUtils.randomAlphanumeric(8); if (emailPassword(password, user.getUsername(), user.getEmail())) { map.put("sentTo", user.getEmail()); user.setLdapAuthenticated(false); user.setPassword(password); securityService.updateUser(user); showCaptcha = false; } else { map.put("error", "recover.error.sendfailed"); } } } if (showCaptcha) { map.put("captcha", captcha.createRecaptchaHtml(null, null)); } return new ModelAndView("recover", "model", map); }