Foros de discusión
Enabling Re- captcha
Naresh Reddy Kallamadi, modificado hace 7 años.
Enabling Re- captcha
Regular Member Mensajes: 120 Fecha de incorporación: 9/07/14 Mensajes recientes
Hi All,
I am trying to enable a recaptcha using steps given by Recaptcha enable url.
I got public and private keys from Google and given in control panel. Using below code to bring re captcha in jsp
<form class="form-register" id="<portlet:namespace/>regform" name="regform" method="post" action="<%=validateRegistrationForm%>" role="form">
<liferay-ui:captcha url="<%= captchaURL %>" /> {To render the re captcha}
<button type="submit" id="<portlet:namespace/>submit" >Submit</button>
</form>
Controller code:
@ResourceMapping
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException,
PortletException {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IN serveResource for getting Captcha image :");
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
} catch (Exception e) {
log.error("Exception occurred while getting the captcha image :: "
+ e.getMessage());
}
}
@ActionMapping
public void submitRegistration(ActionRequest request,
ActionResponse response) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IN action to check captcha :");
boolean captchaValidated = true;
try {
CaptchaUtil.check(request);
log.debug("Captcha validated successfully :: ");
} catch (Exception e) {
if (e instanceof CaptchaTextException
|| e instanceof CaptchaMaxChallengesException) {
log.debug("INVALID CAPTCHA :: ");
log.error("Exception occurred while checking tha captcha:: "
+ e.getMessage());
captchaValidated = false;
} else {
log.debug("VALID CAPTCHA");
}
}
}
When I click on the submit it will give below exception:
Can some one suggest me to move further.
16:13:18,285 ERROR [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'][ReCaptchaImpl:102] java.net.SocketTimeoutException: connect timed out
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.liferay.portal.util.HttpImpl$FastProtocolSocketFactory.createSocket(HttpImpl.java:1360)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1211)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:849)
at com.liferay.portal.util.HttpImpl.URLtoString(HttpImpl.java:876)
at com.liferay.portal.kernel.util.HttpUtil.URLtoString(HttpUtil.java:269)
at com.liferay.portal.captcha.recaptcha.ReCaptchaImpl.validateChallenge(ReCaptchaImpl.java:99)
at com.liferay.portal.captcha.recaptcha.ReCaptchaImpl.validateChallenge(ReCaptchaImpl.java:131)
at com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl.check(SimpleCaptchaImpl.java:86)
at com.liferay.portal.captcha.CaptchaImpl.check(CaptchaImpl.java:49)
As pr mine there might be security issue.
I am trying to enable a recaptcha using steps given by Recaptcha enable url.
I got public and private keys from Google and given in control panel. Using below code to bring re captcha in jsp
<form class="form-register" id="<portlet:namespace/>regform" name="regform" method="post" action="<%=validateRegistrationForm%>" role="form">
<liferay-ui:captcha url="<%= captchaURL %>" /> {To render the re captcha}
<button type="submit" id="<portlet:namespace/>submit" >Submit</button>
</form>
Controller code:
@ResourceMapping
public void serveResource(ResourceRequest resourceRequest,
ResourceResponse resourceResponse) throws IOException,
PortletException {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IN serveResource for getting Captcha image :");
try {
CaptchaUtil.serveImage(resourceRequest, resourceResponse);
} catch (Exception e) {
log.error("Exception occurred while getting the captcha image :: "
+ e.getMessage());
}
}
@ActionMapping
public void submitRegistration(ActionRequest request,
ActionResponse response) {
System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>IN action to check captcha :");
boolean captchaValidated = true;
try {
CaptchaUtil.check(request);
log.debug("Captcha validated successfully :: ");
} catch (Exception e) {
if (e instanceof CaptchaTextException
|| e instanceof CaptchaMaxChallengesException) {
log.debug("INVALID CAPTCHA :: ");
log.error("Exception occurred while checking tha captcha:: "
+ e.getMessage());
captchaValidated = false;
} else {
log.debug("VALID CAPTCHA");
}
}
}
When I click on the submit it will give below exception:
Can some one suggest me to move further.
16:13:18,285 ERROR [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'][ReCaptchaImpl:102] java.net.SocketTimeoutException: connect timed out
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at com.liferay.portal.util.HttpImpl$FastProtocolSocketFactory.createSocket(HttpImpl.java:1360)
at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager$HttpConnectionAdapter.open(MultiThreadedHttpConnectionManager.java:1361)
at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:1211)
at com.liferay.portal.util.HttpImpl.URLtoByteArray(HttpImpl.java:849)
at com.liferay.portal.util.HttpImpl.URLtoString(HttpImpl.java:876)
at com.liferay.portal.kernel.util.HttpUtil.URLtoString(HttpUtil.java:269)
at com.liferay.portal.captcha.recaptcha.ReCaptchaImpl.validateChallenge(ReCaptchaImpl.java:99)
at com.liferay.portal.captcha.recaptcha.ReCaptchaImpl.validateChallenge(ReCaptchaImpl.java:131)
at com.liferay.portal.captcha.simplecaptcha.SimpleCaptchaImpl.check(SimpleCaptchaImpl.java:86)
at com.liferay.portal.captcha.CaptchaImpl.check(CaptchaImpl.java:49)
As pr mine there might be security issue.
Soumyashree Mishra, modificado hace 7 años.
RE: Enabling Re- captcha
Junior Member Mensajes: 32 Fecha de incorporación: 18/04/16 Mensajes recientesNaresh Reddy Kallamadi:
16:13:18,285 ERROR [[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'][ReCaptchaImpl:102] java.net.SocketTimeoutException: connect timed out
java.net.SocketTimeoutException: connect timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
Hi Naresh,
When you submit the recaptcha for validation, liferay makes a call to google for verification. Refer below snippet from ReCaptchaImpl.java :
Http.Options options = new Http.Options();
try {
options.addPart(
"secret",
PrefsPropsUtil.getString(
PropsKeys.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE,
PropsValues.CAPTCHA_ENGINE_RECAPTCHA_KEY_PRIVATE));
}
catch (SystemException se) {
_log.error(se, se);
}
options.addPart("remoteip", request.getRemoteAddr());
options.addPart("response", reCaptchaResponse);
options.setLocation(PropsValues.CAPTCHA_ENGINE_RECAPTCHA_URL_VERIFY);
options.setPost(true);
I think you are not able to connect to the CAPTCHA_ENGINE_RECAPTCHA_URL_VERIFY url.
captcha.engine.recaptcha.url.verify=https://www.google.com/recaptcha/api/siteverify
Regards,
Soumya