yamdrok/kaptcha

Kaptcha not working in OpenCMS, session.getattribute returns null

GoogleCodeExporter opened this issue · 5 comments

Below is the web.xml of opencms
<web-app>   

    <display-name>OpenCms</display-name>

    <description>
        OpenCms is an open source content management solution. 
        See details on http://www.opencms.org/
    </description>

    <servlet>
        <servlet-name>OpenCmsServlet</servlet-name>
        <description>
            The main servlet that handles all requests to the OpenCms VFS.  
        </description>
        <servlet-class>com.opencms.core.OpenCmsHttpServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>OpenCmsServlet</servlet-name>
        <url-pattern>/en/*</url-pattern>
    </servlet-mapping>

    <servlet>
        <servlet-name>Kaptcha</servlet-name>
        <servlet-class>com.google.code.kaptcha.servlet.KaptchaServlet</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>Kaptcha</servlet-name>
        <url-pattern>/kaptcha/Kaptcha.jpg</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>30</session-timeout>    <!-- 30 minutes -->
    </session-config>

    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
    </welcome-file-list>

    <taglib>
        <taglib-uri>http://www.opencms.org/taglib/cms</taglib-uri>
        <taglib-location>/WEB-INF/opencms.tld</taglib-location>
    </taglib>

<security-constraint>
   <web-resource-collection>
    <web-resource-name>Redirect http</web-resource-name>
        <url-pattern>/en/system/login/*</url-pattern>
   </web-resource-collection>
   <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
   </user-data-constraint>
</security-constraint>

</web-app>
JSP is exactly same as KaptchaExample.jsp

Using OpenCMS 5
kaptcha-2.3-jdk14.jar deployed in web-inf/lib
Running on j2sdk1.4.2_15

Image is showing up and randomly generating, session.getAttribute
constantly returning null.

Desperately needed help, thanks!

Original issue reported on code.google.com by henry.c...@gmail.com on 19 Nov 2008 at 9:09

Let's see your session.getAttribute code.

Also, this isn't a problem with Kaptcha, it is a problem with your code.

Original comment by latch...@gmail.com on 19 Nov 2008 at 4:40

  • Added labels: Type-Other
  • Removed labels: Type-Defect
Code is exactly as the same as KaptchaExample.jsp thats comes with the kaptcha 
bundle.

<%@ page session="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <%@ page language="java" contentType="text/html; charset=UTF-8" %>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Kaptcha Example</title>
    </head>
    <body>

        Enter in the <a href="http://code.google.com/p/kaptcha/">Kaptcha</a> to see if it
matches what is stored in the session attributes.

        <table>
            <tr>
                <td><img src="/kaptcha/Kaptcha.jpg"></td>
                <td valign="top">

                    <form method="POST">
                        <br>sec code:<input type="text" name="kaptchafield"><br />
                        <input type="submit" name="submit">
                    </form>
                </td>
            </tr>
        </table>    

        <br /><br /><br /><br />

        <%      
                        String id = request.getSession().getId();
            String c =
(String)session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_K
EY);
            String parm = (String) request.getParameter("kaptchafield");

            out.println("Parameter: " + parm + " ? Session Key: " + c + " : " + id);

            if (c != null && parm != null) {
                if (c.equals(parm)) {
                    out.println("true");
                } else {
                    out.println("false");
                }
            }
        %>

    </body>
</html>


Attached is a screen capture of the jsp.
Session.getAttribute(com.google.code.kaptcha.Constants.KAPTCHA_SESSION_KEY) 
keeps
returning a null value.

Thanks!

Original comment by henry.c...@gmail.com on 20 Nov 2008 at 1:47

Attachments:

What do you see in the tomcat server logs?

Regardless, if you can load up the .war file that comes with the bundle and 
that works for you, then that is all the 
help I have time to give you. You need to figure out how to do development on 
your own. Sorry.

Original comment by latch...@gmail.com on 20 Nov 2008 at 1:53

  • Changed state: Invalid
As I said on the first page of this project:

"Please note that if you are new to web programming, never used Java before or 
just generally clueless as to the 
workings of the internets, I'm probably not going to respond to your email. 
I've made it as easy as possible to 
integrate kaptcha with your project, however this really is a product for 
people who know what they are doing."

Original comment by latch...@gmail.com on 20 Nov 2008 at 1:54

Hi latchkey,

I found the exception thrown in the log.

2008-11-20 10:12:16 StandardWrapper[:jcaptcha]: Marking servlet jcaptcha as 
unavailable
2008-11-20 10:12:16 StandardContext[]: Servlet  threw load() exception
javax.servlet.ServletException: Wrapper cannot find servlet class 
ImageCaptchaServlet
or a class it depends on
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:891)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3427)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3628)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:821)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
    at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:307)
    at org.apache.catalina.core.StandardHost.install(StandardHost.java:788)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:400)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:718)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:358)
    at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.ja
va:166)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1196)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363)
    at org.apache.catalina.core.StandardService.start(StandardService.java:497)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:2190)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
    at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
    at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)
----- Root Cause -----
java.lang.ClassNotFoundException: ImageCaptchaServlet
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1443)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1289)
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:885)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:823)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:3427)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3628)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:821)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:807)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:595)
    at org.apache.catalina.core.StandardHostDeployer.install(StandardHostDeployer.java:307)
    at org.apache.catalina.core.StandardHost.install(StandardHost.java:788)
    at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:492)
    at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:400)
    at org.apache.catalina.startup.HostConfig.start(HostConfig.java:718)
    at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:358)
    at
org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.ja
va:166)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1196)
    at org.apache.catalina.core.StandardHost.start(StandardHost.java:754)
    at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1188)
    at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:363)
    at org.apache.catalina.core.StandardService.start(StandardService.java:497)
    at org.apache.catalina.core.StandardServer.start(StandardServer.java:2190)
    at org.apache.catalina.startup.Catalina.start(Catalina.java:512)
    at org.apache.catalina.startup.Catalina.execute(Catalina.java:400)
    at org.apache.catalina.startup.Catalina.process(Catalina.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:324)
    at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:203)

Sorry I have not touched java for almost 2 years and have forgetten a lot about 
it. I
have min knowledge on J2EE architecture too...Hope you won't mind... 

Original comment by henry.c...@gmail.com on 20 Nov 2008 at 2:20