本文整理汇总了Java中net.tanesha.recaptcha.ReCaptchaFactory类的典型用法代码示例。如果您正苦于以下问题:Java ReCaptchaFactory类的具体用法?Java ReCaptchaFactory怎么用?Java ReCaptchaFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ReCaptchaFactory类属于net.tanesha.recaptcha包,在下文中一共展示了ReCaptchaFactory类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override
public String createHtml(HttpServletRequest request) {
if (captchaEnabled) {
if (StringUtils.isBlank(privateKey) || StringUtils.isBlank(publicKey)) {
return invalidConfigurationMessage;
}
boolean secure = request.isSecure();
ReCaptcha captcha;
if (secure) {
captcha = ReCaptchaFactory.newSecureReCaptcha(publicKey, privateKey, createNoScript);
} else {
captcha = ReCaptchaFactory.newReCaptcha(publicKey, privateKey, createNoScript);
}
return captcha.createRecaptchaHtml(null, null);
}
return "";
}
示例2: register
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override
public String register(ModelMap model, HttpSession session) {
model.addAttribute("openSourceLinks",
new OpenSourceLink[]{
new OpenSourceLink("View this page's jsp code.", "https://github.com/KevinWorkman/StaticVoidGames/blob/master/StaticVoidGames/src/main/webapp/WEB-INF/jsp/register.jsp"),
new OpenSourceLink("View this page's server code.", "https://github.com/KevinWorkman/StaticVoidGames/blob/master/StaticVoidGames/src/main/java/com/StaticVoidGames/spring/controller/StaticVoidGamesController.java")
}
);
String recaptchaPublicKey = env.getProperty("recaptcha.publicKey");
String recaptchaPrivateKey = env.getProperty("recaptcha.privateKey");
ReCaptcha c = ReCaptchaFactory.newReCaptcha(recaptchaPublicKey, recaptchaPrivateKey, false);
model.addAttribute("recaptchaHtml", c.createRecaptchaHtml(null, null));
return "register";
}
示例3: isCaptchaValid
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
private boolean isCaptchaValid(SignUpCredentials creds, SignUpValidationResult result_out, String remoteAddress)
{
String captchaChallenge = creds.getCaptchaChallenge();
String captchaResponse = creds.get(E_SignUpCredentialType.CAPTCHA_RESPONSE);
ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(m_publicRecaptchaKey, m_privateRecaptchaKey, false);
ReCaptchaResponse recaptchaResponse = captcha.checkAnswer(remoteAddress, captchaChallenge, captchaResponse);
if ( !recaptchaResponse.isValid())
{
result_out.setNoErrors(); // just make sure all errors are filled in for json writing...kinda hacky.
result_out.setError(E_SignUpCredentialType.CAPTCHA_RESPONSE, E_SignUpValidationError.CAPTCHA_INCORRECT);
return false;
}
return true;
}
示例4: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
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);
}
示例5: doGet
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
String cacheKey = "page-contact";
String output = null;
Cache cache = CacheSingleton.getInstance().getCache();
if (cache.containsKey(cacheKey)) {
output = (String) cache.get(cacheKey);
} else {
ConfigManager configManager = ConfigManager.getInstance();
ReCaptcha captcha = ReCaptchaFactory
.newReCaptcha(
configManager
.getValue(ConfigManager.RECAPTCHA_PUBLIC_KEY),
configManager
.getValue(ConfigManager.RECAPTCHA_PRIVATE_KEY),
false);
String captchaScript = captcha.createRecaptchaHtml(
req.getParameter("error"), null);
VelocityContext context = prepareContext(req);
context.put(
"pageTitle",
"Contact form and information"
+ configManager
.getValue(ConfigManager.WEBSITE_TITLE_SUFFIX));
context.put("htmlCaptcha", captchaScript);
output = generateTemplate("contact.vm", context);
cache.put(cacheKey, output);
}
writeResponse(output, resp);
}
示例6: isValid
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@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;
}
示例7: createCaptchaHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public String createCaptchaHtml() {
if (config.hasCaptchaKeys()) {
ReCaptcha reCaptcha = ReCaptchaFactory.newSecureReCaptcha(config.reCaptchaPublicKey(), config.reCaptchaPrivateKey(), false);
return reCaptcha.createRecaptchaHtml(null, null);
}
return "";
}
示例8: getReCaptchaHtml
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public String getReCaptchaHtml() {
if (!useReCaptcha()) {
return "";
}
ReCaptcha c = ReCaptchaFactory.newSecureReCaptcha(
properties.getRecaptchaPublic(), properties.getRecaptchaPrivate(), false);
return c.createRecaptchaHtml(null, null);
}
示例9: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
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);
}
示例10: buildCreateContext
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
/**
* Build the context for the create user mode.
*/
private String buildCreateContext(SessionState state, Context context)
{
// put the service in the context
context.put("service", userDirectoryService);
String blurb = (String) state.getAttribute(CONFIG_CREATE_BLURB);
if (!StringUtils.isEmpty(blurb))
{
context.put("createBlurb", blurb);
}
// is the type to be pre-set
context.put("type", state.getAttribute("create-type"));
boolean isValidatedWithAccountValidator = isValidatedWithAccountValidator(state);
boolean isEidEditable = isEidEditable(state);
// if the tool is configured to validate through email, we will use AccountValidator to set name fields, etc. So we indicate this in the context to hide fields that are redundant
context.put("isValidatedWithAccountValidator", isValidatedWithAccountValidator);
// If we're using account validator, an email needs to be sent
// If the eid is not editable, the email will be used as the eid
context.put("emailRequired", isValidatedWithAccountValidator || !isEidEditable);
// password is required when using Gateway New Account tool
// attribute "create-user" is true only for New Account tool
context.put("pwRequired", state.getAttribute("create-user"));
context.put("displayEid", isEidEditable);
String value = (String) state.getAttribute("valueEid");
if (value != null) context.put("valueEid", value);
value = (String) state.getAttribute("valueFirstName");
if (value != null) context.put("valueFirstName", value);
value = (String) state.getAttribute("valueLastName");
if (value != null) context.put("valueLastName", value);
value = (String) state.getAttribute("valueEmail");
if (value != null) context.put("valueEmail", value);
if ((Boolean)state.getAttribute("user.recaptcha-enabled"))
{
ReCaptcha captcha = ReCaptchaFactory.newReCaptcha((String)state.getAttribute("user.recaptcha-public-key"), (String)state.getAttribute("user.recaptcha-private-key"), false);
String captchaScript = captcha.createRecaptchaHtml((String)state.getAttribute("recaptcha-error"), null);
state.removeAttribute("recaptcha-error");
context.put("recaptchaScript", captchaScript);
}
return "_create";
}
示例11: doPost
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
String fromName = req.getParameter("fromName");
String fromEmail = req.getParameter("fromEmail");
String msgBody = req.getParameter("message");
String challengeParam = req.getParameter("recaptcha_challenge_field");
String responseParam = req.getParameter("recaptcha_response_field");
if (null == fromName || null == fromEmail || null == msgBody
|| null == challengeParam || null == responseParam) {
LOGGER.warning("Invalid/missing params");
sendErrorResponse(resp, HttpServletResponse.SC_NOT_FOUND);
return;
}
String remoteAddr = req.getRemoteAddr();
ConfigManager configManager = ConfigManager.getInstance();
ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(
configManager.getValue(ConfigManager.RECAPTCHA_PUBLIC_KEY),
configManager.getValue(ConfigManager.RECAPTCHA_PRIVATE_KEY),
false);
ReCaptchaResponse response = captcha.checkAnswer(remoteAddr,
challengeParam, responseParam);
if (!response.isValid()) {
resp.sendRedirect("/contact?error=" + response.getErrorMessage());
} else {
InternetAddress address = new InternetAddress(
configManager.getValue(ConfigManager.ADMINISTRATOR_EMAIL),
configManager.getValue(ConfigManager.ADMINISTRATOR_NAME));
try {
Message msg = new MimeMessage(session);
msg.setFrom(address);
msg.addRecipient(Message.RecipientType.TO, address);
msg.setSubject("Contact form");
String header = String.format("From: %s (%s)%n%n", fromName,
fromEmail);
msg.setText(header + msgBody);
Transport.send(msg);
} catch (Exception e) {
LOGGER.warning(e.getMessage());
sendErrorResponse(resp);
return;
}
}
resp.sendRedirect("/");
}
示例12: recover
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
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;
if (settingsService.getHttpsPort() != 0) {
captcha = ReCaptchaFactory.newSecureReCaptcha(
"6LcZ3OMSAAAAANkKMdFdaNopWu9iS03V-nLOuoiH",
"6LcZ3OMSAAAAAPaFg89mEzs-Ft0fIu7wxfKtkwmQ", false);
} else {
captcha = ReCaptchaFactory.newReCaptcha(
"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);
}
示例13: makeReCaptcha
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
public ReCaptcha makeReCaptcha(){
return ReCaptchaFactory.newReCaptcha(publicKey, privateKey, false);
}
示例14: getText
import net.tanesha.recaptcha.ReCaptchaFactory; //导入依赖的package包/类
@Override protected String getText(final Arguments arguments, final Element element, final String attributeName) {
final String recaptchaPublicKey = "6LceYuESAAAAAG-s2C1bzURTlpt6niMTMmnHTKuT";
final String recaptchaPrivateKey = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
final ReCaptcha captcha = ReCaptchaFactory.newReCaptcha(recaptchaPublicKey, recaptchaPrivateKey, false);
return captcha.createRecaptchaHtml(null, null);
}