Author: thomas.heute(a)jboss.com
Date: 2010-10-05 04:51:19 -0400 (Tue, 05 Oct 2010)
New Revision: 4497
Added:
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java
Removed:
epp/portal/branches/EPP_5_1_Branch/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
Modified:
epp/portal/branches/EPP_5_1_Branch/examples/portal/war/src/main/webapp/WEB-INF/web.xml
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/web.xml
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
Log:
JBEPP-529: Implement Captcha image as a portlet resource serving
Deleted:
epp/portal/branches/EPP_5_1_Branch/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java 2010-10-05
08:51:19 UTC (rev 4497)
@@ -1,88 +0,0 @@
-/******************************************************************************
- * 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:
epp/portal/branches/EPP_5_1_Branch/examples/portal/war/src/main/webapp/WEB-INF/web.xml
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/examples/portal/war/src/main/webapp/WEB-INF/web.xml 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/examples/portal/war/src/main/webapp/WEB-INF/web.xml 2010-10-05
08:51:19 UTC (rev 4497)
@@ -186,24 +186,6 @@
<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>
Copied:
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java
(from rev 4412,
portal/trunk/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java)
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java
(rev 0)
+++
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/java/org/exoplatform/account/webui/component/RegisterPortletApplicationController.java 2010-10-05
08:51:19 UTC (rev 4497)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (C) 2010 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 nl.captcha.Captcha;
+import nl.captcha.servlet.CaptchaServletUtil;
+import org.exoplatform.webui.application.portlet.PortletApplicationController;
+
+import javax.portlet.PortletException;
+import javax.portlet.PortletSession;
+import javax.portlet.ResourceRequest;
+import javax.portlet.ResourceResponse;
+import javax.portlet.ResourceServingPortlet;
+import java.awt.image.BufferedImage;
+import java.io.IOException;
+
+import static nl.captcha.Captcha.NAME;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class RegisterPortletApplicationController extends PortletApplicationController
implements ResourceServingPortlet
+{
+
+ 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 PortletException
+ {
+ if (getInitParameter(PARAM_HEIGHT) != null)
+ {
+ _height = Integer.valueOf(getInitParameter(PARAM_HEIGHT));
+ }
+
+ if (getInitParameter(PARAM_WIDTH) != null)
+ {
+ _width = Integer.valueOf(getInitParameter(PARAM_WIDTH));
+ }
+ }
+
+ public void serveResource(ResourceRequest req, ResourceResponse resp)
+ throws PortletException, java.io.IOException
+ {
+ PortletSession session = req.getPortletSession();
+ Captcha captcha;
+ if (session.getAttribute(NAME) == null)
+ {
+ captcha = new Captcha.Builder(_width,
_height).addText().gimp().addNoise().addBackground().build();
+
+
+ session.setAttribute(NAME, captcha);
+ writeImage(resp, captcha.getImage());
+
+ return;
+ }
+
+ captcha = (Captcha)session.getAttribute(NAME);
+ writeImage(resp, captcha.getImage());
+
+ }
+
+ public static void writeImage(ResourceResponse response, BufferedImage bi)
+ {
+ response.setProperty("Cache-Control",
"private,no-cache,no-store");
+ response.setContentType("image/png"); // PNGs allow for transparency.
JPGs do not.
+ try
+ {
+ CaptchaServletUtil.writeImage(response.getPortletOutputStream(), bi);
+ }
+ catch (IOException e)
+ {
+ e.printStackTrace();
+ }
+ }
+}
Modified:
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/portlet/exoadmin/src/main/webapp/WEB-INF/portlet.xml 2010-10-05
08:51:19 UTC (rev 4497)
@@ -85,12 +85,20 @@
<description xml:lang="EN">Register Portlet</description>
<portlet-name>RegisterPortlet</portlet-name>
<display-name xml:lang="EN">Register Portlet</display-name>
-
<portlet-class>org.exoplatform.webui.application.portlet.PortletApplicationController</portlet-class>
+
<portlet-class>org.exoplatform.account.webui.component.RegisterPortletApplicationController</portlet-class>
<init-param>
<name>webui.configuration</name>
<value>/WEB-INF/conf/portlet/exoadmin/RegisterPortlet/webui/configuration.xml</value>
</init-param>
+ <init-param>
+ <name>width</name>
+ <value>200</value>
+ </init-param>
+ <init-param>
+ <name>height</name>
+ <value>75</value>
+ </init-param>
<expiration-cache>0</expiration-cache>
<supports>
Modified: epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/web.xml
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/web.xml 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/web/portal/src/main/webapp/WEB-INF/web.xml 2010-10-05
08:51:19 UTC (rev 4497)
@@ -226,25 +226,6 @@
<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:
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/CaptchaValidator.java 2010-10-05
08:51:19 UTC (rev 4497)
@@ -19,9 +19,8 @@
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.application.portlet.PortletRequestContext;
import org.exoplatform.webui.core.UIComponent;
import org.exoplatform.webui.exception.MessageException;
import org.exoplatform.webui.form.UIForm;
@@ -32,8 +31,8 @@
import java.io.Serializable;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpSession;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletSession;
/**
* @author <a href="mailto:theute@redhat.com">Thomas Heute</a>
@@ -46,9 +45,9 @@
public void validate(UIFormInput uiInput) throws Exception
{
- PortalRequestContext prContext = Util.getPortalRequestContext();
- HttpServletRequest request = prContext.getRequest();
- HttpSession session = request.getSession();
+ PortletRequestContext ctx = PortletRequestContext.getCurrentInstance();
+ PortletRequest req = ctx.getRequest();
+ PortletSession session = req.getPortletSession();
Captcha captcha = (Captcha) session.getAttribute(Captcha.NAME);
Modified:
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java
===================================================================
---
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java 2010-10-05
08:44:26 UTC (rev 4496)
+++
epp/portal/branches/EPP_5_1_Branch/webui/portal/src/main/java/org/exoplatform/portal/webui/UICaptcha.java 2010-10-05
08:51:19 UTC (rev 4497)
@@ -22,11 +22,12 @@
******************************************************************************/
package org.exoplatform.portal.webui;
-import java.util.Calendar;
-
import org.exoplatform.webui.application.WebuiRequestContext;
import org.exoplatform.webui.form.UIFormStringInput;
+import javax.portlet.RenderResponse;
+import javax.portlet.ResourceURL;
+
/**
* @author <a href="mailto:theute@redhat.com">Thomas Heute</a>
* @version $Revision$
@@ -40,9 +41,18 @@
}
public void processRender(WebuiRequestContext context) throws Exception
- {
- context.getWriter().write("<div id='" + getId() +
"'><img src=\"" + context.getPortalContextPath() +
"/captcha?v=" +
- Calendar.getInstance().getTimeInMillis() + "\"
/><br/>");
+ {
+
+ RenderResponse resp = context.getResponse();
+
+ //
+ ResourceURL url = resp.createResourceURL();
+
+ // context.getPortalContextPath() + "/captcha?v=" +
Calendar.getInstance().getTimeInMillis()
+
+
+
+ context.getWriter().write("<div id='" + getId() +
"'><img src=\"" + url.toString() + "\"
/><br/>");
super.processRender(context);
context.getWriter().write("</div>");
}