[gatein-commits] gatein SVN: r2422 - in portal/trunk: component/web and 10 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Wed Mar 31 14:57:22 EDT 2010


Author: thomas.heute at jboss.com
Date: 2010-03-31 14:57:21 -0400 (Wed, 31 Mar 2010)
New Revision: 2422

Added:
   portal/trunk/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
   portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java
   portal/trunk/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl
   portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
   portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
Modified:
   portal/trunk/component/web/pom.xml
   portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
   portal/trunk/pom.xml
   portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
   portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
   portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
   portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties
   portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties
   portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
   portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
   portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml
   portal/trunk/webui/portal/pom.xml
Log:
GTNPORTAL-777: Prevent flooding of user db by spambots
Introducing a captcha mechanism


Modified: portal/trunk/component/web/pom.xml
===================================================================
--- portal/trunk/component/web/pom.xml	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/component/web/pom.xml	2010-03-31 18:57:21 UTC (rev 2422)
@@ -84,9 +84,13 @@
     	<artifactId>json</artifactId>
     	<type>jar</type>
     </dependency>
-     <dependency>
+    <dependency>
         <groupId>javax.security</groupId>
         <artifactId>jacc</artifactId>
+    </dependency>
+     <dependency>
+       <groupId>org.gatein.captcha</groupId>
+       <artifactId>simplecaptcha</artifactId>
      </dependency>
      <dependency>
        <groupId>org.exoplatform.portal</groupId>

Added: portal/trunk/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
===================================================================
--- portal/trunk/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java	                        (rev 0)
+++ portal/trunk/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -0,0 +1,88 @@
+/******************************************************************************
+ * JBoss by Red Hat                                                           *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.exoplatform.web.security;
+
+import static nl.captcha.Captcha.NAME;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import nl.captcha.Captcha;
+import nl.captcha.servlet.CaptchaServletUtil;
+
+/**
+ * @author <a href="mailto:theute at redhat.com">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class CaptchaServlet extends HttpServlet
+{
+
+   private static final long serialVersionUID = 1L;
+
+   private static final String PARAM_HEIGHT = "height";
+
+   private static final String PARAM_WIDTH = "width";
+
+   protected int _width = 200;
+
+   protected int _height = 50;
+
+   @Override
+   public void init() throws ServletException
+   {
+      if (getInitParameter(PARAM_HEIGHT) != null)
+      {
+         _height = Integer.valueOf(getInitParameter(PARAM_HEIGHT));
+      }
+
+      if (getInitParameter(PARAM_WIDTH) != null)
+      {
+         _width = Integer.valueOf(getInitParameter(PARAM_WIDTH));
+      }
+   }
+
+   @Override
+   public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
+   {
+      HttpSession session = req.getSession();
+      Captcha captcha;
+      if (session.getAttribute(NAME) == null)
+      {
+         captcha = new Captcha.Builder(_width, _height).addText().gimp().addNoise().addBackground().build();
+
+         session.setAttribute(NAME, captcha);
+         CaptchaServletUtil.writeImage(resp, captcha.getImage());
+
+         return;
+      }
+
+      captcha = (Captcha) session.getAttribute(NAME);
+      CaptchaServletUtil.writeImage(resp, captcha.getImage());
+   }
+
+}

Modified: portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
--- portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js	2010-03-31 18:57:21 UTC (rev 2422)
@@ -46,6 +46,7 @@
    var groovyVersion = "${org.codehaus.groovy.version}";
    var rhinoVersion = "${rhino.version}";
    var jcipVersion = "${jcip.version}";
+   var simplecapthaVersion = "${nl.captcha.simplecaptcha.version}";
 
    //TODO versions for gatein components
    
@@ -175,8 +176,11 @@
       addDependency(core.component.xmlProcessing).
       addDependency(core.component.documents).
 
-      addDependency(jcr.services.jcr);
+      addDependency(jcr.services.jcr).
+      addDependency(new Project("org.gatein.captcha", "simplecaptcha", "jar", simplecapthaVersion)).
+      addDependency(new Project("com.jhlabs", "filters", "jar", "2.0.235")); 
 
+
    module.portlet = {};
 
    module.portlet.exoadmin =

Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/pom.xml	2010-03-31 18:57:21 UTC (rev 2422)
@@ -43,6 +43,7 @@
       <org.exoplatform.jcr.version>1.12.0-GA</org.exoplatform.jcr.version>
       <org.jibx.version>1.2.1</org.jibx.version>
       <org.shindig.version>1.0-r790473-Patch02</org.shindig.version>
+      <nl.captcha.simplecaptcha.version>1.1.1-GA-Patch01</nl.captcha.simplecaptcha.version>
       <org.gatein.common.version>2.0.0-GA</org.gatein.common.version>
       <org.gatein.wci.version>2.0.0-GA</org.gatein.wci.version>
       <org.gatein.pc.version>2.1.0-GA</org.gatein.pc.version>
@@ -649,7 +650,11 @@
             <artifactId>shindig-social-api</artifactId>
             <version>${org.shindig.version}</version>
          </dependency>
-
+         <dependency>
+            <groupId>org.gatein.captcha</groupId>
+            <artifactId>simplecaptcha</artifactId>
+            <version>${nl.captcha.simplecaptcha.version}</version>
+         </dependency>
          <!-- needed for the IBM jdk, should be remove in the future when IBM fixes its jdk (see GTNPORTAL-636) --> 
          <dependency>
          	<groupId>net.jcip</groupId>

Added: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java	                        (rev 0)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -0,0 +1,80 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.account.webui.component;
+
+import org.exoplatform.portal.webui.util.Util;
+import org.exoplatform.portal.webui.workspace.UIPortalApplication;
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.portlet.PortletRequestContext;
+import org.exoplatform.commons.serialization.api.annotations.Serialized;
+import org.exoplatform.webui.config.annotation.ComponentConfig;
+import org.exoplatform.webui.config.annotation.EventConfig;
+import org.exoplatform.webui.core.lifecycle.UIFormLifecycle;
+import org.exoplatform.webui.event.Event;
+import org.exoplatform.webui.event.EventListener;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormCheckBoxInput;
+
+import javax.portlet.PortletMode;
+import javax.portlet.PortletPreferences;
+
+/**
+ * @author <a href="mailto:truong.le at exoplatform.com">Truong Le</a>
+ * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
+ * @version $Id$
+ *
+ */
+ at ComponentConfig(lifecycle = UIFormLifecycle.class, 
+                 template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl", 
+                 events = {@EventConfig(listeners = UIRegisterEditMode.SaveActionListener.class)}
+                )
+ at Serialized
+public class UIRegisterEditMode extends UIForm
+{
+   public static final String USE_CAPTCHA = "useCaptcha";
+   
+   public UIRegisterEditMode() throws Exception
+   {
+      PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
+      PortletPreferences pref = pcontext.getRequest().getPreferences();
+      boolean useCaptcha = Boolean.parseBoolean(pref.getValue(USE_CAPTCHA,"true"));
+      addUIFormInput(new UIFormCheckBoxInput<Boolean>(USE_CAPTCHA, USE_CAPTCHA, useCaptcha).setValue(useCaptcha));
+   }
+
+   static public class SaveActionListener extends EventListener<UIRegisterEditMode>
+   {
+
+      @Override
+      public void execute(Event<UIRegisterEditMode> event) throws Exception
+      {
+         // TODO Auto-generated method stub
+         UIRegisterEditMode uiForm = event.getSource();
+         boolean useCaptcha = uiForm.getUIFormCheckBoxInput(USE_CAPTCHA).isChecked();
+         PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
+         PortletPreferences pref = pcontext.getRequest().getPreferences();
+         pref.setValue(USE_CAPTCHA, Boolean.toString(useCaptcha));
+         pref.store();
+         UIPortalApplication portalApp = Util.getUIPortalApplication();
+         if (portalApp.getModeState() == UIPortalApplication.NORMAL_MODE)
+            pcontext.setApplicationMode(PortletMode.VIEW);
+         
+      }
+      
+   }
+}

Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -19,6 +19,10 @@
 
 package org.exoplatform.account.webui.component;
 
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.webui.CaptchaValidator;
+import org.exoplatform.portal.webui.UICaptcha;
+import org.exoplatform.portal.webui.util.Util;
 import org.exoplatform.services.organization.OrganizationService;
 import org.exoplatform.services.organization.UserHandler;
 import org.exoplatform.web.application.ApplicationMessage;
@@ -40,6 +44,11 @@
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+import nl.captcha.Captcha;
+
 /**
  * 
  * @author <a href="mailto:hoang281283 at gmail.com">Minh Hoang TO</a>
@@ -83,6 +92,12 @@
       @Override
       public void execute(Event<UIRegisterForm> event) throws Exception
       {
+         // Invalidate the captcha image
+         PortalRequestContext prContext = Util.getPortalRequestContext();
+         HttpServletRequest request = prContext.getRequest();
+         HttpSession session = request.getSession();
+         session.removeAttribute(Captcha.NAME);
+ 
          UIRegisterForm registerForm = event.getSource();
          OrganizationService orgService = registerForm.getApplicationComponent(OrganizationService.class);
          UserHandler userHandler = orgService.getUserHandler();

Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -18,11 +18,16 @@
  */
 package org.exoplatform.account.webui.component;
 
+import javax.portlet.PortletPreferences;
+
+import org.exoplatform.portal.webui.CaptchaValidator;
+import org.exoplatform.portal.webui.UICaptcha;
 import org.exoplatform.services.organization.Query;
 import org.exoplatform.services.organization.User;
 import org.exoplatform.services.organization.UserHandler;
 import org.exoplatform.web.application.ApplicationMessage;
 import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.application.portlet.PortletRequestContext;
 import org.exoplatform.webui.core.UIApplication;
 import org.exoplatform.webui.form.UIFormInputWithActions;
 import org.exoplatform.webui.form.UIFormStringInput;
@@ -51,7 +56,9 @@
    protected static String LAST_NAME = "lastName";
    
    protected static String EMAIL_ADDRESS = "emailAddress";
-   
+
+   protected static String CAPTCHA = "captcha";
+
    public UIRegisterInputSet(String name) throws Exception{
       super(name);
       
@@ -76,7 +83,16 @@
          "ResourceValidator.msg.Invalid-char"));
       
       addUIFormInput(new UIFormStringInput(EMAIL_ADDRESS, EMAIL_ADDRESS, null).addValidator(MandatoryValidator.class).addValidator(
-         EmailAddressValidator.class));      
+         EmailAddressValidator.class));
+   
+      PortletRequestContext pcontext = (PortletRequestContext)WebuiRequestContext.getCurrentInstance();
+      PortletPreferences pref = pcontext.getRequest().getPreferences();
+      boolean useCaptcha = Boolean.parseBoolean(pref.getValue(UIRegisterEditMode.USE_CAPTCHA,"true"));
+
+      if (useCaptcha)
+      {
+         addUIFormInput(new UICaptcha(CAPTCHA, CAPTCHA, null).addValidator(MandatoryValidator.class).addValidator(CaptchaValidator.class));
+      }
    }
    
    private String getUserName(){

Modified: portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -30,10 +30,11 @@
  *
  */
 
- at ComponentConfig(lifecycle = UIApplicationLifecycle.class)
+ at ComponentConfig(lifecycle = UIApplicationLifecycle.class, template = "app:/groovy/organization/webui/component/UIRegisterPortlet.gtmpl")
 public class UIRegisterPortlet extends UIPortletApplication {
 
 	public UIRegisterPortlet() throws Exception{
-		addChild(UIRegisterForm.class, null, null);
+        addChild(UIRegisterForm.class, null, null);
+        addChild(UIRegisterEditMode.class,null,null).setRendered(false);
 	}
 }

Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties	2010-03-31 18:57:21 UTC (rev 2422)
@@ -18,9 +18,9 @@
 #
 
 ##expression
-word.cancel=#{word.cancel}
-label.displayName=#{label.displayName}
-label.description=#{label.description}
+word.cancel=Annuleren
+label.displayName=Weergavenaam
+label.description=Beschrijving
 category.msg.changeNotExist=Kan de wijzigingen niet opslaan omdat de categorie niet meer bestaat.
 application.msg.changeNotExist=Kan de wijzigingen niet opslaan omdat de applicatie niet meer bestaat.
 gadget.msg.changeNotExist=Kan de wijzigingen niet opslaan omdat de gadget niet meer bestaat.

Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties	2010-03-31 18:57:21 UTC (rev 2422)
@@ -24,6 +24,10 @@
 UIRegisterForm.label.username=User Name:
 UIRegisterForm.label.password=Password:
 UIRegisterForm.label.confirmPassword=Confirm Password:
-UIRegisterForm.label.firstName= First Name:
-UIRegisterForm.label.lastName= Last Name:
-UIRegisterForm.label.emailAddress= Email Address:
\ No newline at end of file
+UIRegisterForm.label.firstName=First Name:
+UIRegisterForm.label.lastName=Last Name:
+UIRegisterForm.label.emailAddress=Email Address:
+UIRegisterForm.label.captcha=Text validation:
+
+UIRegisterEditMode.title=Register Portlet Preferences
+UIRegisterEditMode.label.useCaptcha=Use captcha:

Modified: portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml	2010-03-31 18:57:21 UTC (rev 2422)
@@ -95,7 +95,7 @@
       <expiration-cache>0</expiration-cache>
       <supports>
          <mime-type>text/html</mime-type>
-         <portlet-mode>help</portlet-mode>
+         <portlet-mode>edit</portlet-mode>
       </supports>
       <supported-locale>en</supported-locale>
 

Added: portal/trunk/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl
===================================================================
--- portal/trunk/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl	                        (rev 0)
+++ portal/trunk/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl	2010-03-31 18:57:21 UTC (rev 2422)
@@ -0,0 +1,20 @@
+<%	
+	import org.exoplatform.account.webui.component.UIRegisterEditMode;
+	import javax.portlet.PortletMode ;
+%>
+<%
+if(_ctx.getRequestContext().getApplicationMode() == PortletMode.VIEW)
+{
+  uicomponent.renderChildren();
+}
+else
+{
+  for (inputEntry in uicomponent.getChildren())
+  {
+    if (inputEntry instanceof UIRegisterEditMode)
+    {
+      uicomponent.renderUIComponent(inputEntry);	
+    }
+  }
+}
+%>

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties	2010-03-31 18:57:21 UTC (rev 2422)
@@ -55,7 +55,14 @@
   
 MandatoryValidatorIterator.msg.empty=The "{0}" list can not be empty.
 
+
   #############################################################################
+  #              Captcha Validator                                            #
+  #############################################################################
+
+CaptchaValidator.msg.Invalid-input=Text verification isn't correct
+
+  #############################################################################
   #              Number Format Validator                                      #
   #############################################################################
   #class org.exoplatform.webui.form.validator.Validator.NumberFormatValidator

Modified: portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/web/portal/src/main/webapp/WEB-INF/web.xml	2010-03-31 18:57:21 UTC (rev 2422)
@@ -213,6 +213,25 @@
     <load-on-startup>0</load-on-startup>
   </servlet>
 
+   <servlet>
+      <servlet-name>StickyCaptcha</servlet-name>
+      <servlet-class>org.exoplatform.web.security.CaptchaServlet</servlet-class>
+      <init-param>
+         <param-name>width</param-name>
+         <param-value>200</param-value>
+      </init-param>
+      <init-param>
+         <param-name>height</param-name>
+         <param-value>75</param-value>
+      </init-param>
+   </servlet>
+
+   <servlet-mapping>
+      <servlet-name>StickyCaptcha</servlet-name>
+      <url-pattern>/captcha</url-pattern>
+   </servlet-mapping>
+
+
 	<!--  =================================================================  --> 
 	<servlet-mapping>
 	  <servlet-name>InitiateLoginServlet</servlet-name> 

Modified: portal/trunk/webui/portal/pom.xml
===================================================================
--- portal/trunk/webui/portal/pom.xml	2010-03-31 17:18:27 UTC (rev 2421)
+++ portal/trunk/webui/portal/pom.xml	2010-03-31 18:57:21 UTC (rev 2422)
@@ -87,5 +87,10 @@
       <groupId>org.exoplatform.portal</groupId>
       <artifactId>exo.portal.gadgets-core</artifactId>
     </dependency>
+
+    <dependency>
+      <groupId>org.gatein.captcha</groupId>
+      <artifactId>simplecaptcha</artifactId>
+    </dependency>
   </dependencies>
 </project>

Added: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java	                        (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -0,0 +1,80 @@
+/**
+ * Copyright (C) 2009 eXo Platform SAS.
+ * 
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ * 
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ * 
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.exoplatform.portal.webui;
+
+import org.exoplatform.portal.application.PortalRequestContext;
+import org.exoplatform.portal.webui.util.Util;
+import org.exoplatform.web.application.ApplicationMessage;
+import org.exoplatform.webui.core.UIComponent;
+import org.exoplatform.webui.exception.MessageException;
+import org.exoplatform.webui.form.UIForm;
+import org.exoplatform.webui.form.UIFormInput;
+import org.exoplatform.webui.form.validator.Validator;
+
+import nl.captcha.Captcha;
+
+import java.io.Serializable;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * @author <a href="mailto:theute at redhat.com">Thomas Heute</a>
+ * Validator for Captcha content.
+ * Checks that the user input is equals to the content displayed by the
+ * distorted image.
+ */
+public class CaptchaValidator implements Validator, Serializable
+{
+
+   public void validate(UIFormInput uiInput) throws Exception
+   {
+      PortalRequestContext prContext = Util.getPortalRequestContext();
+      HttpServletRequest request = prContext.getRequest();
+      HttpSession session = request.getSession();
+
+      Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
+
+      if ((captcha != null) && (captcha.isCorrect((String) uiInput.getValue())))
+      {
+         return;
+      }
+
+      //modified by Pham Dinh Tan
+      UIComponent uiComponent = (UIComponent) uiInput;
+      UIForm uiForm = uiComponent.getAncestorOfType(UIForm.class);
+      String label;
+      try
+      {
+         label = uiForm.getLabel(uiInput.getName());
+      }
+      catch (Exception e)
+      {
+         label = uiInput.getName();
+      }
+      label = label.trim();
+      if (label.charAt(label.length() - 1) == ':')
+         label = label.substring(0, label.length() - 1);
+      Object[] args =
+      {label, uiInput.getBindingField()};
+      throw new MessageException(new ApplicationMessage("CaptchaValidator.msg.Invalid-input", args,
+            ApplicationMessage.WARNING));
+   }
+}

Added: portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
===================================================================
--- portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java	                        (rev 0)
+++ portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java	2010-03-31 18:57:21 UTC (rev 2422)
@@ -0,0 +1,46 @@
+/******************************************************************************
+ * JBoss by Red Hat                                                           *
+ * Copyright 2010, Red Hat Middleware, LLC, and individual                    *
+ * contributors as indicated by the @authors tag. See the                     *
+ * copyright.txt in the distribution for a full listing of                    *
+ * individual contributors.                                                   *
+ *                                                                            *
+ * This is free software; you can redistribute it and/or modify it            *
+ * under the terms of the GNU Lesser General Public License as                *
+ * published by the Free Software Foundation; either version 2.1 of           *
+ * the License, or (at your option) any later version.                        *
+ *                                                                            *
+ * This software is distributed in the hope that it will be useful,           *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU           *
+ * Lesser General Public License for more details.                            *
+ *                                                                            *
+ * You should have received a copy of the GNU Lesser General Public           *
+ * License along with this software; if not, write to the Free                *
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA         *
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.                   *
+ ******************************************************************************/
+package org.exoplatform.portal.webui;
+
+import org.exoplatform.webui.application.WebuiRequestContext;
+import org.exoplatform.webui.form.UIFormStringInput;
+
+/**
+ * @author <a href="mailto:theute at redhat.com">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class UICaptcha extends UIFormStringInput
+{
+
+   public UICaptcha(String name, String bindingExpression, String value)
+   {
+      super(name, bindingExpression, value);
+   }
+
+   public void processRender(WebuiRequestContext context) throws Exception
+   {
+      context.getWriter().write("<img src=\"" + context.getPortalContextPath() + "/captcha\" /><br/>");
+      super.processRender(context);
+   }
+
+}



More information about the gatein-commits mailing list