本文整理汇总了Java中net.tanesha.recaptcha.ReCaptchaImpl类的典型用法代码示例。如果您正苦于以下问题:Java ReCaptchaImpl类的具体用法?Java ReCaptchaImpl怎么用?Java ReCaptchaImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReCaptchaImpl类属于net.tanesha.recaptcha包,在下文中一共展示了ReCaptchaImpl类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBindAndValidate
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
protected void onBindAndValidate(final HttpServletRequest request,
final Object command, final BindException errors) throws Exception {
// Validate the reCAPTCHA
String remoteAddr = request.getRemoteAddr();
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
// Probably don't want to hardcode your private key here but
// just to get it working is OK...
Domain domain = this.getDomain(request);
reCaptcha.setPrivateKey(domain.getConfiguration().get(
"recaptcha.private_key"));
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr,
request.getParameter("recaptcha_challenge_field"), request
.getParameter("recaptcha_response_field"));
if (!reCaptchaResponse.isValid()) {
FieldError fieldError = new FieldError("command", "captcha",
request.getParameter("recaptcha_response_field"), false,
new String[] { MessageCodes.Captcha.Error.BAD_CAPTCHA },
null, "Please try again.");
errors.addError(fieldError);
}
}
示例2: validateRecaptcha
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
public void validateRecaptcha(AuthenticationSubmission registration) {
String remoteAddr = registration.getRemoteAddr();
String challenge = registration.get(CHALLENGE);
String response = registration.get(RESPONSE);
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(recapthaPrivateKey);
ReCaptchaResponse reCaptchaResponse =
reCaptcha.checkAnswer(remoteAddr, challenge, response);
if (!reCaptchaResponse.isValid()) {
LOGGER.error(format("Failed recaptcha for remote addr %s with errror %s", registration.getRemoteAddr(),
reCaptchaResponse.getErrorMessage()));
throw new InvalidRequestException("Bad recaptcha");
}
}
示例3: submitNewCertRequestCreateCSR_KeysOnClient
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
/**
* Accepts a POSTed PKCS#10 CSR request that is provided by the client,
* performs validation and inserts a new row in the <tt>request</tt> table if valid.
* Using this method requires that the CSR and the public/private keys
* are created by the client rather than by the server.
*
* @param pin
* @param email
* @param csr
* @param recaptcha_challenge_field
* @param recaptcha_response_field
* @param request
* @return Either 'SUCCESS' or 'FAIL' which always comes at the start of the string
*
* @throws IOException
*/
@RequestMapping(value = "postCsr", method = RequestMethod.POST)
public @ResponseBody
String submitNewCertRequestCreateCSR_KeysOnClient(
@RequestParam String pin,
@RequestParam String email,
@RequestParam String csr,
@RequestParam String recaptcha_challenge_field,
@RequestParam String recaptcha_response_field,
HttpServletRequest request/*, ServletContext ctx*/)
throws IOException {
if(this.getUseRecaptcha()){
String key = this.mutableConfigParams.getProperty("recaptcha.private.key");
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(key);
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(
request.getRemoteAddr(), recaptcha_challenge_field, recaptcha_response_field);
if (!reCaptchaResponse.isValid()) {
return ("FAIL: reCAPTCHA invalid, please refresh reCAPTCHA and try again (the last reCAPTCHA is now invalid)");
}
}
ProcessCsrResult result = this.processCsrNewService.processNewUserCSR_Provided(
csr, email, pin);
return getReturnString(result, true);
}
示例4: validateCaptcha
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
/**
* @param request
* @param recatpchaPvtKey
* @return
*/
@RequestMapping("/verifyCaptcha.html")
public boolean validateCaptcha( HttpServletRequest request, String recaptchaPvtKey ) {
/*
// https://developers.google.com/recaptcha/docs/java
String remoteAddr = request.getRemoteAddr();
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey("your_private_key");
String challenge = request.getParameter("recaptcha_challenge_field");
String uresponse = request.getParameter("recaptcha_response_field");
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, challenge, uresponse);
if (reCaptchaResponse.isValid()) {
out.print("Answer was entered correctly!");
} else {
out.print("Answer is wrong");
}
*/
String rcChallenge = request.getParameter( "recaptcha_challenge_field" );
String rcResponse = request.getParameter( "recaptcha_response_field" );
String remoteAddr = request.getRemoteAddr();
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey( recaptchaPvtKey );
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer( remoteAddr, rcChallenge, rcResponse );
return reCaptchaResponse.isValid();
}
示例5: validateCaptcha
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
/**
* @param request
* @param recatpchaPvtKey
* @return
*/
@Override
public boolean validateCaptcha( HttpServletRequest request, String recatpchaPvtKey ) {
String rcChallenge = request.getParameter( "recaptcha_challenge_field" );
String rcResponse = request.getParameter( "recaptcha_response_field" );
String remoteAddr = request.getRemoteAddr();
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey( recatpchaPvtKey );
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer( remoteAddr, rcChallenge, rcResponse );
return reCaptchaResponse.isValid();
}
示例6: validateCaptcha
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
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();
}
示例7: preHandle
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
@Override public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
this.logger.info("ReCaptchaInterceptor.preHandle");
final ReCaptchaConsumer annotation = ReCaptchaInterceptor.getReCaptchaConsumerAnnotation(handler);
if (annotation != null) {
final String recaptchaResponse = request.getParameter(ReCaptchaUtils.RECAPTCHA_RESPONSE_FIELD);
final String recaptchaChallenge = request.getParameter(ReCaptchaUtils.RECAPTCHA_CHALLENGE_FIELD);
final String remoteAddr = request.getRemoteAddr();
final ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX");
final ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(remoteAddr, recaptchaChallenge, recaptchaResponse);
request.setAttribute(ReCaptchaUtils.RECAPTCHA_IS_VALID, reCaptchaResponse.isValid());
}
return true;
}
示例8: ReCaptchaService
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
public ReCaptchaService() {
reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(config.reCaptchaPrivateKey());
}
示例9: submitNewCertRequestCreateCSR_KeysOnServer
import net.tanesha.recaptcha.ReCaptchaImpl; //导入依赖的package包/类
/**
* Accepts POSTed CSR attributes needed to build a new PKCS#10 on the server,
* performs validation and inserts a new row in the <tt>request</tt> table if valid.
* Using this method requires that the CSR and the public/private keys
* are created server-side rather than by the client.
* <p/>
* If the request succeeds, 'SUCCESS' is returned appended with the
* PKCS#10 PEM string and the encrypted PKCS#8 private key PEM string.
* If the request fails, 'FAIL' is returned appended with an error message.
* Sample return String on success:
* <pre>
* SUCCESS: CSR submitted ok [1234]
*
* -----BEGIN CERTIFICATE REQUEST-----
* MIIC1zC.....blah......
* -----END CERTIFICATE REQUEST-----
*
* -----BEGIN ENCRYPTED PRIVATE KEY-----
* MIIE....blash......
* -----END ENCRYPTED PRIVATE KEY-----
* </pre>
*
* @param cn Common Name
* @param ra RA
* @param email
* @param pw Used to encrypt the private key
* @param pin Used to identify that the request belongs to the submitter
* @param recaptcha_challenge_field can be null/empty
* @param recaptcha_response_field can be null/empty
* @param request
* @param model
* @return Either 'SUCCESS' or 'FAIL' which always comes at the start of the string
* and append either the CSR/keys on success or an error message on fail.
*
* @throws IOException
*/
@RequestMapping(value = "postCsrAttributes", method = RequestMethod.POST)
public @ResponseBody
String submitNewCertRequestCreateCSR_KeysOnServer(
@RequestParam String cn,
@RequestParam String ra,
@RequestParam String email,
@RequestParam String pw,
@RequestParam String pin,
@RequestParam String recaptcha_challenge_field,
@RequestParam String recaptcha_response_field,
HttpServletRequest request,
//@Valid @ModelAttribute("newUserCertFormBean") NewUserCertFormBean newUserCertFormBean,
//BindingResult result,
/*RedirectAttributes redirectAttrs, */ Model model)
throws IOException {
//String cn = newUserCertFormBean.getName();
if(this.getUseRecaptcha()){
String key = this.mutableConfigParams.getProperty("recaptcha.private.key");
ReCaptchaImpl reCaptcha = new ReCaptchaImpl();
reCaptcha.setPrivateKey(key);
ReCaptchaResponse reCaptchaResponse = reCaptcha.checkAnswer(
request.getRemoteAddr(), recaptcha_challenge_field, recaptcha_response_field);
if (!reCaptchaResponse.isValid()) {
return ("FAIL: reCAPTCHA invalid, please refresh reCAPTCHA and try again (the last reCAPTCHA is now invalid)");
}
}
ProcessCsrNewService.CsrAttributes csrAttributes = new ProcessCsrNewService.CsrAttributes(pw, cn, ra);
ProcessCsrResult result = this.processCsrNewService.processNewUserCSR_CreateOnServer(
csrAttributes, email, pin);
return getReturnString(result, false);
}