com.perimeterx.api.blockhandler.CaptchaBlockHandler Maven / Gradle / Ivy
package com.perimeterx.api.blockhandler;
import com.perimeterx.models.PXContext;
import com.perimeterx.models.exceptions.PXException;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import java.io.IOException;
/**
* Default captcha block handler which display captcha page on block
*
* Created by shikloshi on 07/07/2016.
*/
public class CaptchaBlockHandler implements BlockHandler {
@Override
public void handleBlocking(PXContext context, HttpServletResponseWrapper responseWrapper) throws PXException {
String page = this.getCaptchaHtml(context);
responseWrapper.setStatus(HttpServletResponse.SC_FORBIDDEN);
responseWrapper.setContentType("text/html");
try {
responseWrapper.getWriter().print(page);
} catch (IOException e) {
throw new PXException(e);
}
}
private String getCaptchaHtml(PXContext context) {
return "\n" +
"
\n" +
" \n" +
" \n" +
" Access to This Page Has Been Blocked \n" +
" \n" +
" " +
" \n" +
" \n" +
" \n" +
" \n" +
" Access to This Page Has Been Blocked \n" +
" \n" +
"
Access to '" + context.getFullUrl() + "' is blocked according to the site security policy.
Your browsing behaviour fingerprinting made us think you may be a bot.
This may happen as a result of the following: \n" +
" \n" +
" - JavaScript is disabled or not running properly.
\n" +
" - Your browsing behaviour fingerprinting are not likely to be a regular user.
\n" +
"
\n" +
" To read more about the bot defender solution: https://www.perimeterx.com/bot-defender
If you think the blocking was done by mistake, contact the site administrator.
\n" +
" \n" +
"
Block Reference: #' " + context.getUuid() + "' \n" +
" \n" +
" \n" +
"";
}
}