Author: thomas.heute(a)jboss.com
Date: 2010-04-07 04:40:10 -0400 (Wed, 07 Apr 2010)
New Revision: 2518
Added:
portal/branches/EPP_5_0_Branch/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
Modified:
portal/branches/EPP_5_0_Branch/component/web/pom.xml
portal/branches/EPP_5_0_Branch/packaging/module/src/main/javascript/portal.packaging.module.js
portal/branches/EPP_5_0_Branch/pom.xml
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/web.xml
portal/branches/EPP_5_0_Branch/webui/portal/pom.xml
Log:
JBEPP-229 Prevent flooding of user db by spambots
Modified: portal/branches/EPP_5_0_Branch/component/web/pom.xml
===================================================================
--- portal/branches/EPP_5_0_Branch/component/web/pom.xml 2010-04-07 08:24:02 UTC (rev
2517)
+++ portal/branches/EPP_5_0_Branch/component/web/pom.xml 2010-04-07 08:40:10 UTC (rev
2518)
@@ -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>
Copied:
portal/branches/EPP_5_0_Branch/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
(from rev 2422,
portal/trunk/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java)
===================================================================
---
portal/branches/EPP_5_0_Branch/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
(rev 0)
+++
portal/branches/EPP_5_0_Branch/component/web/src/main/java/org/exoplatform/web/security/CaptchaServlet.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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@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/branches/EPP_5_0_Branch/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
---
portal/branches/EPP_5_0_Branch/packaging/module/src/main/javascript/portal.packaging.module.js 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/packaging/module/src/main/javascript/portal.packaging.module.js 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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
@@ -176,8 +177,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/branches/EPP_5_0_Branch/pom.xml
===================================================================
--- portal/branches/EPP_5_0_Branch/pom.xml 2010-04-07 08:24:02 UTC (rev 2517)
+++ portal/branches/EPP_5_0_Branch/pom.xml 2010-04-07 08:40:10 UTC (rev 2518)
@@ -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>
@@ -669,8 +670,12 @@
<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>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
Copied:
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java
(from rev 2422,
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java)
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java
(rev 0)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterEditMode.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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@exoplatform.com">Truong
Le</a>
+ * @author <a href="mailto:theute@jboss.org">Thomas Heute</a>
+ * @version $Id$
+ *
+ */
+@ComponentConfig(lifecycle = UIFormLifecycle.class,
+ template = "system:/groovy/webui/form/UIFormWithTitle.gtmpl",
+ events = {@EventConfig(listeners =
UIRegisterEditMode.SaveActionListener.class)}
+ )
+@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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterForm.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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@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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterInputSet.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/UIRegisterPortlet.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -30,10 +30,11 @@
*
*/
-@ComponentConfig(lifecycle = UIApplicationLifecycle.class)
+@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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/ApplicationRegistryPortlet_nl.properties 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/classes/locale/portlet/exoadmin/RegisterPortlet_en.properties 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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>
Copied:
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl
(from rev 2422,
portal/trunk/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl)
===================================================================
---
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl
(rev 0)
+++
portal/branches/EPP_5_0_Branch/portlet/exoadmin/src/main/webapp/groovy/organization/webui/component/UIRegisterPortlet.gtmpl 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties
===================================================================
---
portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties 2010-04-07
08:24:02 UTC (rev 2517)
+++
portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/classes/locale/portal/webui_en.properties 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
--- portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/web.xml 2010-04-07
08:24:02 UTC (rev 2517)
+++ portal/branches/EPP_5_0_Branch/web/portal/src/main/webapp/WEB-INF/web.xml 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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/branches/EPP_5_0_Branch/webui/portal/pom.xml
===================================================================
--- portal/branches/EPP_5_0_Branch/webui/portal/pom.xml 2010-04-07 08:24:02 UTC (rev
2517)
+++ portal/branches/EPP_5_0_Branch/webui/portal/pom.xml 2010-04-07 08:40:10 UTC (rev
2518)
@@ -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>
Copied:
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
(from rev 2422,
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java)
===================================================================
---
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
(rev 0)
+++
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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@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));
+ }
+}
Copied:
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
(from rev 2422,
portal/trunk/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java)
===================================================================
---
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
(rev 0)
+++
portal/branches/EPP_5_0_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java 2010-04-07
08:40:10 UTC (rev 2518)
@@ -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@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);
+ }
+
+}