I have figured out how to use kaptcha in a liferay portal

19 views
Skip to first unread message

Cygnet

unread,
Nov 1, 2008, 10:33:15 AM11/1/08
to kaptcha
I have figured out how to use Kaptcha in a portlet within a liferay
portal, and would be happy to post this to the wiki if given access.
The difficulty here is that portlets do not have easy access to the
portal's session attributes. I think that my solution will apply to
all jsr286 portal containers, but I have confirmed that it will work
for Liferay.

Please let me know if you would like this solution posted to the
wiki. I spent several hours figuring it out and I think it may be
beneficial to others. Glad to make it work though! :-) Well done on
this library!

jon stevens

unread,
Nov 1, 2008, 12:46:56 PM11/1/08
to kap...@googlegroups.com
Great thanks! Just send me a wiki document and I'll commit it. You can
checkout the existing svn wiki by going to this url:

http://code.google.com/p/kaptcha/source/checkout

and you want to svn co this tree:

svn co http://kaptcha.googlecode.com/svn/wiki/ wiki

svn add your document locally (don't commit since you only have
read-only access) and then do svn diff and send me the patch file.

thanks,

jon

--
My blog: http://lookfirst.com/

Cygnet

unread,
Nov 1, 2008, 10:14:07 PM11/1/08
to kaptcha
Actually, nevermind, I had made some changes in a different, unused
web.xml by accident, so the solution is much simpler than I had
thought it was... People wanting to do this must simply mark their
portlets:

<private-session-attributes>true</private-session-attributes>

in liferay-portlet.xml in order to get access to the portal session
attributes. Then, to access the attributes, the following code did
the trick:

FacesContext context = FacesContext.getCurrentInstance();
ExternalContext ext_context = context.getExternalContext();

PortletRequest req = (PortletRequest)
ext_context.getRequest();

HttpServletRequest request =
PortalUtil.getOriginalServletRequest(
PortalUtil.getHttpServletRequest(req));

String actualCaptchaValue =
(String)request.getSession().getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY);

if (actualCaptchaValue.equals(captchaValue))
logger.debug("Matched Captcha!!");
else
logger.debug("Failed to match captcha! :-( ");

Sorry for the confusion, it was much less involved than I realized,
but still a bit tricky in the portal context.

Mike


On Nov 1, 12:46 pm, "jon stevens" <latch...@gmail.com> wrote:
> Great thanks! Just send me a wiki document and I'll commit it. You can
> checkout the existing svn wiki by going to this url:
>
> http://code.google.com/p/kaptcha/source/checkout
>
> and you want to svn co this tree:
>
> svn cohttp://kaptcha.googlecode.com/svn/wiki/wiki
>
> svn add your document locally (don't commit since you only have
> read-only access) and then do svn diff and send me the patch file.
>
> thanks,
>
> jon
>
Reply all
Reply to author
Forward
0 new messages