Author: julien_viet
Date: 2010-07-23 17:22:58 -0400 (Fri, 23 Jul 2010)
New Revision: 3699
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/FileResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/MockResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceKey.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceResolver.java
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java
portal/trunk/component/resources/src/main/java/org/exoplatform/web/application/JavascriptManager.java
portal/trunk/component/web/api/
portal/trunk/component/web/api/pom.xml
portal/trunk/component/web/api/src/
portal/trunk/component/web/api/src/main/
portal/trunk/component/web/api/src/main/java/
portal/trunk/component/web/api/src/main/java/org/
portal/trunk/component/web/api/src/main/java/org/exoplatform/
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/GenericHttpListener.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/ExtensibleFilter.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/Filter.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinition.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinitionPlugin.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterMapping.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/GenericFilter.java
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/resource/
portal/trunk/component/web/api/src/test/
portal/trunk/component/web/api/src/test/java/
portal/trunk/component/web/api/src/test/java/conf/
portal/trunk/component/web/api/src/test/java/conf/portal/
portal/trunk/component/web/api/src/test/java/conf/portal/test-configuration.xml
portal/trunk/component/web/api/src/test/java/org/
portal/trunk/component/web/api/src/test/java/org/exoplatform/
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/command/
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/command/TestCommandHandler.java
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestExtensibleFilter.java
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestFilterDefinition.java
portal/trunk/component/web/api/src/test/resources/
portal/trunk/component/web/api/src/test/resources/TestJSonFormat.html
portal/trunk/component/web/controller/
portal/trunk/component/web/controller/pom.xml
portal/trunk/component/web/controller/src/
portal/trunk/component/web/controller/src/main/
portal/trunk/component/web/controller/src/main/java/
portal/trunk/component/web/controller/src/main/java/org/
portal/trunk/component/web/controller/src/main/java/org/exoplatform/
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Application.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationLifecycle.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationSession.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Parameter.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestContext.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestFailure.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/URLBuilder.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/Command.java
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/CommandHandler.java
portal/trunk/component/web/security/
portal/trunk/component/web/security/pom.xml
portal/trunk/component/web/security/src/
portal/trunk/component/web/security/src/main/
portal/trunk/component/web/security/src/main/java/
portal/trunk/component/web/security/src/main/java/conf/
portal/trunk/component/web/security/src/main/java/conf/autologin-nodetypes.xml
portal/trunk/component/web/security/src/main/java/conf/portal/
portal/trunk/component/web/security/src/main/java/conf/portal/configuration.xml
portal/trunk/component/web/security/src/main/java/org/
portal/trunk/component/web/security/src/main/java/org/exoplatform/
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/CacheUserProfileFilter.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ClusteredSSOFilter.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/RememberMeFilter.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Credentials.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/GateInToken.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/PortalLoginModule.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Token.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/TokenStore.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/RemindPasswordTokenService.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenEntry.java
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
portal/trunk/component/web/server/
portal/trunk/component/web/server/pom.xml
portal/trunk/component/web/server/src/
portal/trunk/component/web/server/src/main/
portal/trunk/component/web/server/src/main/java/
portal/trunk/component/web/server/src/main/java/org/
portal/trunk/component/web/server/src/main/java/org/exoplatform/
portal/trunk/component/web/server/src/main/java/org/exoplatform/download/
portal/trunk/component/web/server/src/main/java/org/exoplatform/services/
portal/trunk/component/web/server/src/main/java/org/exoplatform/upload/
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
Removed:
portal/trunk/component/web/src/
Modified:
portal/trunk/component/application-registry/pom.xml
portal/trunk/component/portal/pom.xml
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/FileResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/MockResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceKey.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceResolver.java
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java
portal/trunk/component/web/pom.xml
portal/trunk/examples/extension/ear/pom.xml
portal/trunk/examples/extension/jar/pom.xml
portal/trunk/examples/portal/ear/pom.xml
portal/trunk/examples/portal/jar/pom.xml
portal/trunk/gadgets/core/pom.xml
portal/trunk/gadgets/eXoGadgets/pom.xml
portal/trunk/packaging/jboss-as/ear/pom.xml
portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
portal/trunk/pom.xml
portal/trunk/webui/core/pom.xml
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/wysiwyg/FCKEditor.java
portal/trunk/webui/framework/pom.xml
portal/trunk/webui/framework/src/main/java/org/exoplatform/webui/core/UIComponent.java
portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
Log:
GTNPORTAL-1374 : component.web modularization
Modified: portal/trunk/component/application-registry/pom.xml
===================================================================
--- portal/trunk/component/application-registry/pom.xml 2010-07-23 11:14:58 UTC (rev
3698)
+++ portal/trunk/component/application-registry/pom.xml 2010-07-23 21:22:58 UTC (rev
3699)
@@ -48,6 +48,11 @@
</dependency>
<dependency>
+ <groupId>org.gatein.shindig</groupId>
+ <artifactId>shindig-gadgets</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.chromattic</groupId>
<artifactId>chromattic.ext</artifactId>
</dependency>
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,124 @@
+/**
+ * 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.resolver;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * This class is an aggregation of ResourceResolver object and extends itself the
ResourceResover class.
+ *
+ * Hence every call to this ResourceResolver will in fact be delegated to one of the
resolver it aggregates.
+ *
+ * Created by The eXo Platform SAS
+ * Oct 24, 2006
+ */
+public class ApplicationResourceResolver extends ResourceResolver
+{
+
+ protected static Log log =
ExoLogger.getLogger("portal:ApplicationResourceResolver");
+
+ private Map<String, ResourceResolver> resolvers_ = new HashMap<String,
ResourceResolver>();
+
+ /**
+ * There are by default 2 resolvers already aggregated:
+ * 1) FileResourceResolver
+ * 2) ClasspathResourceResolver
+ */
+ public ApplicationResourceResolver()
+ {
+ addResourceResolver(new FileResourceResolver());
+ addResourceResolver(new ClasspathResourceResolver());
+ }
+
+ public ResourceResolver getResourceResolverByScheme(String scheme)
+ {
+ return resolvers_.get(scheme);
+ }
+
+ public ResourceResolver getResourceResolver(String url)
+ {
+ String scheme = "app:";
+ int index = url.indexOf(":");
+ if (index > 0)
+ scheme = url.substring(0, index + 1);
+ if (log.isDebugEnabled())
+ log.debug("Try to extract resource resolver for the url: " + url);
+ return resolvers_.get(scheme);
+ }
+
+ public void addResourceResolver(ResourceResolver resolver)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Add a resource resolver for the scheme: " +
resolver.getResourceScheme());
+ resolvers_.put(resolver.getResourceScheme(), resolver);
+ }
+
+ public URL getResource(String url) throws Exception
+ {
+ return getResourceResolver(url).getResource(url);
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ return getResourceResolver(url).getInputStream(url);
+ }
+
+ public List<URL> getResources(String url) throws Exception
+ {
+ return getResourceResolver(url).getResources(url);
+ }
+
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ return getResourceResolver(url).getInputStreams(url);
+ }
+
+ public boolean isModified(String url, long lastAccess)
+ {
+ return getResourceResolver(url).isModified(url, lastAccess);
+ }
+
+ public boolean isResolvable(String url)
+ {
+ return getResourceResolver(url) != null;
+ }
+
+ public String getResourceIdPrefix()
+ {
+ return Integer.toString(hashCode());
+ }
+
+ public String createResourceId(String url)
+ {
+ return hashCode() + ":" + url;
+ }
+
+ public String getResourceScheme()
+ {
+ return "app:";
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -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.resolver;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Tuan Nguyen
+ * tuan08(a)users.sourceforge.net
+ * Mar 15, 2006
+ */
+public class ClasspathResourceResolver extends ResourceResolver
+{
+
+ public URL getResource(String url) throws Exception
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return cl.getResource(removeScheme(url));
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ return cl.getResourceAsStream(removeScheme(url));
+ }
+
+ public List<URL> getResources(String url) throws Exception
+ {
+ ArrayList<URL> urlList = new ArrayList<URL>();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Enumeration<URL> e = cl.getResources(removeScheme(url));
+ while (e.hasMoreElements())
+ urlList.add(e.nextElement());
+ return urlList;
+ }
+
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Enumeration<URL> e = cl.getResources(removeScheme(url));
+ while (e.hasMoreElements())
+ inputStreams.add(e.nextElement().openStream());
+ return inputStreams;
+ }
+
+ @SuppressWarnings("unused")
+ public boolean isModified(String url, long lastAccess)
+ {
+ return false;
+ }
+
+ public String getResourceScheme()
+ {
+ return "classpath:";
+ }
+
+}
\ No newline at end of file
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/FileResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/FileResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/FileResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,94 @@
+/**
+ * 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.resolver;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Tuan Nguyen
+ * tuan08(a)users.sourceforge.net
+ * Mar 15, 2006
+ */
+public class FileResourceResolver extends ResourceResolver
+{
+
+ static String FILE_PREFIX = "file:";
+
+ public URL getResource(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ File file = new File(path);
+ if (file.exists() && file.isFile())
+ return file.toURL();
+ return null;
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ File file = new File(path);
+ if (file.exists() && file.isFile())
+ {
+ FileInputStream is = new FileInputStream(file);
+ return is;
+ }
+ return null;
+ }
+
+ public List<URL> getResources(String url) throws Exception
+ {
+ ArrayList<URL> urlList = new ArrayList<URL>();
+ urlList.add(getResource(url));
+ return urlList;
+ }
+
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
+ inputStreams.add(getInputStream(url));
+ return inputStreams;
+ }
+
+ public String getRealPath(String url)
+ {
+ String path = removeScheme(url);
+ return path;
+ }
+
+ public boolean isModified(String url, long lastAccess)
+ {
+ File file = new File(getRealPath(url));
+ if (file.exists() && file.lastModified() > lastAccess)
+ return true;
+ return false;
+ }
+
+ public String getResourceScheme()
+ {
+ return "file:";
+ }
+
+}
\ No newline at end of file
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/MockResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/MockResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/MockResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,73 @@
+/**
+ * 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.resolver;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+public class MockResourceResolver extends ResourceResolver
+{
+
+ private Map<String, URL> resources_;
+
+ public MockResourceResolver(Map<String, URL> mapResources)
+ {
+ resources_ = mapResources;
+ }
+
+ public URL getResource(String url) throws Exception
+ {
+ return resources_.get(url);
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ URL result = resources_.get(url);
+ if (result != null)
+ return result.openStream();
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ public List<URL> getResources(String url) throws Exception
+ {
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ return null;
+ }
+
+ @SuppressWarnings("unused")
+ public boolean isModified(String url, long lastAccess)
+ {
+ return false;
+ }
+
+ public String getResourceScheme()
+ {
+ return null;
+ }
+
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,106 @@
+/**
+ * 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.resolver;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.portlet.PortletContext;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 15, 2006
+ */
+public class PortletResourceResolver extends ResourceResolver
+{
+
+ protected static Log log = ExoLogger.getLogger(PortletResourceResolver.class);
+
+ private PortletContext pcontext_;
+
+ private String scheme_;
+
+ public PortletResourceResolver(PortletContext context, String scheme)
+ {
+ pcontext_ = context;
+ scheme_ = scheme;
+ }
+
+ public URL getResource(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ return pcontext_.getResource(path);
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ return pcontext_.getResourceAsStream(path);
+ }
+
+ public List<URL> getResources(String url) throws Exception
+ {
+ ArrayList<URL> urlList = new ArrayList<URL>();
+ urlList.add(getResource(url));
+ return urlList;
+ }
+
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
+ inputStreams.add(getInputStream(url));
+ return inputStreams;
+ }
+
+ public String getRealPath(String url)
+ {
+ String path = removeScheme(url);
+ return pcontext_.getRealPath(path);
+ }
+
+ public boolean isModified(String url, long lastAccess)
+ {
+ File file = new File(getRealPath(url));
+ if (log.isDebugEnabled())
+ log.debug(url + ": " + file.lastModified() + " " +
lastAccess);
+ if (file.exists() && file.lastModified() > lastAccess)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public String getWebAccessPath(String url)
+ {
+ return "/" + pcontext_.getPortletContextName() + removeScheme(url);
+ }
+
+ public String getResourceScheme()
+ {
+ return scheme_;
+ }
+
+}
\ No newline at end of file
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceKey.java
===================================================================
--- portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceKey.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceKey.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,72 @@
+/*
+ * 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.resolver;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class ResourceKey implements Serializable
+{
+
+ /** . */
+ private final int resolverId;
+
+ /** . */
+ private final String url;
+
+ public ResourceKey(int resolverId, String url)
+ {
+ if (url == null)
+ {
+ throw new NullPointerException("no null URL accepted");
+ }
+ this.resolverId = resolverId;
+ this.url = url;
+ }
+
+ public String getURL()
+ {
+ return url;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return resolverId ^ url.hashCode();
+ }
+
+ @Override
+ public boolean equals(Object o)
+ {
+ if (o == this)
+ {
+ return true;
+ }
+ if (o instanceof ResourceKey)
+ {
+ ResourceKey that = (ResourceKey)o;
+ return resolverId == that.resolverId && url.equals(that.url);
+ }
+ return false;
+ }
+}
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,97 @@
+/**
+ * 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.resolver;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 15, 2006
+ */
+abstract public class ResourceResolver
+{
+
+ abstract public URL getResource(String url) throws Exception;
+
+ abstract public InputStream getInputStream(String url) throws Exception;
+
+ abstract public List<URL> getResources(String url) throws Exception;
+
+ abstract public List<InputStream> getInputStreams(String url) throws Exception;
+
+ @SuppressWarnings("unused")
+ public String getWebAccessPath(String url)
+ {
+ throw new RuntimeException("This method is not supported");
+ }
+
+ abstract public String getResourceScheme();
+
+ @SuppressWarnings("unused")
+ public String getRealPath(String url)
+ {
+ throw new RuntimeException("unsupported method");
+ }
+
+ public ResourceKey createResourceKey(String url)
+ {
+ return new ResourceKey(hashCode(), url);
+ }
+
+ public String createResourceId(String url)
+ {
+ return hashCode() + ":" + url;
+ }
+
+ public boolean isResolvable(String url)
+ {
+ return url.startsWith(getResourceScheme());
+ }
+
+ public byte[] getResourceContentAsBytes(String url) throws Exception
+ {
+ InputStream is = getInputStream(url);
+ BufferedInputStream buffer = new BufferedInputStream(is);
+ ByteArrayOutputStream output = new ByteArrayOutputStream();
+ byte[] data = new byte[buffer.available()];
+ int available = -1;
+ while ((available = buffer.read(data)) > -1)
+ {
+ output.write(data, 0, available);
+ }
+ return output.toByteArray();
+ }
+
+ abstract public boolean isModified(String url, long lastAccess);
+
+ protected String removeScheme(String url)
+ {
+ String scheme = getResourceScheme();
+ if (url.startsWith(scheme))
+ {
+ return url.substring(scheme.length());
+ }
+ return url;
+ }
+}
\ No newline at end of file
Added:
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java
===================================================================
---
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java
(rev 0)
+++
portal/trunk/component/common/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,108 @@
+/**
+ * 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.resolver;
+
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.ServletContext;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 15, 2006
+ */
+public class ServletResourceResolver extends ResourceResolver
+{
+
+ protected static Log log =
ExoLogger.getLogger("portal:ServletResourceResolver");
+
+ private ServletContext scontext_;
+
+ private String scheme_;
+
+ public ServletResourceResolver(ServletContext context, String scheme)
+ {
+ scontext_ = context;
+ scheme_ = scheme;
+ }
+
+ public URL getResource(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ return scontext_.getResource(path);
+ }
+
+ public InputStream getInputStream(String url) throws Exception
+ {
+ String path = removeScheme(url);
+ return scontext_.getResourceAsStream(path);
+ }
+
+ public List<URL> getResources(String url) throws Exception
+ {
+ ArrayList<URL> urlList = new ArrayList<URL>();
+ urlList.add(getResource(url));
+ return urlList;
+ }
+
+ public List<InputStream> getInputStreams(String url) throws Exception
+ {
+ ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
+ inputStreams.add(getInputStream(url));
+ return inputStreams;
+ }
+
+ public String getRealPath(String url)
+ {
+ String path = removeScheme(url);
+ return scontext_.getRealPath(path);
+ }
+
+ public boolean isModified(String url, long lastAccess)
+ {
+ File file = new File(getRealPath(url));
+ if (log.isDebugEnabled())
+ log.debug(url + ": " + file.lastModified() + " " +
lastAccess);
+ if (file.exists() && file.lastModified() > lastAccess)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public String getWebAccessPath(String url)
+ {
+ if (log.isDebugEnabled())
+ log.debug("GET WEB ACCESS " + url);
+ return "/" + scontext_.getServletContextName() + removeScheme(url);
+ }
+
+ public String getResourceScheme()
+ {
+ return scheme_;
+ }
+
+}
\ No newline at end of file
Modified: portal/trunk/component/portal/pom.xml
===================================================================
--- portal/trunk/component/portal/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/component/portal/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -50,11 +50,6 @@
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component.pc</artifactId>
</dependency>
@@ -84,6 +79,11 @@
</dependency>
<dependency>
+ <groupId>org.json</groupId>
+ <artifactId>json</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<scope>provided</scope>
Copied:
portal/trunk/component/resources/src/main/java/org/exoplatform/web/application/JavascriptManager.java
(from rev 3698,
portal/trunk/component/web/src/main/java/org/exoplatform/web/application/JavascriptManager.java)
===================================================================
---
portal/trunk/component/resources/src/main/java/org/exoplatform/web/application/JavascriptManager.java
(rev 0)
+++
portal/trunk/component/resources/src/main/java/org/exoplatform/web/application/JavascriptManager.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,166 @@
+/**
+ * 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.web.application;
+
+import org.exoplatform.commons.utils.PropertyManager;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.web.application.javascript.JavascriptConfigService;
+
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 27, 2007
+ */
+public class JavascriptManager
+{
+
+ /** . */
+ private ArrayList<String> data = new ArrayList<String>(100);
+
+ /** . */
+ private ArrayList<String> customizedOnloadJavascript = null;
+
+ /** . */
+ private JavascriptConfigService jsSrevice_;
+
+ public JavascriptManager()
+ {
+ jsSrevice_ =
+
(JavascriptConfigService)ExoContainerContext.getCurrentContainer().getComponentInstanceOfType(
+ JavascriptConfigService.class);
+ }
+
+ public void addJavascript(CharSequence s)
+ {
+ if (s != null)
+ {
+ data.add(s instanceof String ? (String)s : s.toString());
+ data.add(" \n");
+ }
+ }
+
+ public void importJavascript(CharSequence s)
+ {
+ if (s != null)
+ {
+ if (!jsSrevice_.isModuleLoaded(s) || PropertyManager.isDevelopping())
+ {
+ data.add("eXo.require('");
+ data.add(s instanceof String ? (String)s : s.toString());
+ data.add("'); \n");
+ }
+ }
+ }
+
+ public void importJavascript(String s, String location)
+ {
+ if (s != null && location != null)
+ {
+ if (!jsSrevice_.isModuleLoaded(s) || PropertyManager.isDevelopping())
+ {
+ data.add("eXo.require('");
+ data.add(s);
+ data.add("', '");
+ data.add(location);
+ if (!location.endsWith("/"))
+ {
+ data.add("/");
+ }
+ data.add("'); \n");
+ }
+ }
+ }
+
+ public void addOnLoadJavascript(CharSequence s)
+ {
+ if (s != null)
+ {
+ String id = Integer.toString(Math.abs(s.hashCode()));
+ data.add("eXo.core.Browser.addOnLoadCallback('mid");
+ data.add(id);
+ data.add("',");
+ data.add(s instanceof String ? (String)s : s.toString());
+ data.add("); \n");
+ }
+ }
+
+ public void addOnResizeJavascript(CharSequence s)
+ {
+ if (s != null)
+ {
+ String id = Integer.toString(Math.abs(s.hashCode()));
+ data.add("eXo.core.Browser.addOnResizeCallback('mid");
+ data.add(id);
+ data.add("',");
+ data.add(s instanceof String ? (String)s : s.toString());
+ data.add("); \n");
+ }
+ }
+
+ public void addOnScrollJavascript(CharSequence s)
+ {
+ if (s != null)
+ {
+ String id = Integer.toString(Math.abs(s.hashCode()));
+ data.add("eXo.core.Browser.addOnScrollCallback('mid");
+ data.add(id);
+ data.add("',");
+ data.add(s instanceof String ? (String)s : s.toString());
+ data.add("); \n");
+ }
+ }
+
+ public void writeJavascript(Writer writer) throws IOException
+ {
+ for (int i = 0;i < data.size();i++)
+ {
+ String s = data.get(i);
+ writer.write(s);
+ }
+ }
+
+ public void addCustomizedOnLoadScript(CharSequence s)
+ {
+ if (s != null)
+ {
+ if (customizedOnloadJavascript == null)
+ {
+ customizedOnloadJavascript = new ArrayList<String>(30);
+ }
+ customizedOnloadJavascript.add(s instanceof String ? (String)s : s.toString());
+ customizedOnloadJavascript.add("\n");
+ }
+ }
+
+ public void writeCustomizedOnLoadScript(Writer writer) throws IOException
+ {
+ if (customizedOnloadJavascript != null)
+ {
+ for (int i = 0;i < customizedOnloadJavascript.size();i++)
+ {
+ String s = customizedOnloadJavascript.get(i);
+ writer.write(s);
+ }
+ }
+ }
+}
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ApplicationResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,124 +0,0 @@
-/**
- * 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.resolver;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * This class is an aggregation of ResourceResolver object and extends itself the
ResourceResover class.
- *
- * Hence every call to this ResourceResolver will in fact be delegated to one of the
resolver it aggregates.
- *
- * Created by The eXo Platform SAS
- * Oct 24, 2006
- */
-public class ApplicationResourceResolver extends ResourceResolver
-{
-
- protected static Log log =
ExoLogger.getLogger("portal:ApplicationResourceResolver");
-
- private Map<String, ResourceResolver> resolvers_ = new HashMap<String,
ResourceResolver>();
-
- /**
- * There are by default 2 resolvers already aggregated:
- * 1) FileResourceResolver
- * 2) ClasspathResourceResolver
- */
- public ApplicationResourceResolver()
- {
- addResourceResolver(new FileResourceResolver());
- addResourceResolver(new ClasspathResourceResolver());
- }
-
- public ResourceResolver getResourceResolverByScheme(String scheme)
- {
- return resolvers_.get(scheme);
- }
-
- public ResourceResolver getResourceResolver(String url)
- {
- String scheme = "app:";
- int index = url.indexOf(":");
- if (index > 0)
- scheme = url.substring(0, index + 1);
- if (log.isDebugEnabled())
- log.debug("Try to extract resource resolver for the url: " + url);
- return resolvers_.get(scheme);
- }
-
- public void addResourceResolver(ResourceResolver resolver)
- {
- if (log.isDebugEnabled())
- log.debug("Add a resource resolver for the scheme: " +
resolver.getResourceScheme());
- resolvers_.put(resolver.getResourceScheme(), resolver);
- }
-
- public URL getResource(String url) throws Exception
- {
- return getResourceResolver(url).getResource(url);
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- return getResourceResolver(url).getInputStream(url);
- }
-
- public List<URL> getResources(String url) throws Exception
- {
- return getResourceResolver(url).getResources(url);
- }
-
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- return getResourceResolver(url).getInputStreams(url);
- }
-
- public boolean isModified(String url, long lastAccess)
- {
- return getResourceResolver(url).isModified(url, lastAccess);
- }
-
- public boolean isResolvable(String url)
- {
- return getResourceResolver(url) != null;
- }
-
- public String getResourceIdPrefix()
- {
- return Integer.toString(hashCode());
- }
-
- public String createResourceId(String url)
- {
- return hashCode() + ":" + url;
- }
-
- public String getResourceScheme()
- {
- return "app:";
- }
-}
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ClasspathResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,80 +0,0 @@
-/**
- * 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.resolver;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Tuan Nguyen
- * tuan08(a)users.sourceforge.net
- * Mar 15, 2006
- */
-public class ClasspathResourceResolver extends ResourceResolver
-{
-
- public URL getResource(String url) throws Exception
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return cl.getResource(removeScheme(url));
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- return cl.getResourceAsStream(removeScheme(url));
- }
-
- public List<URL> getResources(String url) throws Exception
- {
- ArrayList<URL> urlList = new ArrayList<URL>();
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Enumeration<URL> e = cl.getResources(removeScheme(url));
- while (e.hasMoreElements())
- urlList.add(e.nextElement());
- return urlList;
- }
-
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
- ClassLoader cl = Thread.currentThread().getContextClassLoader();
- Enumeration<URL> e = cl.getResources(removeScheme(url));
- while (e.hasMoreElements())
- inputStreams.add(e.nextElement().openStream());
- return inputStreams;
- }
-
- @SuppressWarnings("unused")
- public boolean isModified(String url, long lastAccess)
- {
- return false;
- }
-
- public String getResourceScheme()
- {
- return "classpath:";
- }
-
-}
\ No newline at end of file
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/FileResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/FileResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/FileResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,94 +0,0 @@
-/**
- * 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.resolver;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SARL
- * Author : Tuan Nguyen
- * tuan08(a)users.sourceforge.net
- * Mar 15, 2006
- */
-public class FileResourceResolver extends ResourceResolver
-{
-
- static String FILE_PREFIX = "file:";
-
- public URL getResource(String url) throws Exception
- {
- String path = removeScheme(url);
- File file = new File(path);
- if (file.exists() && file.isFile())
- return file.toURL();
- return null;
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- String path = removeScheme(url);
- File file = new File(path);
- if (file.exists() && file.isFile())
- {
- FileInputStream is = new FileInputStream(file);
- return is;
- }
- return null;
- }
-
- public List<URL> getResources(String url) throws Exception
- {
- ArrayList<URL> urlList = new ArrayList<URL>();
- urlList.add(getResource(url));
- return urlList;
- }
-
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
- inputStreams.add(getInputStream(url));
- return inputStreams;
- }
-
- public String getRealPath(String url)
- {
- String path = removeScheme(url);
- return path;
- }
-
- public boolean isModified(String url, long lastAccess)
- {
- File file = new File(getRealPath(url));
- if (file.exists() && file.lastModified() > lastAccess)
- return true;
- return false;
- }
-
- public String getResourceScheme()
- {
- return "file:";
- }
-
-}
\ No newline at end of file
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/MockResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/MockResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/MockResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,73 +0,0 @@
-/**
- * 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.resolver;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-public class MockResourceResolver extends ResourceResolver
-{
-
- private Map<String, URL> resources_;
-
- public MockResourceResolver(Map<String, URL> mapResources)
- {
- resources_ = mapResources;
- }
-
- public URL getResource(String url) throws Exception
- {
- return resources_.get(url);
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- URL result = resources_.get(url);
- if (result != null)
- return result.openStream();
- return null;
- }
-
- @SuppressWarnings("unused")
- public List<URL> getResources(String url) throws Exception
- {
- return null;
- }
-
- @SuppressWarnings("unused")
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- return null;
- }
-
- @SuppressWarnings("unused")
- public boolean isModified(String url, long lastAccess)
- {
- return false;
- }
-
- public String getResourceScheme()
- {
- return null;
- }
-
-}
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/PortletResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,106 +0,0 @@
-/**
- * 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.resolver;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.portlet.PortletContext;
-
-/**
- * Created by The eXo Platform SAS
- * Mar 15, 2006
- */
-public class PortletResourceResolver extends ResourceResolver
-{
-
- protected static Log log = ExoLogger.getLogger(PortletResourceResolver.class);
-
- private PortletContext pcontext_;
-
- private String scheme_;
-
- public PortletResourceResolver(PortletContext context, String scheme)
- {
- pcontext_ = context;
- scheme_ = scheme;
- }
-
- public URL getResource(String url) throws Exception
- {
- String path = removeScheme(url);
- return pcontext_.getResource(path);
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- String path = removeScheme(url);
- return pcontext_.getResourceAsStream(path);
- }
-
- public List<URL> getResources(String url) throws Exception
- {
- ArrayList<URL> urlList = new ArrayList<URL>();
- urlList.add(getResource(url));
- return urlList;
- }
-
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
- inputStreams.add(getInputStream(url));
- return inputStreams;
- }
-
- public String getRealPath(String url)
- {
- String path = removeScheme(url);
- return pcontext_.getRealPath(path);
- }
-
- public boolean isModified(String url, long lastAccess)
- {
- File file = new File(getRealPath(url));
- if (log.isDebugEnabled())
- log.debug(url + ": " + file.lastModified() + " " +
lastAccess);
- if (file.exists() && file.lastModified() > lastAccess)
- {
- return true;
- }
- return false;
- }
-
- public String getWebAccessPath(String url)
- {
- return "/" + pcontext_.getPortletContextName() + removeScheme(url);
- }
-
- public String getResourceScheme()
- {
- return scheme_;
- }
-
-}
\ No newline at end of file
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceKey.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceKey.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceKey.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,72 +0,0 @@
-/*
- * 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.resolver;
-
-import java.io.Serializable;
-
-/**
- * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
- * @version $Revision$
- */
-public class ResourceKey implements Serializable
-{
-
- /** . */
- private final int resolverId;
-
- /** . */
- private final String url;
-
- public ResourceKey(int resolverId, String url)
- {
- if (url == null)
- {
- throw new NullPointerException("no null URL accepted");
- }
- this.resolverId = resolverId;
- this.url = url;
- }
-
- public String getURL()
- {
- return url;
- }
-
- @Override
- public int hashCode()
- {
- return resolverId ^ url.hashCode();
- }
-
- @Override
- public boolean equals(Object o)
- {
- if (o == this)
- {
- return true;
- }
- if (o instanceof ResourceKey)
- {
- ResourceKey that = (ResourceKey)o;
- return resolverId == that.resolverId && url.equals(that.url);
- }
- return false;
- }
-}
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,97 +0,0 @@
-/**
- * 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.resolver;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-
-/**
- * Created by The eXo Platform SAS
- * Mar 15, 2006
- */
-abstract public class ResourceResolver
-{
-
- abstract public URL getResource(String url) throws Exception;
-
- abstract public InputStream getInputStream(String url) throws Exception;
-
- abstract public List<URL> getResources(String url) throws Exception;
-
- abstract public List<InputStream> getInputStreams(String url) throws Exception;
-
- @SuppressWarnings("unused")
- public String getWebAccessPath(String url)
- {
- throw new RuntimeException("This method is not supported");
- }
-
- abstract public String getResourceScheme();
-
- @SuppressWarnings("unused")
- public String getRealPath(String url)
- {
- throw new RuntimeException("unsupported method");
- }
-
- public ResourceKey createResourceKey(String url)
- {
- return new ResourceKey(hashCode(), url);
- }
-
- public String createResourceId(String url)
- {
- return hashCode() + ":" + url;
- }
-
- public boolean isResolvable(String url)
- {
- return url.startsWith(getResourceScheme());
- }
-
- public byte[] getResourceContentAsBytes(String url) throws Exception
- {
- InputStream is = getInputStream(url);
- BufferedInputStream buffer = new BufferedInputStream(is);
- ByteArrayOutputStream output = new ByteArrayOutputStream();
- byte[] data = new byte[buffer.available()];
- int available = -1;
- while ((available = buffer.read(data)) > -1)
- {
- output.write(data, 0, available);
- }
- return output.toByteArray();
- }
-
- abstract public boolean isModified(String url, long lastAccess);
-
- protected String removeScheme(String url)
- {
- String scheme = getResourceScheme();
- if (url.startsWith(scheme))
- {
- return url.substring(scheme.length());
- }
- return url;
- }
-}
\ No newline at end of file
Modified:
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java
===================================================================
---
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/component/scripting/src/main/java/org/exoplatform/resolver/ServletResourceResolver.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -1,108 +0,0 @@
-/**
- * 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.resolver;
-
-import org.exoplatform.services.log.ExoLogger;
-import org.exoplatform.services.log.Log;
-
-import java.io.File;
-import java.io.InputStream;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.servlet.ServletContext;
-
-/**
- * Created by The eXo Platform SAS
- * Mar 15, 2006
- */
-public class ServletResourceResolver extends ResourceResolver
-{
-
- protected static Log log =
ExoLogger.getLogger("portal:ServletResourceResolver");
-
- private ServletContext scontext_;
-
- private String scheme_;
-
- public ServletResourceResolver(ServletContext context, String scheme)
- {
- scontext_ = context;
- scheme_ = scheme;
- }
-
- public URL getResource(String url) throws Exception
- {
- String path = removeScheme(url);
- return scontext_.getResource(path);
- }
-
- public InputStream getInputStream(String url) throws Exception
- {
- String path = removeScheme(url);
- return scontext_.getResourceAsStream(path);
- }
-
- public List<URL> getResources(String url) throws Exception
- {
- ArrayList<URL> urlList = new ArrayList<URL>();
- urlList.add(getResource(url));
- return urlList;
- }
-
- public List<InputStream> getInputStreams(String url) throws Exception
- {
- ArrayList<InputStream> inputStreams = new ArrayList<InputStream>();
- inputStreams.add(getInputStream(url));
- return inputStreams;
- }
-
- public String getRealPath(String url)
- {
- String path = removeScheme(url);
- return scontext_.getRealPath(path);
- }
-
- public boolean isModified(String url, long lastAccess)
- {
- File file = new File(getRealPath(url));
- if (log.isDebugEnabled())
- log.debug(url + ": " + file.lastModified() + " " +
lastAccess);
- if (file.exists() && file.lastModified() > lastAccess)
- {
- return true;
- }
- return false;
- }
-
- public String getWebAccessPath(String url)
- {
- if (log.isDebugEnabled())
- log.debug("GET WEB ACCESS " + url);
- return "/" + scontext_.getServletContextName() + removeScheme(url);
- }
-
- public String getResourceScheme()
- {
- return scheme_;
- }
-
-}
\ No newline at end of file
Added: portal/trunk/component/web/api/pom.xml
===================================================================
--- portal/trunk/component/web/api/pom.xml (rev 0)
+++ portal/trunk/component/web/api/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -0,0 +1,51 @@
+<!--
+ ~ 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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>exo.portal.component.web.api</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn Portal Component Web API</name>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.test.core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/GenericHttpListener.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/GenericHttpListener.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/GenericHttpListener.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,225 @@
+/**
+ * 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.web;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.RootContainer;
+import org.exoplatform.container.RootContainer.PortalContainerPostInitTask;
+import org.exoplatform.container.util.EnvSpecific;
+import org.exoplatform.container.web.AbstractHttpSessionListener;
+import org.exoplatform.services.listener.ListenerService;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+
+import java.util.EventObject;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
+import javax.servlet.ServletContextListener;
+import javax.servlet.http.HttpSessionEvent;
+
+/**
+ * This class is used to broadcast any "HttpEvent" to allow the rest of the
platform to be notified
+ * without changing the web.xml file.
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class GenericHttpListener extends AbstractHttpSessionListener implements
ServletContextListener
+{
+
+ /**
+ * The name of the "session created" event
+ */
+ public static final String SESSION_CREATED =
"org.exoplatform.web.GenericHttpListener.sessionCreated";
+
+ /**
+ * The name of the "session destroyed" event
+ */
+ public static final String SESSION_DESTROYED =
"org.exoplatform.web.GenericHttpListener.sessionDestroyed";
+
+ /**
+ * The name of the "context initialized" event
+ */
+ public static final String CONTEXT_INITIALIZED =
"org.exoplatform.web.GenericHttpListener.contextInitialized";
+
+ /**
+ * The name of the "context destroyed" event
+ */
+ public static final String CONTEXT_DESTROYED =
"org.exoplatform.web.GenericHttpListener.contextDestroyed";
+
+ /**
+ * Logger.
+ */
+ private static Log log = ExoLogger.getLogger("portal:GenericHttpListener");
+
+ /**
+ * This method is called when a HTTP session of a Portal instance is created.
+ *
+ * In this method, we:
+ * 1) first get the portal instance name for which the session is created.
+ * 2) Put the portal instance in the Portal ThreadLocal
+ * 3) Broadcast the SESSION_CREATED event
+ * 4) Flush the {@link ThreadLocal} for the PortalContainer
+ */
+ @Override
+ protected void onSessionCreated(ExoContainer container, HttpSessionEvent event)
+ {
+ try
+ {
+ broadcast((PortalContainer)container, SESSION_CREATED, event);
+ }
+ catch (Exception ex)
+ {
+ log.error("Error on sessionCreated", ex);
+ }
+ }
+
+ /**
+ * This method is called when a HTTP session of a Portal instance is destroyed.
+ *
+ * In this method, we:
+ * 1) first get the portal instance name for which the session is created.
+ * 2) Put the portal instance in the Portal ThreadLocal
+ * 3) Broadcast the SESSION_DESTROYED event
+ * 4) Flush the {@link ThreadLocal} for the PortalContainer
+ */
+ @Override
+ protected void onSessionDestroyed(ExoContainer container, HttpSessionEvent event)
+ {
+ try
+ {
+ broadcast((PortalContainer)container, SESSION_DESTROYED, event);
+ }
+ catch (Exception ex)
+ {
+ log.error("Error on sessionDestroyed", ex);
+ }
+ }
+
+ /**
+ * This method is called when the {@link ServletContext} of the Portal is destroyed.
+ *
+ * In this method, we:
+ * 1) first get the portal instance name for which the session is created.
+ * 2) Put the portal instance in the Portal ThreadLocal
+ * 3) Broadcast the CONTEXT_DESTROYED event
+ * 4) Flush the {@link ThreadLocal} for the PortalContainer
+ */
+ public void contextDestroyed(ServletContextEvent event)
+ {
+ boolean hasBeenSet = false;
+ final ExoContainer oldContainer = ExoContainerContext.getCurrentContainer();
+ try
+ {
+ PortalContainer portalContainer = PortalContainer.getInstanceIfPresent();
+ if (portalContainer == null)
+ {
+ portalContainer =
PortalContainer.getCurrentInstance(event.getServletContext());
+ PortalContainer.setInstance(portalContainer);
+ hasBeenSet = true;
+ }
+ broadcast(portalContainer, CONTEXT_DESTROYED, event);
+ }
+ catch (Exception ex)
+ {
+ log.error("Error on contextDestroyed", ex);
+ }
+ finally
+ {
+ if (hasBeenSet)
+ {
+ PortalContainer.setInstance(null);
+ ExoContainerContext.setCurrentContainer(oldContainer);
+ }
+ }
+ }
+
+ /**
+ * This method is called when the {@link ServletContext} of the Portal is initialized.
+ *
+ * In this method, we:
+ * 1) first get the portal instance name for which the session is created.
+ * 2) Put the portal instance in the Portal ThreadLocal
+ * 3) Broadcast the CONTEXT_INITIALIZED event
+ * 4) Flush the {@link ThreadLocal} for the PortalContainer
+ */
+ public void contextInitialized(final ServletContextEvent event)
+ {
+ final PortalContainerPostInitTask task = new PortalContainerPostInitTask()
+ {
+ public void execute(ServletContext scontext, PortalContainer portalContainer)
+ {
+ try
+ {
+ broadcast(portalContainer, CONTEXT_INITIALIZED, event);
+ }
+ catch (Exception ex)
+ {
+ log.error("Error on contextInitialized", ex);
+ }
+ }
+ };
+ ServletContext ctx = event.getServletContext();
+ try
+ {
+ EnvSpecific.initThreadEnv(ctx);
+ RootContainer.getInstance().addInitTask(event.getServletContext(), task);
+ }
+ finally
+ {
+ EnvSpecific.cleanupThreadEnv(ctx);
+ }
+
+ }
+
+ /**
+ * @see
org.exoplatform.container.web.AbstractHttpSessionListener#requirePortalEnvironment()
+ */
+ @Override
+ protected boolean requirePortalEnvironment()
+ {
+ return true;
+ }
+
+ /**
+ * Allow the rest of the application to be notified when an HttpEvent happens
+ * @param portalContainer the related portal container
+ * @param eventName the name of the event to broadcast
+ * @param event the notification event
+ */
+ private <T extends EventObject> void broadcast(PortalContainer portalContainer,
String eventName, T event)
+ {
+ try
+ {
+ ListenerService listenerService =
+
(ListenerService)portalContainer.getComponentInstanceOfType(ListenerService.class);
+ listenerService.broadcast(eventName, portalContainer, event);
+ }
+ catch (Exception e)
+ {
+ log.warn("Cannot broadcast the event '" + eventName +
"'", e);
+ }
+ }
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/ExtensibleFilter.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/ExtensibleFilter.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/ExtensibleFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,115 @@
+/**
+ * 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.web.filter;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+
+/**
+ * This class allows the rest of the platform to define new filters thanks to the
external
+ * plugins.
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class ExtensibleFilter implements Filter
+{
+
+ /**
+ * List of all the sub filters
+ */
+ private volatile List<FilterDefinition> filters =
Collections.unmodifiableList(new ArrayList<FilterDefinition>());
+
+ /**
+ * Adds new {@link FilterDefinition}
+ */
+ public void addFilterDefinitions(FilterDefinitionPlugin plugin)
+ {
+ addFilterDefinitions(plugin.getFilterDefinitions());
+ }
+
+ /**
+ * Adds new {@link FilterDefinition}
+ */
+ void addFilterDefinitions(List<FilterDefinition> pluginFilters)
+ {
+ if (pluginFilters == null || pluginFilters.isEmpty())
+ {
+ // No filter to add
+ return;
+ }
+ synchronized (this)
+ {
+ List<FilterDefinition> result = new
ArrayList<FilterDefinition>(filters);
+ result.addAll(pluginFilters);
+ this.filters = Collections.unmodifiableList(result);
+ }
+ }
+
+ /**
+ * @see Filter#doFilter(javax.servlet.ServletRequest, javax.servlet.ServletResponse,
javax.servlet.FilterChain)
+ */
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ ExtensibleFilterChain efChain = new ExtensibleFilterChain(chain, filters);
+ efChain.doFilter(request, response);
+ }
+
+ private static class ExtensibleFilterChain implements FilterChain
+ {
+
+ private final FilterChain parentChain;
+
+ private final Iterator<FilterDefinition> filters;
+
+ private ExtensibleFilterChain(FilterChain parentChain, List<FilterDefinition>
filters)
+ {
+ this.parentChain = parentChain;
+ this.filters = filters.iterator();
+ }
+
+ public void doFilter(ServletRequest request, ServletResponse response) throws
IOException, ServletException
+ {
+ String path = ((HttpServletRequest)request).getRequestURI();
+ while (filters.hasNext())
+ {
+ FilterDefinition filterDef = filters.next();
+ if (filterDef.getMapping().match(path))
+ {
+ filterDef.getFilter().doFilter(request, response, this);
+ return;
+ }
+ }
+ parentChain.doFilter(request, response);
+ }
+ }
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/Filter.java
===================================================================
--- portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/Filter.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/Filter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,46 @@
+/**
+ * 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.web.filter;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * This interface defines a Filter that cans be added to the {@link ExtensibleFilter}
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public interface Filter
+{
+ /**
+ * The <code>doFilter</code> method of the Filter is called by the {@link
ExtensibleFilter}
+ * each time a request/response pair is passed through the chain due to a client
request
+ * for a resource at the end of the chain.
+ */
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException;
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinition.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinition.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinition.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,126 @@
+/**
+ * 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.web.filter;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/**
+ * This class defined all the variables needed to define a {@link Filter}
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class FilterDefinition
+{
+
+ /**
+ * The filter.
+ */
+ private Filter filter;
+
+ /**
+ * The filter mapping.
+ */
+ private volatile FilterMapping mapping;
+
+ /**
+ * The list of patterns that will defined the {@link FilterMapping}
+ */
+ private List<String> patterns;
+
+ public FilterDefinition()
+ {
+ }
+
+ public FilterDefinition(Filter filter, List<String> patterns)
+ {
+ this.filter = filter;
+ this.patterns = patterns;
+ }
+
+ public Filter getFilter()
+ {
+ return filter;
+ }
+
+ public FilterMapping getMapping()
+ {
+ if (mapping == null)
+ {
+ synchronized (this)
+ {
+ if (mapping == null)
+ {
+ this.mapping = new PatternMapping(patterns);
+ this.patterns = null;
+ }
+ }
+ }
+ return mapping;
+ }
+
+ /**
+ * This class is used to defined a mapping based on a list of regular expression
+ */
+ private static class PatternMapping implements FilterMapping
+ {
+
+ /**
+ * the list of regular expressions
+ */
+ private final List<Pattern> patterns;
+
+ private PatternMapping(List<String> strPatterns)
+ {
+ if (strPatterns == null || strPatterns.isEmpty())
+ {
+ throw new IllegalArgumentException("The list of patterns cannot be
empty");
+ }
+ this.patterns = new ArrayList<Pattern>(strPatterns.size());
+ for (String sPattern : strPatterns)
+ {
+ patterns.add(Pattern.compile(sPattern));
+ }
+ }
+
+ /**
+ * @return <code>true</code> if at least one pattern matches
+ */
+ public boolean match(String path)
+ {
+ for (int i = 0, length = patterns.size(); i < length; i++)
+ {
+ Pattern pattern = patterns.get(i);
+ Matcher matcher = pattern.matcher(path);
+ if (matcher.matches())
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ }
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinitionPlugin.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinitionPlugin.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterDefinitionPlugin.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,52 @@
+/**
+ * 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.web.filter;
+
+import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.container.xml.InitParams;
+
+import java.util.List;
+
+/**
+ * This class is used to add new {@link FilterDefinition}
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class FilterDefinitionPlugin extends BaseComponentPlugin
+{
+
+ private final InitParams params;
+
+ public FilterDefinitionPlugin(InitParams params)
+ {
+ this.params = params;
+ }
+
+ /**
+ * @return the list of enclosed {@link FilterDefinition}
+ */
+ public List<FilterDefinition> getFilterDefinitions()
+ {
+ return params.getObjectParamValues(FilterDefinition.class);
+ }
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterMapping.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterMapping.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/FilterMapping.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,37 @@
+/**
+ * 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.web.filter;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public interface FilterMapping
+{
+
+ /**
+ * Indicates if the current path matches with the current mapping
+ * @param path the path to check
+ * @return <code>true</code> if it matches, <code>false</code>
otherwise.
+ */
+ public boolean match(String path);
+}
Added:
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/GenericFilter.java
===================================================================
---
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/GenericFilter.java
(rev 0)
+++
portal/trunk/component/web/api/src/main/java/org/exoplatform/web/filter/GenericFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,69 @@
+/**
+ * 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.web.filter;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.web.AbstractFilter;
+
+import java.io.IOException;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+/**
+ * This filter allows the rest of the platform to add their own filters without changing
the web.xml
+ * file. It is based on {@link ExtensibleFilter} which is a component that supports
plugin.
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class GenericFilter extends AbstractFilter
+{
+
+ /**
+ * @see javax.servlet.Filter#destroy()
+ */
+ public void destroy()
+ {
+ }
+
+ /**
+ * This filter calls <code>doFilter</code> of the {@link ExtensibleFilter}
of
+ * the current eXo container if it cans be found otherwise it releases filter
+ */
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ ExoContainer container = getContainer();
+ ExtensibleFilter filter =
(ExtensibleFilter)container.getComponentInstanceOfType(ExtensibleFilter.class);
+ if (filter == null)
+ {
+ chain.doFilter(request, response);
+ }
+ else
+ {
+ filter.doFilter(request, response, chain);
+ }
+ }
+}
Copied: portal/trunk/component/web/api/src/main/java/org/exoplatform/web/resource (from
rev 3698, portal/trunk/component/web/src/main/java/org/exoplatform/web/resource)
Added: portal/trunk/component/web/api/src/test/java/conf/portal/test-configuration.xml
===================================================================
--- portal/trunk/component/web/api/src/test/java/conf/portal/test-configuration.xml
(rev 0)
+++
portal/trunk/component/web/api/src/test/java/conf/portal/test-configuration.xml 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+ <component>
+ <key>org.exoplatform.download.DownloadService</key>
+ <type>org.exoplatform.download.DownloadService</type>
+ <init-params>
+ <value-param>
+ <name>download.resource.cache.size</name>
+ <description>Maximun number of the download can be in the
cache</description>
+ <value>3</value>
+ </value-param>
+ </init-params>
+ </component>
+</configuration>
Added:
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/command/TestCommandHandler.java
===================================================================
---
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/command/TestCommandHandler.java
(rev 0)
+++
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/command/TestCommandHandler.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,98 @@
+/**
+ * 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.web.command;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+import org.exoplatform.web.WebAppController;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Nhu Dinh Thuan
+ * nhudinhthuan(a)exoplatform.com
+ * Mar 26, 2007
+ */
+public class TestCommandHandler extends AbstractGateInTest
+{
+
+ public TestCommandHandler(String name)
+ {
+ super(name);
+ }
+
+ public void testCommandHandler() throws Exception
+ {
+ CommandHandler handler = new CommandHandler();
+ Map<String, Object> props = new HashMap<String, Object>();
+ props.put("intProp", "10");
+ props.put("stringProp", "welcome to eXo");
+ props.put("doubleValues", new String[]{"10.0",
"-6.7", "7.0"});
+ props.put("booleanValue", "true");
+ Command command =
handler.createCommand("org.exoplatform.web.command.TestCommandHandler$CommandTest2",
props);
+ command.execute(null, null, null);
+ }
+
+ static public class CommandTest2 extends CommandTest
+ {
+
+ private boolean booleanValue = false;
+
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res)
+ throws Exception
+ {
+ super.execute(controller, req, res);
+ System.out.println(" \n\n\n === >" + booleanValue +
"\n\n");
+ }
+ }
+
+ static public class CommandTest extends Command
+ {
+
+ private double[] doubleValues;
+
+ private Integer intProp;
+
+ private String stringProp;
+
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res)
+ throws Exception
+ {
+ System.out.println("\n\n");
+ System.out.println("int prop : " + intProp);
+ System.out.println("String prop : " + stringProp);
+ for (double ele : doubleValues)
+ {
+ System.out.println("===== > " + ele);
+ }
+ System.out.println("\n\n");
+ }
+
+ public void setStringProp(String value)
+ {
+ System.out.println("\n\n invoke setter " + value +
"\n\n");
+ stringProp = value;
+ }
+ }
+}
Added:
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestExtensibleFilter.java
===================================================================
---
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestExtensibleFilter.java
(rev 0)
+++
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestExtensibleFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,606 @@
+/**
+ * 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.web.filter;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.Principal;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.servlet.FilterChain;
+import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
+import javax.servlet.ServletInputStream;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class TestExtensibleFilter extends AbstractGateInTest
+{
+
+ public void testDoFilter() throws IOException, ServletException
+ {
+ ExtensibleFilter exFilter = new ExtensibleFilter();
+ MockFilterOKTF mockFilterOKTF = new MockFilterOKTF();
+ MockFilterOKWTF mockFilterOKWTF = new MockFilterOKWTF();
+ MockFilterChain chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF)));
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertTrue(mockFilterOKWTF.end);
+ assertTrue(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKO())));
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertTrue(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKOIO())));
+ try
+ {
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ fail("IOException is expected");
+ }
+ catch (IOException e)
+ {
+ }
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertFalse(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKOSE())));
+ try
+ {
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ fail("ServletException is expected");
+ }
+ catch (ServletException e)
+ {
+ }
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertFalse(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKORE())));
+ try
+ {
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ fail("RuntimeException is expected");
+ }
+ catch (RuntimeException e)
+ {
+ }
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertFalse(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKOER())));
+ try
+ {
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ fail("Error is expected");
+ }
+ catch (Error e)
+ {
+ }
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertFalse(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ exFilter = new ExtensibleFilter();
+ mockFilterOKTF = new MockFilterOKTF();
+ mockFilterOKWTF = new MockFilterOKWTF();
+ MockFilterOKTF mockFilterOKTF2 = new MockFilterOKTF();
+ chain = new MockFilterChain();
+ exFilter.addFilterDefinitions(Arrays.asList(getFilterDefinition(mockFilterOKTF),
+ getFilterDefinition(mockFilterOKWTF), getFilterDefinition(new
MockFilterKOIO()),
+ getFilterDefinition(mockFilterOKTF2)));
+ try
+ {
+ exFilter.doFilter(new MockServletRequest(), null, chain);
+ fail("IOException is expected");
+ }
+ catch (IOException e)
+ {
+ }
+ assertTrue(mockFilterOKTF.start);
+ assertTrue(mockFilterOKTF.end);
+ assertTrue(mockFilterOKWTF.start);
+ assertFalse(mockFilterOKWTF.end);
+ assertFalse(chain.called);
+ assertFalse(mockFilterOKTF2.start);
+ assertFalse(mockFilterOKTF2.end);
+ }
+
+ private FilterDefinition getFilterDefinition(Filter filter)
+ {
+ return new FilterDefinition(filter, Collections.singletonList(".*"));
+ }
+
+ private static class MockFilterChain implements FilterChain
+ {
+ private boolean called;
+
+ public void doFilter(ServletRequest request, ServletResponse response) throws
IOException, ServletException
+ {
+ called = true;
+ }
+ }
+
+ private static class MockFilterOKTF implements Filter
+ {
+
+ private boolean start;
+
+ private boolean end;
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ try
+ {
+ start = true;
+ chain.doFilter(request, response);
+ }
+ finally
+ {
+ end = true;
+ }
+ }
+ }
+
+ private static class MockFilterOKWTF implements Filter
+ {
+
+ private boolean start;
+
+ private boolean end;
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ start = true;
+ chain.doFilter(request, response);
+ end = true;
+ }
+ }
+
+ private static class MockFilterKO implements Filter
+ {
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ }
+ }
+
+ private static class MockFilterKOIO implements Filter
+ {
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ throw new IOException();
+ }
+ }
+
+ private static class MockFilterKOSE implements Filter
+ {
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ throw new ServletException();
+ }
+ }
+
+ private static class MockFilterKORE implements Filter
+ {
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ throw new RuntimeException();
+ }
+ }
+
+ private static class MockFilterKOER implements Filter
+ {
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException,
+ ServletException
+ {
+ throw new Error();
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ private static class MockServletRequest implements HttpServletRequest
+ {
+
+ public String getAuthType()
+ {
+
+ return null;
+ }
+
+ public String getContextPath()
+ {
+
+ return null;
+ }
+
+ public Cookie[] getCookies()
+ {
+
+ return null;
+ }
+
+ public long getDateHeader(String name)
+ {
+
+ return 0;
+ }
+
+ public String getHeader(String name)
+ {
+
+ return null;
+ }
+
+ public Enumeration getHeaderNames()
+ {
+
+ return null;
+ }
+
+ public Enumeration getHeaders(String name)
+ {
+
+ return null;
+ }
+
+ public int getIntHeader(String name)
+ {
+
+ return 0;
+ }
+
+ public String getMethod()
+ {
+
+ return null;
+ }
+
+ public String getPathInfo()
+ {
+ return null;
+ }
+
+ public String getPathTranslated()
+ {
+
+ return null;
+ }
+
+ public String getQueryString()
+ {
+
+ return null;
+ }
+
+ public String getRemoteUser()
+ {
+
+ return null;
+ }
+
+ public String getRequestURI()
+ {
+
+ return "/";
+ }
+
+ public StringBuffer getRequestURL()
+ {
+
+ return null;
+ }
+
+ public String getRequestedSessionId()
+ {
+
+ return null;
+ }
+
+ public String getServletPath()
+ {
+
+ return null;
+ }
+
+ public HttpSession getSession()
+ {
+
+ return null;
+ }
+
+ public HttpSession getSession(boolean create)
+ {
+
+ return null;
+ }
+
+ public Principal getUserPrincipal()
+ {
+
+ return null;
+ }
+
+ public boolean isRequestedSessionIdFromCookie()
+ {
+
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromURL()
+ {
+
+ return false;
+ }
+
+ public boolean isRequestedSessionIdFromUrl()
+ {
+
+ return false;
+ }
+
+ public boolean isRequestedSessionIdValid()
+ {
+
+ return false;
+ }
+
+ public boolean isUserInRole(String role)
+ {
+
+ return false;
+ }
+
+ public Object getAttribute(String name)
+ {
+
+ return null;
+ }
+
+ public Enumeration getAttributeNames()
+ {
+
+ return null;
+ }
+
+ public String getCharacterEncoding()
+ {
+
+ return null;
+ }
+
+ public int getContentLength()
+ {
+
+ return 0;
+ }
+
+ public String getContentType()
+ {
+
+ return null;
+ }
+
+ public ServletInputStream getInputStream() throws IOException
+ {
+
+ return null;
+ }
+
+ public String getLocalAddr()
+ {
+
+ return null;
+ }
+
+ public String getLocalName()
+ {
+
+ return null;
+ }
+
+ public int getLocalPort()
+ {
+
+ return 0;
+ }
+
+ public Locale getLocale()
+ {
+
+ return null;
+ }
+
+ public Enumeration getLocales()
+ {
+
+ return null;
+ }
+
+ public String getParameter(String name)
+ {
+
+ return null;
+ }
+
+ public Map getParameterMap()
+ {
+
+ return null;
+ }
+
+ public Enumeration getParameterNames()
+ {
+
+ return null;
+ }
+
+ public String[] getParameterValues(String name)
+ {
+
+ return null;
+ }
+
+ public String getProtocol()
+ {
+
+ return null;
+ }
+
+ public BufferedReader getReader() throws IOException
+ {
+
+ return null;
+ }
+
+ public String getRealPath(String path)
+ {
+
+ return null;
+ }
+
+ public String getRemoteAddr()
+ {
+
+ return null;
+ }
+
+ public String getRemoteHost()
+ {
+
+ return null;
+ }
+
+ public int getRemotePort()
+ {
+
+ return 0;
+ }
+
+ public RequestDispatcher getRequestDispatcher(String path)
+ {
+
+ return null;
+ }
+
+ public String getScheme()
+ {
+
+ return null;
+ }
+
+ public String getServerName()
+ {
+
+ return null;
+ }
+
+ public int getServerPort()
+ {
+
+ return 0;
+ }
+
+ public boolean isSecure()
+ {
+
+ return false;
+ }
+
+ public void removeAttribute(String name)
+ {
+
+ }
+
+ public void setAttribute(String name, Object o)
+ {
+
+ }
+
+ public void setCharacterEncoding(String env) throws UnsupportedEncodingException
+ {
+
+ }
+
+ }
+}
Added:
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestFilterDefinition.java
===================================================================
---
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestFilterDefinition.java
(rev 0)
+++
portal/trunk/component/web/api/src/test/java/org/exoplatform/web/filter/TestFilterDefinition.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,64 @@
+/**
+ * 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.web.filter;
+
+import org.exoplatform.component.test.AbstractGateInTest;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 25 sept. 2009
+ */
+public class TestFilterDefinition extends AbstractGateInTest
+{
+
+ public void testMatch()
+ {
+ FilterDefinition def = new FilterDefinition(null, null);
+ try
+ {
+ def.getMapping();
+ fail("An IllegalArgumentException is expected");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ def = new FilterDefinition(null, new ArrayList<String>());
+ try
+ {
+ def.getMapping();
+ fail("An IllegalArgumentException is expected");
+ }
+ catch (IllegalArgumentException e)
+ {
+ }
+ def = new FilterDefinition(null, Arrays.asList(".*\\.gif"));
+ assertTrue(def.getMapping().match("/foo/foo.gif"));
+ assertFalse(def.getMapping().match("/foo/foo.giff"));
+ def = new FilterDefinition(null, Arrays.asList(".*\\.gif",
".*\\.giff"));
+ assertTrue(def.getMapping().match("/foo/foo.gif"));
+ assertTrue(def.getMapping().match("/foo/foo.giff"));
+ assertFalse(def.getMapping().match("/foo/foo.giffo"));
+ }
+}
Added: portal/trunk/component/web/api/src/test/resources/TestJSonFormat.html
===================================================================
--- portal/trunk/component/web/api/src/test/resources/TestJSonFormat.html
(rev 0)
+++ portal/trunk/component/web/api/src/test/resources/TestJSonFormat.html 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,63 @@
+<!--
+
+ 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.
+
+-->
+
+<html>
+ <head>
+ <script type="text/javascript">
+ function testJSonFormat() {
+ text = "{ " +
+ " 'name': 'Thuy', " +
+ " 'scores': [34, 78, 56, 43, 90], " +
+ " 'index': 24, " +
+ " 'isPass': true, " +
+ " 'schools': [ " +
+ " 'school1', " +
+ " 'school2' " +
+ " ], " +
+ " 'accounts': [ " +
+ " { " +
+ " 'username': 'ammi', " +
+ " 'password': '1234' " +
+ " }, " +
+ " { "+
+ " 'username': 'sara', " +
+ " 'password': '34543mf' " +
+ " }, " +
+ " { " +
+ " 'username': 'bim', " +
+ " 'password': 'dsfd4' " +
+ " } " +
+ " ] " +
+ "} ";
+ var json;
+ try{
+ eval("json="+text);
+ alert(json.name +" : "+json.scores[2]);
+ }catch(err){
+ alert(err);
+ }
+ }
+ </script>
+ </head>
+ <body onload="testJSonFormat();">
+ </body>
+</html>
+
Added: portal/trunk/component/web/controller/pom.xml
===================================================================
--- portal/trunk/component/web/controller/pom.xml (rev 0)
+++ portal/trunk/component/web/controller/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -0,0 +1,47 @@
+<!--
+ ~ 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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn Portal Component Web Controller</name>
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.resources</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebAppController.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,151 @@
+/**
+ * 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.web;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.component.ComponentRequestLifecycle;
+import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.web.application.Application;
+import org.exoplatform.web.command.CommandHandler;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 21, 2007
+ *
+ * The WebAppController is the entry point of the eXo web framework
+ *
+ * It also stores WebRequestHandlers, Attributes and deployed Applications
+ *
+ */
+public class WebAppController
+{
+
+ protected static Log log = ExoLogger.getLogger("portal:WebAppController");
+
+ private HashMap<String, Object> attributes_;
+
+ private HashMap<String, Application> applications_;
+
+ private HashMap<String, WebRequestHandler> handlers_;
+
+ /**
+ * The WebAppControler along with the PortalRequestHandler defined in the init()
method of the
+ * PortalController servlet (controller.register(new PortalRequestHandler())) also add
the
+ * CommandHandler object that will listen for the incoming /command path in the URL
+ *
+ * @throws Exception
+ */
+ public WebAppController() throws Exception
+ {
+ applications_ = new HashMap<String, Application>();
+ attributes_ = new HashMap<String, Object>();
+ handlers_ = new HashMap<String, WebRequestHandler>();
+ register(new CommandHandler());
+ }
+
+ @SuppressWarnings("unused")
+ public Object getAttribute(String name, Object value)
+ {
+ return attributes_.get(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public <T extends Application> T getApplication(String appId)
+ {
+ return (T)applications_.get(appId);
+ }
+
+ public List<Application> getApplicationByType(String type)
+ {
+ List<Application> applications = new ArrayList<Application>();
+ for (Application app : applications_.values())
+ {
+ if (app.getApplicationType().equals(type))
+ applications.add(app);
+ }
+ return applications;
+ }
+
+ public void removeApplication(String appId)
+ {
+ applications_.remove(appId);
+ }
+
+ public void addApplication(Application app)
+ {
+ applications_.put(app.getApplicationId(), app);
+ }
+
+ public void register(WebRequestHandler handler) throws Exception
+ {
+ for (String path : handler.getPath())
+ handlers_.put(path, handler);
+ }
+
+ public void unregister(String[] paths)
+ {
+ for (String path : paths)
+ handlers_.remove(path);
+ }
+
+ /**
+ * This is the first method - in the eXo web framework - reached by incoming HTTP
request, it acts like a
+ * servlet service() method
+ *
+ * According to the servlet path used the correct handler is selected and then
executed.
+ *
+ * The event "exo.application.portal.start-http-request" and
"exo.application.portal.end-http-request" are also sent
+ * through the ListenerService and several listeners may listen to it.
+ *
+ * Finally a WindowsInfosContainer object using a ThreadLocal (from the
portlet-container product) is created
+ */
+ public void service(HttpServletRequest req, HttpServletResponse res) throws Exception
+ {
+ WebRequestHandler handler = handlers_.get(req.getServletPath());
+ if (log.isDebugEnabled())
+ {
+ log.debug("Servlet Path: " + req.getServletPath());
+ log.debug("Handler used for this path: " + handler);
+ }
+ if (handler != null)
+ {
+ ExoContainer portalContainer = ExoContainerContext.getCurrentContainer();
+ RequestLifeCycle.begin(portalContainer);
+ try
+ {
+ handler.execute(this, req, res);
+ }
+ finally
+ {
+ RequestLifeCycle.end();
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/WebRequestHandler.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,53 @@
+/**
+ * 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.web;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 21, 2007
+ *
+ * Abstract calss that one must implement if it want to provide a dedicated handler for a
custom servlet path
+ *
+ * In case of portal the path is /portal but you could return your own from the getPath()
method and hence the
+ * WebAppController would use your own handler
+ *
+ * The execute method is to be overideen and the buisness logic should be handled here
+ */
+abstract public class WebRequestHandler
+{
+
+ public void onInit(WebAppController controller) throws Exception
+ {
+
+ }
+
+ abstract public String[] getPath();
+
+ abstract public void execute(WebAppController app, HttpServletRequest req,
HttpServletResponse res) throws Exception;
+
+ public void onDestroy(WebAppController controler) throws Exception
+ {
+
+ }
+
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Application.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Application.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Application.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,115 @@
+/**
+ * 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.web.application;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.container.component.BaseComponentPlugin;
+import org.exoplatform.resolver.ApplicationResourceResolver;
+
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Created by The eXo Platform SAS
+ * May 7, 2006
+ */
+abstract public class Application extends BaseComponentPlugin
+{
+
+ final static public String JSR168_APPLICATION_TYPE = "jsr168Application";
+
+ final static public String EXO_PORTLET_TYPE = "portlet";
+
+ final static public String EXO_PORTAL_TYPE = "eXoPortal";
+
+ final static public String EXO_GADGET_TYPE = "eXoGadget";
+
+ public final static String WSRP_TYPE = "wsrp";
+
+ private List<ApplicationLifecycle> lifecycleListeners_;
+
+ private ApplicationResourceResolver resourceResolver_;
+
+ private Hashtable<String, Object> attributes_ = new Hashtable<String,
Object>();
+
+ abstract public String getApplicationId();
+
+ abstract public String getApplicationType();
+
+ abstract public String getApplicationGroup();
+
+ abstract public String getApplicationName();
+
+ final public ApplicationResourceResolver getResourceResolver()
+ {
+ return resourceResolver_;
+ }
+
+ final public void setResourceResolver(ApplicationResourceResolver resolver)
+ {
+ resourceResolver_ = resolver;
+ }
+
+ final public Object getAttribute(String name)
+ {
+ return attributes_.get(name);
+ }
+
+ final public void setAttribute(String name, Object value)
+ {
+ attributes_.put(name, value);
+ }
+
+ abstract public ResourceBundle getResourceBundle(Locale locale) throws Exception;
+
+ abstract public ResourceBundle getOwnerResourceBundle(String username, Locale locale)
throws Exception;
+
+ public ExoContainer getApplicationServiceContainer()
+ {
+ return ExoContainerContext.getCurrentContainer();
+ }
+
+ final public List<ApplicationLifecycle> getApplicationLifecycle()
+ {
+ return lifecycleListeners_;
+ }
+
+ final public void setApplicationLifecycle(List<ApplicationLifecycle> list)
+ {
+ lifecycleListeners_ = list;
+ }
+
+ public void onInit() throws Exception
+ {
+ for (ApplicationLifecycle lifecycle : lifecycleListeners_)
+ {
+ lifecycle.onInit(this);
+ }
+ }
+
+ public void onDestroy() throws Exception
+ {
+ for (ApplicationLifecycle lifecycle : lifecycleListeners_)
+ lifecycle.onDestroy(this);
+ }
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationLifecycle.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationLifecycle.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationLifecycle.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,41 @@
+/**
+ * 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.web.application;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Tuan Nguyen
+ * tuan08(a)users.sourceforge.net
+ * May 9, 2006
+ */
+public interface ApplicationLifecycle<E extends RequestContext>
+{
+
+ public void onInit(Application app) throws Exception;
+
+ public void onStartRequest(Application app, E context) throws Exception;
+
+ public void onFailRequest(Application app, E context, RequestFailure failureType)
throws Exception;
+
+ public void onEndRequest(Application app, E context) throws Exception;
+
+ public void onDestroy(Application app) throws Exception;
+
+}
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationMessage.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,72 @@
+/**
+ * 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.web.application;
+
+import java.io.Serializable;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Dang Van Minh
+ * minhdv81(a)yahoo.com
+ * Jun 7, 2006
+ */
+public class ApplicationMessage implements Serializable
+{
+ final public static int ERROR = 0, WARNING = 1, INFO = 2;
+
+ private int type_ = INFO;
+
+ private String messageKey_;
+
+ private Object[] messageArgs_;
+
+ public ApplicationMessage(String key, Object[] args)
+ {
+ messageKey_ = key;
+ messageArgs_ = args;
+ }
+
+ public ApplicationMessage(String key, Object[] args, int type)
+ {
+ this(key, args);
+ type_ = type;
+ }
+
+ public String getMessageKey()
+ {
+ return messageKey_;
+ }
+
+ public Object[] getMessageAruments()
+ {
+ return messageArgs_;
+ }
+
+ public int getType()
+ {
+ return type_;
+ }
+
+ public void setType(int type)
+ {
+ this.type_ = type;
+ }
+
+}
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationSession.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationSession.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/ApplicationSession.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,36 @@
+/**
+ * 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.web.application;
+
+/**
+ * todo (julien) : remove that class that seem useless
+ */
+abstract public class ApplicationSession
+{
+ abstract public Object getAttribute(String name) throws Exception;
+
+ abstract public void setAttribute(String name, Object value, boolean replicated)
throws Exception;
+
+ abstract public Object getUserAttribute(String name) throws Exception;
+
+ abstract public void setUserAttribute(String name, Object value, boolean replicated)
throws Exception;
+
+ abstract public String getId();
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Parameter.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Parameter.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/Parameter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,60 @@
+/**
+ * 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.web.application;
+
+/**
+ * Author : Nhu Dinh Thuan
+ * nhudinhthuan(a)exoplatform.com
+ * Oct 26, 2006
+ */
+public class Parameter
+{
+
+ private String name;
+
+ private String value;
+
+ public Parameter(String name, String value)
+ {
+ this.name = name;
+ this.value = value;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+
+}
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestContext.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestContext.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestContext.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,171 @@
+/**
+ * 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.web.application;
+
+import org.exoplatform.services.resources.Orientation;
+
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.ResourceBundle;
+
+/**
+ * Created by The eXo Platform SAS
+ * May 7, 2006
+ *
+ * This abstract class is a wrapper on top of the request information such as the Locale
in use,
+ * the application (for instance PortalApplication, PortletApplication...), an access to
the JavascriptManager
+ * as well as a reference to the URLBuilder in use.
+ *
+ * It also contains a ThreadLocal object for an easy access.
+ *
+ * Context can be nested and hence a getParentAppRequestContext() is also available
+ *
+ */
+abstract public class RequestContext
+{
+
+ final static public String ACTION = "op";
+
+ private static ThreadLocal<RequestContext> tlocal_ = new
ThreadLocal<RequestContext>();
+
+ private Application app_;
+
+ protected RequestContext parentAppRequestContext_;
+
+ private Map<String, Object> attributes;
+
+ public RequestContext(Application app)
+ {
+ app_ = app;
+ }
+
+ public Application getApplication()
+ {
+ return app_;
+ }
+
+ public Locale getLocale()
+ {
+ return parentAppRequestContext_.getLocale();
+ }
+
+ /**
+ * Returns the orientation for the current request.
+ *
+ * @return the orientation
+ */
+ public abstract Orientation getOrientation();
+
+ public ResourceBundle getApplicationResourceBundle()
+ {
+ return null;
+ }
+
+ abstract public String getRequestParameter(String name);
+
+ abstract public String[] getRequestParameterValues(String name);
+
+ public JavascriptManager getJavascriptManager()
+ {
+ return getParentAppRequestContext().getJavascriptManager();
+ }
+
+ abstract public URLBuilder<?> getURLBuilder();
+
+ public String getRemoteUser()
+ {
+ return parentAppRequestContext_.getRemoteUser();
+ }
+
+ public boolean isUserInRole(String roleUser)
+ {
+ return parentAppRequestContext_.isUserInRole(roleUser);
+ }
+
+ abstract public boolean useAjax();
+
+ public boolean getFullRender()
+ {
+ return true;
+ }
+
+ public ApplicationSession getApplicationSession()
+ {
+ throw new RuntimeException("This method is not supported");
+ }
+
+ public Writer getWriter() throws Exception
+ {
+ return parentAppRequestContext_.getWriter();
+ }
+
+ public void setWriter (Writer writer)
+ {
+ parentAppRequestContext_.setWriter(writer);
+ }
+
+ final public Object getAttribute(String name)
+ {
+ if (attributes == null)
+ return null;
+ return attributes.get(name);
+ }
+
+ final public void setAttribute(String name, Object value)
+ {
+ if (attributes == null)
+ attributes = new HashMap<String, Object>();
+ attributes.put(name, value);
+ }
+
+ final public Object getAttribute(Class type)
+ {
+ return getAttribute(type.getName());
+ }
+
+ final public void setAttribute(Class type, Object value)
+ {
+ setAttribute(type.getName(), value);
+ }
+
+ public RequestContext getParentAppRequestContext()
+ {
+ return parentAppRequestContext_;
+ }
+
+ public void setParentAppRequestContext(RequestContext context)
+ {
+ parentAppRequestContext_ = context;
+ }
+
+ @SuppressWarnings("unchecked")
+ public static <T extends RequestContext> T getCurrentInstance()
+ {
+ return (T)tlocal_.get();
+ }
+
+ public static void setCurrentInstance(RequestContext ctx)
+ {
+ tlocal_.set(ctx);
+ }
+
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestFailure.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestFailure.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/RequestFailure.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,29 @@
+/*
+ * 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.web.application;
+
+/**
+ * @author <a href="mailto:hoang281283@gmail.com">Minh Hoang
TO</a>
+ * @version $Id$
+ *
+ */
+public enum RequestFailure {
+
+ IO_FAILURE, CONCURRENCY_FAILURE
+}
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/URLBuilder.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/URLBuilder.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/application/URLBuilder.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,129 @@
+/**
+ * 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.web.application;
+
+import java.net.URLEncoder;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 29, 2007
+ */
+abstract public class URLBuilder<T>
+{
+
+ protected String baseURL_;
+
+ public URLBuilder(String baseURL)
+ {
+ baseURL_ = baseURL;
+ }
+
+ public String getBaseURL()
+ {
+ return baseURL_;
+ }
+
+ public void setBaseURL(String url)
+ {
+ baseURL_ = url;
+ }
+
+ public String createURL(String action)
+ {
+ return createURL(action, (Parameter[])null);
+ }
+
+ abstract public String createURL(String action, Parameter[] params);
+
+ public String createURL(String action, String objectId)
+ {
+ return createURL(action, objectId, (Parameter[])null);
+ }
+
+ abstract public String createURL(String action, String objectId, Parameter[] params);
+
+ public String createURL(T targetComponent, String action, String targetBeanId)
+ {
+ return createURL(targetComponent, action, null, targetBeanId, (Parameter[])null);
+ }
+
+ public String createAjaxURL(T targetComponent, String action, String targetBeanId)
+ {
+ return createAjaxURL(targetComponent, action, null, targetBeanId,
(Parameter[])null);
+ }
+
+ public String createAjaxURL(T targetComponent, String action, String confirm, String
targetBeanId)
+ {
+ return createAjaxURL(targetComponent, action, confirm, targetBeanId,
(Parameter[])null);
+ }
+
+ public String createAjaxURL(T targetComponent, String action, String confirm, String
targetBeanId, Parameter[] params)
+ {
+ StringBuilder builder = new StringBuilder("javascript:");
+ if (confirm != null && confirm.length() > 0)
+ {
+
builder.append("if(confirm('").append(confirm.replaceAll("'",
"\\\\'")).append("'))");
+ }
+ builder.append("ajaxGet('");
+ if (targetBeanId != null)
+ {
+ try
+ {
+ targetBeanId = URLEncoder.encode(targetBeanId, "utf-8");
+ }
+ catch (Exception e)
+ {
+ System.err.println(e.toString());
+ }
+ }
+ createURL(builder, targetComponent, action, targetBeanId, params);
+ builder.append("&ajaxRequest=true')");
+ return builder.toString();
+ }
+
+ public String createURL(T targetComponent, String action, String confirm, String
targetBeanId, Parameter[] params)
+ {
+ StringBuilder builder = new StringBuilder();
+ boolean hasConfirm = confirm != null && confirm.length() > 0;
+ if (hasConfirm)
+ {
+
builder.append("javascript:if(confirm('").append(confirm.replaceAll("'",
"\\\\'")).append("'))");
+ builder.append("window.location=\'");
+ }
+ if (targetBeanId != null)
+ {
+ try
+ {
+ targetBeanId = URLEncoder.encode(targetBeanId, "utf-8");
+ }
+ catch (Exception e)
+ {
+ System.err.println(e.toString());
+ }
+ }
+ createURL(builder, targetComponent, action, targetBeanId, params);
+ if (hasConfirm)
+ builder.append("\';");
+ return builder.toString();
+ }
+
+ abstract protected void createURL(StringBuilder builder, T targetComponent, String
action, String targetBeanId,
+ Parameter[] params);
+}
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/Command.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/Command.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/Command.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,43 @@
+/**
+ * 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.web.command;
+
+import org.exoplatform.web.WebAppController;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Tuan Nguyen
+ * tuan.nguyen(a)exoplatform.com
+ * May 22, 2007
+ */
+abstract public class Command
+{
+
+ public String[] getRequiredMemberships()
+ {
+ return null;
+ }
+
+ abstract public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res)
+ throws Exception;
+}
\ No newline at end of file
Added:
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/CommandHandler.java
===================================================================
---
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/CommandHandler.java
(rev 0)
+++
portal/trunk/component/web/controller/src/main/java/org/exoplatform/web/command/CommandHandler.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,195 @@
+/**
+ * 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.web.command;
+
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.WebRequestHandler;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.rmi.activation.UnknownObjectException;
+import java.util.Iterator;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SAS
+ * Mar 21, 2007
+ */
+public class CommandHandler extends WebRequestHandler
+{
+
+ public String[] getPath()
+ {
+ return new String[]{"/command"};
+ }
+
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ {
+ Map props = req.getParameterMap();
+ String type = req.getParameter("type");
+ if (type == null || type.trim().length() < 1)
+ throw new NullPointerException("Unknown type command handler");
+ Command command = createCommand(type, props);
+ if (command == null)
+ throw new UnknownObjectException("Unknown command handler with type is
" + type);
+ command.execute(controller, req, res);
+ }
+
+ /**
+ * This method should use the java reflection to create the command object according
to the command
+ * type, then populate the command properties
+ *
+ * @param type The command class type
+ * @param props list of the properties that should be set in the command object
+ * @return The command object instance
+ * @throws Exception
+ */
+ @SuppressWarnings("unchecked")
+ public Command createCommand(String type, Map props) throws Exception
+ {
+ ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
+ Class<?> clazz = classLoader.loadClass(type);
+ Object object = clazz.newInstance();
+ Iterator<Object> iter = props.keySet().iterator();
+ while (iter.hasNext())
+ {
+ Object key = iter.next();
+ Field field = getField(clazz, key.toString());
+ if (field == null)
+ continue;
+ setValue(object, field, props.get(key));
+ }
+ return (Command)object;
+ }
+
+ private final void setValue(Object bean, Field field, Object value) throws Exception
+ {
+ Class type = field.getType();
+ if (type.isArray() && !value.getClass().isArray())
+ {
+ value = toValues(type, new Object[]{value});
+ }
+ else if (type.isArray() && value.getClass().isArray())
+ {
+ value = toValues(type, value);
+ }
+ else
+ {
+ if (!type.isArray() && value.getClass().isArray())
+ value = Array.get(value, 0);
+ value = toValue(type, value);
+ }
+ Class clazz = bean.getClass();
+ Method method = getMethod("set", field, clazz);
+ if (method != null)
+ {
+ method.invoke(bean, new Object[]{value});
+ return;
+ }
+ field.setAccessible(true);
+ field.set(bean, value);
+ }
+
+ private final Method getMethod(String prefix, Field field, Class clazz) throws
Exception
+ {
+ StringBuilder name = new StringBuilder(field.getName());
+ name.setCharAt(0, Character.toUpperCase(name.charAt(0)));
+ name.insert(0, prefix);
+ return getMethodByName(name.toString(), field, clazz);
+ }
+
+ private final Method getMethodByName(String name, Field field, Class clazz)
+ {
+ try
+ {
+ Method method = clazz.getDeclaredMethod(name.toString(), new
Class[]{field.getType()});
+ if (method != null)
+ return method;
+ if (clazz == Object.class)
+ return null;
+ method = getMethodByName(name, field, clazz.getSuperclass());
+ if (method != null)
+ return method;
+ }
+ catch (Exception e)
+ {
+ }
+ return null;
+ }
+
+ private Field getField(Class clazz, String name)
+ {
+ Field field = null;
+ try
+ {
+ field = clazz.getDeclaredField(name);
+ }
+ catch (Exception e)
+ {
+ }
+ if (field != null)
+ return field;
+ if (clazz == Object.class)
+ return null;
+ return getField(clazz.getSuperclass(), name);
+ }
+
+ private Object toValues(Class<?> clazz, Object objects)
+ {
+ Class componentType = clazz.getComponentType();
+ Object newValues = Array.newInstance(componentType, Array.getLength(objects));
+ for (int i = 0; i < Array.getLength(objects); i++)
+ {
+ Array.set(newValues, i, toValue(componentType, Array.get(objects, i)));
+ }
+ return clazz.cast(newValues);
+ }
+
+ private Object toValue(Class<?> clazz, Object object)
+ {
+ if (clazz == int.class)
+ return new Integer(object.toString()).intValue();
+ if (clazz == short.class)
+ return new Short(object.toString()).shortValue();
+ if (clazz == float.class)
+ return new Float(object.toString()).floatValue();
+ if (clazz == double.class)
+ return new Double(object.toString()).doubleValue();
+ if (clazz == boolean.class)
+ return new Boolean(object.toString()).booleanValue();
+ if (clazz == char.class)
+ return object.toString().trim().charAt(0);
+ try
+ {
+ Constructor<?> constructor = clazz.getConstructor(new
Class[]{String.class});
+ return constructor.newInstance(new Object[]{object.toString()});
+ }
+ catch (Exception e)
+ {
+ }
+ return object.toString();
+ }
+
+}
\ No newline at end of file
Modified: portal/trunk/component/web/pom.xml
===================================================================
--- portal/trunk/component/web/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/component/web/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -28,70 +28,13 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>exo.portal.component.web</artifactId>
- <packaging>jar</packaging>
+ <packaging>pom</packaging>
<name>GateIn Portal Component Web</name>
- <properties>
- <maven.test.skip>true</maven.test.skip>
- </properties>
-
- <dependencies>
-
- <dependency>
- <groupId>org.exoplatform.kernel</groupId>
- <artifactId>exo.kernel.container</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.core</groupId>
- <artifactId>exo.core.component.organization.api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.jcr</groupId>
- <artifactId>exo.jcr.component.ext</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.common</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.resources</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.wci</groupId>
- <artifactId>wci-wci</artifactId>
- </dependency>
- <dependency>
- <groupId>org.chromattic</groupId>
- <artifactId>chromattic.apt</artifactId>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.scripting</artifactId>
- </dependency>
- <dependency>
- <groupId>org.gatein.shindig</groupId>
- <artifactId>shindig-gadgets</artifactId>
- </dependency>
- <dependency>
- <groupId>org.json</groupId>
- <artifactId>json</artifactId>
- <type>jar</type>
- </dependency>
- <dependency>
- <groupId>org.gatein.captcha</groupId>
- <artifactId>simplecaptcha</artifactId>
- </dependency>
- <dependency>
- <groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.test.core</artifactId>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.jboss.jbossas</groupId>
- <artifactId>jboss-as-tomcat</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
+ <modules>
+ <module>controller</module>
+ <module>security</module>
+ <module>server</module>
+ <module>api</module>
+ </modules>
</project>
Added: portal/trunk/component/web/security/pom.xml
===================================================================
--- portal/trunk/component/web/security/pom.xml (rev 0)
+++ portal/trunk/component/web/security/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>exo.portal.component.web.security</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn Portal Component Web Security</name>
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.core</groupId>
+ <artifactId>exo.core.component.organization.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.common</artifactId>
+ </dependency>
+<!--
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.wci</groupId>
+ <artifactId>wci-wci</artifactId>
+ </dependency>
+-->
+ <dependency>
+ <groupId>org.chromattic</groupId>
+ <artifactId>chromattic.apt</artifactId>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.captcha</groupId>
+ <artifactId>simplecaptcha</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.test.core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.jbossas</groupId>
+ <artifactId>jboss-as-tomcat</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+</project>
Added: portal/trunk/component/web/security/src/main/java/conf/autologin-nodetypes.xml
===================================================================
--- portal/trunk/component/web/security/src/main/java/conf/autologin-nodetypes.xml
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/conf/autologin-nodetypes.xml 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,56 @@
+<!--
+
+ 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.
+
+-->
+<nodeTypes
xmlns:nt="http://www.jcp.org/jcr/nt/1.0"
xmlns:mix="http://www.jcp.org/jcr/mix/1.0"
xmlns:jcr="http://www.jcp.org/jcr/1.0">
+
+ <nodeType name="tkn:tokencontainer" isMixin="false"
hasOrderableChildNodes="false" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <childNodeDefinitions>
+ <childNodeDefinition name="*"
defaultPrimaryType="tkn:tokenentry" autoCreated="false"
mandatory="false"
+ onParentVersion="COPY" protected="false"
sameNameSiblings="false">
+ <requiredPrimaryTypes>
+ <requiredPrimaryType>tkn:tokenentry</requiredPrimaryType>
+ </requiredPrimaryTypes>
+ </childNodeDefinition>
+ </childNodeDefinitions>
+ </nodeType>
+
+ <nodeType name="tkn:tokenentry" isMixin="false"
hasOrderableChildNodes="false" primaryItemName="">
+ <supertypes>
+ <supertype>nt:base</supertype>
+ <supertype>mix:referenceable</supertype>
+ </supertypes>
+ <propertyDefinitions>
+ <propertyDefinition name="username" requiredType="String"
autoCreated="false" mandatory="true" onParentVersion="COPY"
protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="password" requiredType="String"
autoCreated="false" mandatory="true" onParentVersion="COPY"
protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ <propertyDefinition name="expiration" requiredType="Date"
autoCreated="true" mandatory="true" onParentVersion="COPY"
protected="false" multiple="false">
+ <valueConstraints/>
+ </propertyDefinition>
+ </propertyDefinitions>
+ </nodeType>
+
+</nodeTypes>
Added: portal/trunk/component/web/security/src/main/java/conf/portal/configuration.xml
===================================================================
--- portal/trunk/component/web/security/src/main/java/conf/portal/configuration.xml
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/conf/portal/configuration.xml 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+
+ 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.
+
+-->
+
+<configuration
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd
http://www.exoplaform.org/xml/ns/kernel_1_0.xsd"
+
xmlns="http://www.exoplaform.org/xml/ns/kernel_1_0.xsd">
+ <component>
+ <type>org.exoplatform.upload.UploadService</type>
+ <init-params>
+ <value-param>
+ <name>upload.limit.size</name>
+ <description>Maximum size of the file to upload in MB</description>
+ <value>10</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.exoplatform.download.DownloadService</type>
+ <init-params>
+ <value-param>
+ <name>download.resource.cache.size</name>
+ <description>Maximun number of the download can be in the
cache</description>
+ <value>500</value>
+ </value-param>
+ </init-params>
+ </component>
+
+ <component>
+ <type>org.exoplatform.web.WebAppController</type>
+ </component>
+
+ <component>
+ <key>org.exoplatform.web.application.javascript.JavascriptConfigService</key>
+ <type>org.exoplatform.web.application.javascript.JavascriptConfigService</type>
+ </component>
+
+ <component>
+ <type>org.exoplatform.web.filter.ExtensibleFilter</type>
+ </component>
+
+</configuration>
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/CacheUserProfileFilter.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/CacheUserProfileFilter.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/CacheUserProfileFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,100 @@
+/**
+ * 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.web;
+
+import org.exoplatform.container.component.ComponentRequestLifecycle;
+import org.exoplatform.container.component.RequestLifeCycle;
+import org.exoplatform.container.web.AbstractFilter;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.organization.OrganizationService;
+import org.exoplatform.services.organization.User;
+import org.exoplatform.services.security.ConversationState;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+
+public class CacheUserProfileFilter extends AbstractFilter
+{
+
+ /**
+ * "subject".
+ */
+ public static final String USER_PROFILE = "UserProfile";
+
+ /**
+ * Logger.
+ */
+ private static Log log =
ExoLogger.getLogger("core.security.SetCurrentIdentityFilter");
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws ServletException
+ {
+ ConversationState state = ConversationState.getCurrent();
+ try
+ {
+ if (state != null)
+ {
+ if (log.isDebugEnabled())
+ log.debug("Conversation State found, save user profile to
Conversation State.");
+
+ if (state.getAttribute(USER_PROFILE) == null)
+ {
+ OrganizationService orgService =
+
(OrganizationService)getContainer().getComponentInstanceOfType(OrganizationService.class);
+
+ begin(orgService);
+ User user =
orgService.getUserHandler().findUserByName(state.getIdentity().getUserId());
+ end(orgService);
+ state.setAttribute(USER_PROFILE, user);
+
+ }
+
+ }
+ chain.doFilter(request, response);
+ }
+ catch (Exception e)
+ {
+ log.warn("An error occured while cache user profile", e);
+ }
+
+ }
+
+ public void destroy()
+ {
+ }
+
+ public void begin(OrganizationService orgService) throws Exception
+ {
+ if (orgService instanceof ComponentRequestLifecycle)
+ {
+ RequestLifeCycle.begin((ComponentRequestLifecycle)orgService);
+ }
+ }
+
+ public void end(OrganizationService orgService) throws Exception
+ {
+ if (orgService instanceof ComponentRequestLifecycle)
+ {
+ RequestLifeCycle.end();
+ }
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ClusteredSSOFilter.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ClusteredSSOFilter.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ClusteredSSOFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,80 @@
+/*
+* JBoss, a division of Red Hat
+* Copyright 2010, Red Hat Middleware, 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.login;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.web.AbstractFilter;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.PortalLoginModule;
+
+import org.jboss.web.tomcat.security.login.WebAuthentication;
+
+import javax.servlet.FilterChain;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import java.io.IOException;
+
+/*
+ * @author <a href="mailto:boleslaw.dawidowicz at redhat.com">Boleslaw
Dawidowicz</a>
+ */
+public class ClusteredSSOFilter extends AbstractFilter
+{
+
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain
chain) throws IOException, ServletException
+ {
+ if (ExoContainer.getProfiles().contains("cluster"))
+ {
+ HttpServletRequest httpRequest = (HttpServletRequest)request;
+
+ Credentials credentials =
(Credentials)httpRequest.getSession().getAttribute(PortalLoginModule.AUTHENTICATED_CREDENTIALS);
+
+ // Make programatic login if authenticated credentials are present in session -
they were set in another cluster node
+ if (credentials != null && httpRequest.getRemoteUser() == null)
+ {
+ WebAuthentication pwl = new WebAuthentication();
+ pwl.login(credentials.getUsername(), credentials.getPassword());
+
+ }
+
+ chain.doFilter(request, response);
+
+ // TODO:
+ // This is a workaround... without this code this attr will vanish from session
after first request - don't ask...
+ if (credentials != null && httpRequest.getSession(false) != null)
+ {
+
httpRequest.getSession(false).setAttribute(PortalLoginModule.AUTHENTICATED_CREDENTIALS,
credentials);
+ }
+ }
+ else
+ {
+ chain.doFilter(request, response);
+ }
+ }
+
+ public void destroy()
+ {
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/ErrorLoginServlet.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,126 @@
+/**
+ * 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.web.login;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.web.AbstractHttpServlet;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Manages an error on login
+ *
+ * Created by The eXo Platform SAS
+ * Author : Nicolas Filotto
+ * nicolas.filotto(a)exoplatform.com
+ * 4 oct. 2009
+ */
+public class ErrorLoginServlet extends AbstractHttpServlet
+{
+
+ /**
+ * Serial version ID
+ */
+ private static final long serialVersionUID = -1565579389217147072L;
+
+ /**
+ * Logger.
+ */
+ private static final Log LOG =
ExoLogger.getLogger(ErrorLoginServlet.class.getName());
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ PortalContainer pContainer = PortalContainer.getInstance();
+ ServletContext context = pContainer.getPortalContext();
+ // Unregister the token cookie
+ unregisterTokenCookie(req);
+ // Clear the token cookie
+ clearTokenCookie(req, resp);
+ // This allows the customer to define another login page without changing the
portal
+ context.getRequestDispatcher("/login/jsp/login.jsp").include(req, resp);
+ }
+
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+ private void clearTokenCookie(HttpServletRequest req, HttpServletResponse resp)
+ {
+ Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, "");
+ cookie.setPath(req.getContextPath());
+ cookie.setMaxAge(0);
+ resp.addCookie(cookie);
+ }
+
+ private void unregisterTokenCookie(HttpServletRequest req)
+ {
+ String tokenId = getTokenCookie(req);
+ if (tokenId != null)
+ {
+ try
+ {
+ AbstractTokenService tokenService =
AbstractTokenService.getInstance(CookieTokenService.class);
+ tokenService.deleteToken(tokenId);
+ }
+ catch (Exception e)
+ {
+ LOG.warn("Cannot delete the token '" + tokenId +
"'", e);
+ }
+ }
+ }
+
+ private String getTokenCookie(HttpServletRequest req)
+ {
+ Cookie[] cookies = req.getCookies();
+ if (cookies != null)
+ {
+ for (Cookie cookie : cookies)
+ {
+ if (InitiateLoginServlet.COOKIE_NAME.equals(cookie.getName()))
+ {
+ return cookie.getValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.exoplatform.container.web.AbstractHttpServlet#requirePortalEnvironment()
+ */
+ @Override
+ protected boolean requirePortalEnvironment()
+ {
+ return true;
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/InitiateLoginServlet.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,183 @@
+/**
+ * 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.web.login;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.web.AbstractHttpServlet;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+import org.exoplatform.web.security.security.TransientTokenService;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
+import java.io.IOException;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+/**
+ * Initiate the login dance.
+ *
+ * @author <a href="mailto:trong.tran@exoplatform.com">Tran The
Trong</a>
+ * @version $Revision$
+ */
+public class InitiateLoginServlet extends AbstractHttpServlet
+{
+
+ /** . */
+ private static final Logger log =
LoggerFactory.getLogger(InitiateLoginServlet.class);
+
+ /** . */
+ public static final String COOKIE_NAME = "rememberme";
+
+ /** . */
+ public static final String CREDENTIALS = "credentials";
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ resp.setContentType("text/html; charset=UTF-8");
+ HttpSession session = req.getSession();
+
+ // Looking for credentials stored in the session
+ Credentials credentials =
(Credentials)session.getAttribute(InitiateLoginServlet.CREDENTIALS);
+
+ //
+ if (credentials == null)
+ {
+ PortalContainer pContainer = PortalContainer.getInstance();
+ ServletContext context = pContainer.getPortalContext();
+
+ //
+ String token = getRememberMeTokenCookie(req);
+ if (token != null)
+ {
+ AbstractTokenService tokenService =
AbstractTokenService.getInstance(CookieTokenService.class);
+ credentials = tokenService.validateToken(token, false);
+ if (credentials == null)
+ {
+ log.debug("Login initiated with no credentials in session but found
token an invalid " + token + " " +
+ "that will be cleared in next response");
+
+ // We clear the cookie in the next response as it was not valid
+ Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME,
"");
+ cookie.setPath(req.getContextPath());
+ cookie.setMaxAge(0);
+ resp.addCookie(cookie);
+
+ // This allows the customer to define another login page without
+ // changing the portal
+ showLoginForm(req, resp);
+ }
+ else
+ {
+ // Send authentication request
+ log.debug("Login initiated with no credentials in session but found
token " + token + " with existing credentials, " +
+ "performing authentication");
+ sendAuth(resp, credentials.getUsername(), token);
+ }
+ }
+ else
+ {
+ // This allows the customer to define another login page without
+ // changing the portal
+ log.debug("Login initiated with no credentials in session and no token
cookie, redirecting to login page");
+ showLoginForm(req, resp);
+ }
+ }
+ else
+ {
+ // We create a temporary token just for the login time
+ TransientTokenService tokenService =
AbstractTokenService.getInstance(TransientTokenService.class);
+ String token = tokenService.createToken(credentials);
+ req.getSession().removeAttribute(InitiateLoginServlet.CREDENTIALS);
+
+ // Send authentication request
+ log.debug("Login initiated with credentials in session, performing
authentication");
+ sendAuth(resp, credentials.getUsername(), token);
+ }
+ }
+
+ private void showLoginForm(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ String initialURI =
(String)req.getAttribute("javax.servlet.forward.request_uri");
+ if (initialURI == null)
+ {
+ throw new IllegalStateException("request attribute
javax.servlet.forward.request_uri should not be null here");
+ }
+ try
+ {
+ req.setAttribute("org.gatein.portal.login.initial_uri", initialURI);
+
getServletContext().getRequestDispatcher("/login/jsp/login.jsp").include(req,
resp);
+ }
+ finally
+ {
+ req.removeAttribute("org.gatein.portal.login.initial_uri");
+ }
+ }
+
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+ private void sendAuth(HttpServletResponse resp, String jUsername, String jPassword)
throws IOException
+ {
+ String url = "j_security_check?j_username=" + jUsername +
"&j_password=" + jPassword;
+ url = resp.encodeRedirectURL(url);
+ resp.sendRedirect(url);
+ }
+
+ /**
+ * Extract the remember me token from the request or returns null.
+ *
+ * @param req the incoming request
+ * @return the token
+ */
+ public static String getRememberMeTokenCookie(HttpServletRequest req)
+ {
+ Cookie[] cookies = req.getCookies();
+ if (cookies != null)
+ {
+ for (Cookie cookie : cookies)
+ {
+ if (InitiateLoginServlet.COOKIE_NAME.equals(cookie.getName()))
+ {
+ return cookie.getValue();
+ }
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.exoplatform.container.web.AbstractHttpServlet#requirePortalEnvironment()
+ */
+ @Override
+ protected boolean requirePortalEnvironment()
+ {
+ return true;
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/PortalLoginController.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,118 @@
+/**
+ * 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.web.login;
+
+import org.exoplatform.container.web.AbstractHttpServlet;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.security.AbstractTokenService;
+import org.exoplatform.web.security.security.CookieTokenService;
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.Cookie;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * @author <a href="mailto:trong.tran@exoplatform.com">Tran The
Trong</a>
+ * @version $Revision$
+ */
+public class PortalLoginController extends AbstractHttpServlet
+{
+
+ /** . */
+ private static final Logger log =
LoggerFactory.getLogger(PortalLoginController.class);
+
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ String username = req.getParameter("username");
+ String password = req.getParameter("password");
+
+ //
+ if (username == null)
+ {
+ log.error("Tried to access the portal login controller without username
provided");
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "No username
provided");
+ return;
+ }
+ if (password == null)
+ {
+ log.error("Tried to access the portal login controller without password
provided");
+ resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "No password
provided");
+ return;
+ }
+
+ //
+ log.debug("Found username and password and set credentials in http
session");
+ Credentials credentials = new Credentials(username, password);
+ req.getSession().setAttribute(InitiateLoginServlet.CREDENTIALS, credentials);
+
+ // Obtain initial URI
+ String uri = req.getParameter("initialURI");
+
+ // otherwise compute one
+ if (uri == null || uri.length() == 0)
+ {
+ uri = req.getContextPath() + "/private/classic";
+ log.debug("No initial URI found, will use default " + uri + "
instead ");
+ }
+ else
+ {
+ log.debug("Found initial URI " + uri);
+ }
+
+ // if we do have a remember me
+ String rememberme = req.getParameter("rememberme");
+ if ("true".equals(rememberme))
+ {
+ boolean isRemember =
"true".equals(req.getParameter(InitiateLoginServlet.COOKIE_NAME));
+ if (isRemember)
+ {
+ //Create token
+ AbstractTokenService tokenService =
AbstractTokenService.getInstance(CookieTokenService.class);
+ String cookieToken = tokenService.createToken(credentials);
+
+ log.debug("Found a remember me request parameter, created a persistent
token " + cookieToken + " for it and set it up " +
+ "in the next response");
+ Cookie cookie = new Cookie(InitiateLoginServlet.COOKIE_NAME, cookieToken);
+ cookie.setPath(req.getContextPath());
+ cookie.setMaxAge((int)tokenService.getValidityTime() / 1000);
+ resp.addCookie(cookie);
+ }
+ }
+
+ //
+ resp.sendRedirect(uri);
+ }
+
+ protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws
ServletException, IOException
+ {
+ doGet(req, resp);
+ }
+
+ @Override
+ protected boolean requirePortalEnvironment()
+ {
+ return true;
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/RememberMeFilter.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/RememberMeFilter.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/login/RememberMeFilter.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,98 @@
+/*
+ * 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.web.login;
+
+import org.gatein.common.logging.Logger;
+import org.gatein.common.logging.LoggerFactory;
+import org.gatein.common.text.FastURLEncoder;
+
+import javax.servlet.*;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.Enumeration;
+
+/**
+ * The remember me filter performs a send redirect on a portal private servlet mapping
when the current request
+ * is a GET request, the user is not authenticated and there is a remember me token
cookie in the request.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class RememberMeFilter implements Filter
+{
+ /** . */
+ private static final FastURLEncoder CONVERTER = FastURLEncoder.getUTF8Instance();
+
+ /** . */
+ private static final Logger log = LoggerFactory.getLogger(RememberMeFilter.class);
+
+ public void init(FilterConfig filterConfig) throws ServletException
+ {
+ }
+
+ public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain)
throws IOException, ServletException
+ {
+ doFilter((HttpServletRequest)req, (HttpServletResponse)resp, chain);
+ }
+
+ private void doFilter(HttpServletRequest req, HttpServletResponse resp, FilterChain
chain) throws IOException, ServletException
+ {
+ if (req.getRemoteUser() == null &&
"GET".equals(req.getMethod()))
+ {
+ String token = InitiateLoginServlet.getRememberMeTokenCookie(req);
+ if (token != null)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append(req.getContextPath());
+ builder.append("/private");
+ String pathInfo = req.getPathInfo();
+ if (pathInfo != null)
+ {
+ builder.append(pathInfo);
+ }
+ char sep = '?';
+ for (Enumeration<String> e =
req.getParameterNames();e.hasMoreElements();)
+ {
+ String parameterName = e.nextElement();
+ for (String parameteValue : req.getParameterValues(parameterName))
+ {
+ builder.append(sep);
+ sep = '&';
+ builder.append(CONVERTER.encode(parameterName));
+ builder.append('=');
+ builder.append(CONVERTER.encode(parameteValue));
+ }
+ }
+ String s = builder.toString();
+ log.debug("Redirecting unauthenticated request with token " + token
+ " to URL " + s);
+ resp.sendRedirect(s);
+ return;
+ }
+ }
+
+ //
+ chain.doFilter(req, resp);
+ }
+
+ public void destroy()
+ {
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/CaptchaServlet.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -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());
+ }
+
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Credentials.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Credentials.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Credentials.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,81 @@
+/**
+ * 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.web.security;
+
+import java.io.Serializable;
+
+/**
+ * An immutable object that contains a username and a password.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class Credentials implements Serializable
+{
+
+
+
+ /** . */
+ private final String username;
+
+ /** . */
+ private final String password;
+
+ /**
+ * Construct a new instance.
+ *
+ * @param username the username value
+ * @param password the password value
+ * @throws NullPointerException if any argument is null
+ */
+ public Credentials(String username, String password) throws NullPointerException
+ {
+ if (username == null)
+ {
+ throw new NullPointerException("Username is null");
+ }
+ if (password == null)
+ {
+ throw new NullPointerException("Password is null");
+ }
+ this.username = username;
+ this.password = password;
+ }
+
+ /**
+ * Returns the username.
+ *
+ * @return the username
+ */
+ public String getUsername()
+ {
+ return username;
+ }
+
+ /**
+ * Returns the password.
+ *
+ * @return the password
+ */
+ public String getPassword()
+ {
+ return password;
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/GateInToken.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/GateInToken.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/GateInToken.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,64 @@
+/**
+ * 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.web.security;
+
+
+/**
+ * Created by The eXo Platform SAS
+ * Author : Tan Pham Dinh
+ * tan.pham(a)exoplatform.com
+ * May 6, 2009
+ */
+public class GateInToken implements Token
+{
+
+ public static String EXPIRE_MILI = "expirationMilis";
+
+ public static String USERNAME = "userName";
+
+ public static String PASSWORD = "password";
+
+ /** . */
+ private final long expirationTimeMillis;
+
+ /** . */
+ private final Credentials payload;
+
+ public GateInToken(long expirationTimeMillis, Credentials payload)
+ {
+ this.expirationTimeMillis = expirationTimeMillis;
+ this.payload = payload;
+ }
+
+ public long getExpirationTimeMillis()
+ {
+ return expirationTimeMillis;
+ }
+
+ public Credentials getPayload()
+ {
+ return payload;
+ }
+
+ public boolean isExpired()
+ {
+ return System.currentTimeMillis() > expirationTimeMillis;
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/PortalLoginModule.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/PortalLoginModule.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/PortalLoginModule.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,206 @@
+/**
+ * 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.web.security;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.exoplatform.services.security.jaas.AbstractLoginModule;
+import org.exoplatform.web.login.InitiateLoginServlet;
+import org.exoplatform.web.security.security.CookieTokenService;
+import org.exoplatform.web.security.security.TransientTokenService;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.NameCallback;
+import javax.security.auth.callback.PasswordCallback;
+import javax.security.auth.login.LoginException;
+import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.Method;
+
+/**
+ * A login module implementation that relies on the token store to check the
+ * password validity. If the token store provides a valid {@link Credentials}
+ * value then password stacking is used and the two entries are added in the
+ * shared state map. The first entry is keyed by
+ * <code>javax.security.auth.login.name</code> and contains the
+ * {@link Credentials#getUsername()} value, the second entry is keyed by
+ * <code>javax.security.auth.login.password</code> and contains the
+ * {@link Credentials#getPassword()} ()} value.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public class PortalLoginModule extends AbstractLoginModule
+{
+
+ /** Logger. */
+ private static final Log log = ExoLogger.getLogger(PortalLoginModule.class);
+
+ /** JACC get context method. */
+ private static final Method getContextMethod;
+
+ static
+ {
+ Method getContext = null;
+ if (isClusteredSSO())
+ {
+ log.debug("About to configure clustered SSO");
+ try
+ {
+ Class<?> policyContextClass =
Thread.currentThread().getContextClassLoader().loadClass("javax.security.jacc.PolicyContext");
+ getContext = policyContextClass.getDeclaredMethod("getContext",
String.class);
+ }
+ catch (ClassNotFoundException ignore)
+ {
+ log.debug("JACC not found ignoring it", ignore);
+ }
+ catch (Exception e)
+ {
+ log.error("Could not obtain JACC get context method", e);
+ }
+ }
+
+ //
+ getContextMethod = getContext;
+ }
+
+ public static final String AUTHENTICATED_CREDENTIALS =
"authenticatedCredentials";
+
+ /**
+ * @see javax.security.auth.spi.LoginModule#login()
+ */
+ @SuppressWarnings("unchecked")
+ public boolean login() throws LoginException
+ {
+
+ Callback[] callbacks = new Callback[2];
+ callbacks[0] = new NameCallback("Username");
+ callbacks[1] = new PasswordCallback("Password", false);
+
+ try
+ {
+ callbackHandler.handle(callbacks);
+ String password = new String(((PasswordCallback)callbacks[1]).getPassword());
+
+ ExoContainer container = getContainer();
+ Object o =
+
((TransientTokenService)container.getComponentInstanceOfType(TransientTokenService.class)).validateToken(
+ password, true);
+ if (o == null)
+ o =
+
((CookieTokenService)container.getComponentInstanceOfType(CookieTokenService.class)).validateToken(
+ password, false);
+ //
+
+ // For clustered config check credentials stored and propagated in session. This
won't work in tomcat because
+ // of lack of JACC PolicyContext so the code must be a bit defensive
+ if (o == null && getContextMethod != null &&
password.startsWith(InitiateLoginServlet.COOKIE_NAME))
+ {
+ HttpServletRequest request;
+ try
+ {
+ request = (HttpServletRequest)getContextMethod.invoke(null,
"javax.servlet.http.HttpServletRequest");
+ o = request.getSession().getAttribute(AUTHENTICATED_CREDENTIALS);
+ }
+ catch(Throwable e)
+ {
+ log.error(this,e);
+ log.error("LoginModule error. Turn off session credentials checking
with proper configuration option of " +
+ "LoginModule set to false");
+ }
+
+ }
+
+ if (o instanceof Credentials)
+ {
+ Credentials wc = (Credentials)o;
+
+ // Set shared state
+ sharedState.put("javax.security.auth.login.name",
wc.getUsername());
+ sharedState.put("javax.security.auth.login.password",
wc.getPassword());
+ }
+ return true;
+ }
+ catch (Exception e)
+ {
+ LoginException le = new LoginException();
+ le.initCause(e);
+ throw le;
+ }
+ }
+
+ /**
+ * @see javax.security.auth.spi.LoginModule#commit()
+ */
+ public boolean commit() throws LoginException
+ {
+
+ if (getContextMethod != null &&
+ sharedState.containsKey("javax.security.auth.login.name") &&
+ sharedState.containsKey("javax.security.auth.login.password"))
+ {
+ String uid =
(String)sharedState.get("javax.security.auth.login.name");
+ String pass =
(String)sharedState.get("javax.security.auth.login.password");
+
+ Credentials wc = new Credentials(uid, pass);
+
+ HttpServletRequest request = null;
+ try
+ {
+ request = (HttpServletRequest)getContextMethod.invoke(null,
"javax.servlet.http.HttpServletRequest");
+ request.getSession().setAttribute(AUTHENTICATED_CREDENTIALS, wc);
+ }
+ catch(Exception e)
+ {
+ log.error(this,e);
+ log.error("LoginModule error. Turn off session credentials checking with
proper configuration option of " +
+ "LoginModule set to false");
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @see javax.security.auth.spi.LoginModule#abort()
+ */
+ public boolean abort() throws LoginException
+ {
+ return true;
+ }
+
+ /**
+ * @see javax.security.auth.spi.LoginModule#logout()
+ */
+ public boolean logout() throws LoginException
+ {
+ return true;
+ }
+
+ @Override
+ protected Log getLogger()
+ {
+ return log;
+ }
+
+ protected static boolean isClusteredSSO()
+ {
+ return ExoContainer.getProfiles().contains("cluster");
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Token.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Token.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/Token.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,32 @@
+/**
+ * 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.web.security;
+
+/**
+ * A token.
+ */
+public interface Token
+{
+ boolean isExpired();
+
+ long getExpirationTimeMillis();
+
+ Credentials getPayload();
+
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/TokenStore.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/TokenStore.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/TokenStore.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,53 @@
+/**
+ * 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.web.security;
+
+/**
+ * The token store is a place where temporary tokens are held.
+ *
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+public interface TokenStore
+{
+ /**
+ * Create a token and returns it. The store state is modified as it retains the token
until
+ * it is removed either explicitely or because the token validity is expired.
+ *
+ * @param credentials the credentials
+ * @return the token key
+ * @throws IllegalArgumentException if the validity is not greater than zero
+ * @throws NullPointerException if the payload is null
+ */
+ String createToken(Credentials credentials) throws IllegalArgumentException,
NullPointerException;
+
+ /**
+ * Validates a token. If the token is valid it returns the attached credentials. The
store state may be modified
+ * by the removal of the token. The token is removed either if the remove argument is
set to true of if the
+ * token is not anymore valid.
+ *
+ * @param tokenKey the token key
+ * @param remove true if the token must be removed regardless its validity
+ * @return the attached credentials or null
+ * @throws NullPointerException if the token key argument is null
+ */
+ Credentials validateToken(String tokenKey, boolean remove) throws
NullPointerException;
+
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/AbstractTokenService.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,223 @@
+/**
+ * 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.web.security.security;
+
+import org.exoplatform.container.PortalContainer;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.management.annotations.*;
+import org.exoplatform.management.jmx.annotations.NameTemplate;
+import org.exoplatform.management.jmx.annotations.Property;
+import org.exoplatform.web.login.InitiateLoginServlet;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.Token;
+import org.exoplatform.web.security.TokenStore;
+import org.picocontainer.Startable;
+
+import java.util.List;
+import java.util.Random;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
+ * 2009
+ *
+ * todo julien :
+ * - make delay configuration from init param and @Managed setter
+ * - start/stop expiration daemon
+ * - manually invoke the daemon via @Managed
+ *
+ * @param <T> the token type
+ * @param <K> the token key type
+ */
+@Managed
+@ManagedDescription("Token Store Service")
+@NameTemplate({
+ @Property(key = "service", value = "TokenStore"),
+ @Property(key = "name", value = "{Name}")})
+public abstract class AbstractTokenService<T extends Token, K> implements
Startable, TokenStore
+{
+
+ protected static final String SERVICE_CONFIG = "service.configuration";
+
+ protected static final int DELAY_TIME = 600;
+
+ protected final Random random = new Random();
+
+ protected String name;
+
+ protected long validityMillis;
+
+ @SuppressWarnings("unchecked")
+ public AbstractTokenService(InitParams initParams)
+ {
+ List<String> params = initParams.getValuesParam(SERVICE_CONFIG).getValues();
+ this.name = params.get(0);
+ long configValue = new Long(params.get(1));
+ this.validityMillis =
TimeoutEnum.valueOf(params.get(2)).toMilisecond(configValue);
+ }
+
+ public void start()
+ {
+ // start a thread, garbage expired cookie token every [DELAY_TIME]
+ final AbstractTokenService service = this;
+ ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
+ executor.scheduleWithFixedDelay(new Runnable()
+ {
+ public void run()
+ {
+ service.cleanExpiredTokens();
+ }
+ }, 0, DELAY_TIME, TimeUnit.SECONDS);
+
+ }
+
+ public void stop()
+ {
+ // do nothing
+ }
+
+ public static <T extends AbstractTokenService> T getInstance(Class<T>
classType)
+ {
+ PortalContainer container = PortalContainer.getInstance();
+ return classType.cast(container.getComponentInstanceOfType(classType));
+ }
+
+ public Credentials validateToken(String stringKey, boolean remove)
+ {
+ if (stringKey == null)
+ {
+ throw new NullPointerException();
+ }
+
+ //
+ K tokenKey = decodeKey(stringKey);
+
+ T token;
+ try
+ {
+ if (remove)
+ {
+ token = this.deleteToken(tokenKey);
+ }
+ else
+ {
+ token = this.getToken(tokenKey);
+ }
+
+ if (token != null)
+ {
+ boolean valid = token.getExpirationTimeMillis() >
System.currentTimeMillis();
+ if (valid)
+ {
+ return token.getPayload();
+ }
+ else if (!remove)
+ {
+ this.deleteToken(tokenKey);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ }
+
+ return null;
+ }
+
+ @Managed
+ @ManagedDescription("Clean all tokens are expired")
+ @Impact(ImpactType.IDEMPOTENT_WRITE)
+ public void cleanExpiredTokens()
+ {
+ K[] ids = getAllTokens();
+ for (K id : ids)
+ {
+ T token = getToken(id);
+ if (token.isExpired())
+ {
+ deleteToken(id);
+ }
+ }
+ }
+
+ @Managed
+ @ManagedDescription("Get time for token expiration in seconds")
+ public long getValidityTime()
+ {
+ return validityMillis / 1000;
+ }
+
+ @Managed
+ @ManagedDescription("The expiration daemon period time in seconds")
+ public long getPeriodTime()
+ {
+ return DELAY_TIME;
+ }
+
+ @Managed
+ @ManagedDescription("The token service name")
+ public String getName()
+ {
+ return name;
+ }
+
+ public abstract T getToken(K id);
+
+ public abstract T deleteToken(K id);
+
+ public abstract K[] getAllTokens();
+
+ /**
+ * Decode a key from its string representation.
+ *
+ * @param stringKey the key a s a string
+ * @return the typed key
+ */
+ protected abstract K decodeKey(String stringKey);
+
+ // We don't make it a property as retrieving the value can be an expensive
operation
+ @Managed
+ @ManagedDescription("The number of tokens")
+ @Impact(ImpactType.READ)
+ public abstract long size() throws Exception;
+
+ private enum TimeoutEnum {
+ SECOND(1000), MINUTE(1000 * 60), HOUR(1000 * 60 * 60), DAY(1000 * 60 * 60 * 24);
+
+ private long multiply;
+
+ private TimeoutEnum(long multiply)
+ {
+ this.multiply = multiply;
+ }
+
+ public long toMilisecond(long configValue)
+ {
+ return configValue * multiply;
+ }
+ }
+
+ protected String nextTokenId()
+ {
+ return InitiateLoginServlet.COOKIE_NAME + random.nextInt();
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/CookieTokenService.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,177 @@
+/**
+ * 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.web.security.security;
+
+import org.chromattic.api.ChromatticSession;
+import org.exoplatform.commons.chromattic.ChromatticLifeCycle;
+import org.exoplatform.commons.chromattic.ChromatticManager;
+import org.exoplatform.commons.chromattic.ContextualTask;
+import org.exoplatform.commons.chromattic.SessionContext;
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.GateInToken;
+
+import java.util.Collection;
+import java.util.Date;
+
+/**
+ * Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
+ * 2009
+ */
+public class CookieTokenService extends AbstractTokenService<GateInToken, String>
+{
+
+ /** . */
+ public static final String LIFECYCLE_NAME="lifecycle-name";
+
+ /** . */
+ private ChromatticLifeCycle chromatticLifeCycle;
+
+ /** . */
+ private String lifecycleName="autologin";
+
+ public CookieTokenService(InitParams initParams, ChromatticManager chromatticManager)
+ {
+ super(initParams);
+
+ if (initParams.getValuesParam(SERVICE_CONFIG).getValues().size() > 3)
+ {
+ lifecycleName =
(String)initParams.getValuesParam(SERVICE_CONFIG).getValues().get(3);
+ }
+ this.chromatticLifeCycle = chromatticManager.getLifeCycle(lifecycleName);
+ }
+
+ public String createToken(final Credentials credentials)
+ {
+ if (validityMillis < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (credentials == null)
+ {
+ throw new NullPointerException();
+ }
+ return new TokenTask<String>() {
+ @Override
+ protected String execute()
+ {
+ String tokenId = nextTokenId();
+ long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
+ GateInToken token = new GateInToken(expirationTimeMillis, credentials);
+ TokenContainer container = getTokenContainer();
+ container.saveToken(tokenId, token.getPayload(), new
Date(token.getExpirationTimeMillis()));
+ return tokenId;
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public GateInToken getToken(final String id)
+ {
+ return new TokenTask<GateInToken>() {
+ @Override
+ protected GateInToken execute()
+ {
+ return getTokenContainer().getToken((String)id);
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public GateInToken deleteToken(final String id)
+ {
+ return new TokenTask<GateInToken>() {
+ @Override
+ protected GateInToken execute()
+ {
+ return getTokenContainer().removeToken((String)id);
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public String[] getAllTokens()
+ {
+ return new TokenTask<String[]>() {
+ @Override
+ protected String[] execute()
+ {
+ TokenContainer container = getTokenContainer();
+ Collection<TokenEntry> tokens = container.getAllTokens();
+ String[] ids = new String[tokens.size()];
+ int count = 0;
+ for (TokenEntry token : tokens)
+ {
+ ids[count++] = token.getId();
+ }
+ return ids;
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ public long size() throws Exception
+ {
+ return new TokenTask<Long>() {
+ @Override
+ protected Long execute()
+ {
+ TokenContainer container = getTokenContainer();
+ Collection<TokenEntry> tokens = container.getAllTokens();
+ return (long)tokens.size();
+ }
+ }.executeWith(chromatticLifeCycle);
+ }
+
+ @Override
+ protected String decodeKey(String stringKey)
+ {
+ return stringKey;
+ }
+
+ /**
+ * Wraps token store logic conveniently.
+ *
+ * @param <V> the return type
+ */
+ private abstract class TokenTask<V> extends ContextualTask<V>
+ {
+
+ protected final TokenContainer getTokenContainer() {
+ SessionContext ctx = chromatticLifeCycle.getContext();
+ ChromatticSession session = ctx.getSession();
+ TokenContainer container = session.findByPath(TokenContainer.class,
lifecycleName);
+ if (container == null)
+ {
+ container = session.insert(TokenContainer.class, lifecycleName);
+ }
+ return container;
+ }
+
+ @Override
+ protected V execute(SessionContext context)
+ {
+ return execute();
+ }
+
+ protected abstract V execute();
+
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/RemindPasswordTokenService.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/RemindPasswordTokenService.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/RemindPasswordTokenService.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,45 @@
+/******************************************************************************
+ * JBoss, a division of 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.security;
+
+import org.exoplatform.commons.chromattic.ChromatticManager;
+import org.exoplatform.container.xml.InitParams;
+
+/**
+ * @author <a href="mailto:theute@redhat.com">Thomas Heute</a>
+ * @version $Revision$
+ */
+public class RemindPasswordTokenService extends CookieTokenService {
+
+ public RemindPasswordTokenService(InitParams initParams,
+ ChromatticManager chromatticManager)
+ {
+ super(initParams, chromatticManager);
+ }
+
+ @Override
+ protected String nextTokenId()
+ {
+ return "" + random.nextInt();
+ }
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenContainer.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,88 @@
+/*
+ * 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.web.security.security;
+
+import org.chromattic.api.annotations.Create;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.OneToMany;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.GateInToken;
+
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = "tkn:tokencontainer")
+public abstract class TokenContainer
+{
+
+ @Create
+ protected abstract TokenEntry createToken();
+
+ @OneToMany
+ protected abstract Map<String, TokenEntry> getTokens();
+
+ public Collection<TokenEntry> getAllTokens()
+ {
+ return getTokens().values();
+ }
+
+ public GateInToken getToken(String tokenId)
+ {
+ Map<String, TokenEntry> tokens = getTokens();
+ TokenEntry entry = tokens.get(tokenId);
+ return entry != null ? entry.getToken() : null;
+ }
+
+ public GateInToken removeToken(String tokenId)
+ {
+ Map<String, TokenEntry> tokens = getTokens();
+ TokenEntry entry = tokens.get(tokenId);
+ if (entry != null)
+ {
+ GateInToken token = entry.getToken();
+ entry.remove();
+ return token;
+ }
+ else
+ {
+ return null;
+ }
+ }
+
+ public GateInToken saveToken(String tokenId, Credentials credentials, Date
expirationTime)
+ {
+ Map<String, TokenEntry> tokens = getTokens();
+ TokenEntry entry = tokens.get(tokenId);
+ if (entry == null)
+ {
+ entry = createToken();
+ tokens.put(tokenId, entry);
+ entry.setUserName(credentials.getUsername());
+ entry.setPassword(credentials.getPassword());
+ }
+ entry.setExpirationTime(expirationTime);
+ return entry.getToken();
+ }
+
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenEntry.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenEntry.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TokenEntry.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,66 @@
+/*
+ * 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.web.security.security;
+
+import org.chromattic.api.annotations.Destroy;
+import org.chromattic.api.annotations.Name;
+import org.chromattic.api.annotations.PrimaryType;
+import org.chromattic.api.annotations.Property;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.GateInToken;
+
+import java.util.Date;
+
+/**
+ * @author <a href="mailto:julien.viet@exoplatform.com">Julien
Viet</a>
+ * @version $Revision$
+ */
+@PrimaryType(name = "tkn:tokenentry")
+public abstract class TokenEntry
+{
+
+ @Name
+ public abstract String getId();
+
+ @Property(name = "username")
+ public abstract String getUserName();
+
+ public abstract void setUserName(String userName);
+
+ @Property(name = "password")
+ public abstract String getPassword();
+
+ public abstract void setPassword(String password);
+
+ @Property(name = "expiration")
+ public abstract Date getExpirationTime();
+
+ public abstract void setExpirationTime(Date expirationTime);
+
+ @Destroy
+ public abstract void remove();
+
+ public GateInToken getToken()
+ {
+ return new GateInToken(
+ getExpirationTime().getTime(),
+ new Credentials(getUserName(), getPassword()));
+ }
+
+}
Added:
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
===================================================================
---
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java
(rev 0)
+++
portal/trunk/component/web/security/src/main/java/org/exoplatform/web/security/security/TransientTokenService.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,89 @@
+/**
+ * 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.web.security.security;
+
+import org.exoplatform.container.xml.InitParams;
+import org.exoplatform.web.security.Credentials;
+import org.exoplatform.web.security.GateInToken;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by The eXo Platform SAS Author : liem.nguyen ncliam(a)gmail.com Jun 5,
+ * 2009
+ */
+public class TransientTokenService extends AbstractTokenService<GateInToken,
String>
+{
+
+ protected final ConcurrentHashMap<String, GateInToken> tokens = new
ConcurrentHashMap<String, GateInToken>();
+
+ public TransientTokenService(InitParams initParams)
+ {
+ super(initParams);
+ }
+
+ public String createToken(Credentials credentials)
+ {
+ if (validityMillis < 0)
+ {
+ throw new IllegalArgumentException();
+ }
+ if (credentials == null)
+ {
+ throw new NullPointerException();
+ }
+ String tokenId = nextTokenId();
+ long expirationTimeMillis = System.currentTimeMillis() + validityMillis;
+ tokens.put(tokenId, new GateInToken(expirationTimeMillis, credentials));
+ return tokenId;
+ }
+
+ @Override
+ public GateInToken getToken(String id)
+ {
+ return tokens.get(id);
+ }
+
+ @Override
+ protected String decodeKey(String stringKey)
+ {
+ return stringKey;
+ }
+
+ @Override
+ public GateInToken deleteToken(String id)
+ {
+ GateInToken token = tokens.get(id);
+ tokens.remove(id);
+ return token;
+ }
+
+ @Override
+ public String[] getAllTokens()
+ {
+ return tokens.keySet().toArray(new String[]{});
+ }
+
+ @Override
+ public long size() throws Exception
+ {
+ return tokens.size();
+ }
+}
Added: portal/trunk/component/web/server/pom.xml
===================================================================
--- portal/trunk/component/web/server/pom.xml (rev 0)
+++ portal/trunk/component/web/server/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -0,0 +1,54 @@
+<!--
+ ~ 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.
+ -->
+
+<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </parent>
+
+ <modelVersion>4.0.0</modelVersion>
+ <artifactId>exo.portal.component.web.server</artifactId>
+ <packaging>jar</packaging>
+ <name>GateIn Portal Component Web Server</name>
+
+ <properties>
+ <maven.test.skip>true</maven.test.skip>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.captcha</groupId>
+ <artifactId>simplecaptcha</artifactId>
+ </dependency>
+ </dependencies>
+</project>
Copied: portal/trunk/component/web/server/src/main/java/org/exoplatform/download (from rev
3698, portal/trunk/component/web/src/main/java/org/exoplatform/download)
Copied: portal/trunk/component/web/server/src/main/java/org/exoplatform/services (from rev
3698, portal/trunk/component/web/src/main/java/org/exoplatform/services)
Copied: portal/trunk/component/web/server/src/main/java/org/exoplatform/upload (from rev
3698, portal/trunk/component/web/src/main/java/org/exoplatform/upload)
Added:
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
===================================================================
---
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java
(rev 0)
+++
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/DownloadHandler.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,109 @@
+/**
+ * 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.web.handler;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.download.DownloadResource;
+import org.exoplatform.download.DownloadService;
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.command.Command;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URLEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : LeBienThuy
+ * thuy.le(a)exoplatform.com
+ * Dec 9, 2006
+ */
+public class DownloadHandler extends Command
+{
+
+ private String resourceId;
+
+ @SuppressWarnings("unused")
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ {
+ res.setHeader("Cache-Control", "private max-age=600,
s-maxage=120");
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ DownloadService dservice =
(DownloadService)container.getComponentInstanceOfType(DownloadService.class);
+ DownloadResource dresource = dservice.getDownloadResource(resourceId);
+ if (dresource == null)
+ {
+ res.setContentType("text/plain");
+ res.getWriter().write("NO DOWNDLOAD RESOURCE CONTENT OR YOU DO NOT HAVE
THE RIGHT TO ACCESS THE CONTENT");
+ return;
+ }
+ String userAgent = req.getHeader("User-Agent");
+ if (dresource.getDownloadName() != null)
+ {
+ if (userAgent != null && userAgent.contains("MSIE"))
+ {
+ res.setHeader("Content-Disposition",
"attachment;filename=\""
+ + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") +
"\"");
+ }
+ else
+ {
+ res.setHeader("Content-Disposition", "attachment;
filename*=utf-8''"
+ + URLEncoder.encode(dresource.getDownloadName(), "UTF-8") +
"");
+ }
+ }
+ res.setContentType(dresource.getResourceMimeType());
+ InputStream is = dresource.getInputStream();
+ try
+ {
+ optimalRead(is, res.getOutputStream());
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ finally
+ {
+ is.close();
+ }
+ }
+
+ public String getResourceId()
+ {
+ return resourceId;
+ }
+
+ private static void optimalRead(InputStream is, OutputStream os) throws Exception
+ {
+ int bufferLength = 1024; //TODO: Better to compute bufferLength in term of -Xms,
-Xmx properties
+ int readLength = 0;
+ while (readLength > -1)
+ {
+ byte[] chunk = new byte[bufferLength];
+ readLength = is.read(chunk);
+ if (readLength > 0)
+ {
+ os.write(chunk, 0, readLength);
+ }
+ }
+ }
+}
\ No newline at end of file
Added:
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
===================================================================
---
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java
(rev 0)
+++
portal/trunk/component/web/server/src/main/java/org/exoplatform/web/handler/UploadHandler.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -0,0 +1,138 @@
+/**
+ * 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.web.handler;
+
+import org.exoplatform.container.ExoContainer;
+import org.exoplatform.container.ExoContainerContext;
+import org.exoplatform.upload.UploadResource;
+import org.exoplatform.upload.UploadService;
+import org.exoplatform.web.WebAppController;
+import org.exoplatform.web.command.Command;
+
+import java.io.Writer;
+import java.net.URLEncoder;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+/**
+ * Created by The eXo Platform SARL
+ * Author : Nhu Dinh Thuan
+ * nhudinhthuan(a)exoplatform.com
+ * Dec 9, 2006
+ */
+public class UploadHandler extends Command
+{
+
+ static enum UploadServiceAction {
+ PROGRESS, UPLOAD, DELETE, ABORT
+ }
+
+ private String action;
+
+ private String[] uploadId;
+
+ public void setAction(String action)
+ {
+ this.action = action;
+ }
+
+ public void setUploadId(String[] uploadId)
+ {
+ this.uploadId = uploadId;
+ }
+
+ @SuppressWarnings("unused")
+ public void execute(WebAppController controller, HttpServletRequest req,
HttpServletResponse res) throws Exception
+ {
+ res.setHeader("Cache-Control", "no-cache");
+
+ ExoContainer container = ExoContainerContext.getCurrentContainer();
+ UploadService service =
(UploadService)container.getComponentInstanceOfType(UploadService.class);
+ if (action == null || action.length() < 1)
+ return;
+
+ UploadServiceAction uploadActionService =
UploadServiceAction.valueOf(action.toUpperCase());
+ if (uploadActionService == UploadServiceAction.PROGRESS)
+ {
+ Writer writer = res.getWriter();
+ if (uploadId == null)
+ return;
+ StringBuilder value = new StringBuilder();
+ value.append("{\n upload : {");
+ for (int i = 0; i < uploadId.length; i++)
+ {
+ UploadResource upResource = service.getUploadResource(uploadId[i]);
+ if (upResource == null)
+ continue;
+ if (upResource.getStatus() == UploadResource.FAILED_STATUS)
+ {
+ int limitMB = service.getUploadLimitsMB().get(uploadId[i]).intValue();
+ value.append("\n
\"").append(uploadId[i]).append("\": {");
+ value.append("\n
\"status\":").append('\"').append("failed").append("\",");
+ value.append("\n
\"size\":").append('\"').append(limitMB).append("\"");
+ value.append("\n }");
+ continue;
+ }
+ double percent = 100;
+ if (upResource.getStatus() == UploadResource.UPLOADING_STATUS)
+ {
+ percent = (upResource.getUploadedSize() * 100) /
upResource.getEstimatedSize();
+ }
+ value.append("\n
\"").append(uploadId[i]).append("\": {");
+ value.append("\n
\"percent\":").append('\"').append((int)percent).append("\",");
+ value.append("\n
\"fileName\":").append('\"').append(encodeName(upResource.getFileName()))
+ .append("\"");
+ value.append("\n }");
+ if (i < uploadId.length - 1)
+ value.append(',');
+ }
+ value.append("\n }\n}");
+ writer.append(value);
+ }
+ else if (uploadActionService == UploadServiceAction.UPLOAD)
+ {
+ service.createUploadResource(req);
+ }
+ else if (uploadActionService == UploadServiceAction.DELETE)
+ {
+ service.removeUpload(uploadId[0]);
+ }
+ else if (uploadActionService == UploadServiceAction.ABORT)
+ {
+ //TODO: dang.tung - we don't need 2 statements because it'll show error
when we reload browser
+ //UploadResource upResource = service.getUploadResource(uploadId[0]);
+ //if(upResource != null) upResource.setStatus(UploadResource.UPLOADED_STATUS) ;
+ service.removeUpload(uploadId[0]);
+ }
+ }
+
+ public String encodeName(String name) throws Exception
+ {
+ String[] arr = name.split(" ");
+ String str = "";
+ for (int i = 0; i < arr.length; i++)
+ {
+ str += " " + URLEncoder.encode(arr[i], "UTF-8");
+ }
+ return str;
+ }
+
+}
\ No newline at end of file
Modified: portal/trunk/examples/extension/ear/pom.xml
===================================================================
--- portal/trunk/examples/extension/ear/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/examples/extension/ear/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.api</artifactId>
<version>3.2.0-Beta01-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Modified: portal/trunk/examples/extension/jar/pom.xml
===================================================================
--- portal/trunk/examples/extension/jar/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/examples/extension/jar/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -36,7 +36,7 @@
<dependencies>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.api</artifactId>
</dependency>
</dependencies>
</project>
Modified: portal/trunk/examples/portal/ear/pom.xml
===================================================================
--- portal/trunk/examples/portal/ear/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/examples/portal/ear/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -46,7 +46,7 @@
</dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.api</artifactId>
<version>3.2.0-Beta01-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
Modified: portal/trunk/examples/portal/jar/pom.xml
===================================================================
--- portal/trunk/examples/portal/jar/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/examples/portal/jar/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -36,7 +36,7 @@
<dependencies>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.api</artifactId>
</dependency>
</dependencies>
</project>
Modified: portal/trunk/gadgets/core/pom.xml
===================================================================
--- portal/trunk/gadgets/core/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/gadgets/core/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -62,20 +62,33 @@
</resources>
</build>
<dependencies>
- <dependency>
+ <dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
- <scope>provided</scope>
- </dependency>
+ <artifactId>exo.portal.component.common</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.security</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.kernel</groupId>
+ <artifactId>exo.kernel.container</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.gatein.shindig</groupId>
+ <artifactId>shindig-gadgets</artifactId>
+ </dependency>
<dependency>
<groupId>org.gatein.shindig</groupId>
<artifactId>shindig-common</artifactId>
- <type>jar</type>
</dependency>
<dependency>
<groupId>org.gatein.shindig</groupId>
<artifactId>shindig-features</artifactId>
- <type>jar</type>
</dependency>
<dependency>
<groupId>org.chromattic</groupId>
Modified: portal/trunk/gadgets/eXoGadgets/pom.xml
===================================================================
--- portal/trunk/gadgets/eXoGadgets/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/gadgets/eXoGadgets/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -38,7 +38,7 @@
<dependencies>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.security</artifactId>
<scope>provided</scope>
</dependency>
Modified: portal/trunk/packaging/jboss-as/ear/pom.xml
===================================================================
--- portal/trunk/packaging/jboss-as/ear/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/packaging/jboss-as/ear/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -88,10 +88,22 @@
</dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.security</artifactId>
</dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component.portal</artifactId>
</dependency>
<dependency>
Modified: portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js
===================================================================
---
portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/packaging/module/src/main/javascript/portal.packaging.module.js 2010-07-23
21:22:58 UTC (rev 3699)
@@ -97,10 +97,24 @@
module.component.management =
new Project("org.exoplatform.portal",
"exo.portal.component.management", "jar", module.version);
- module.component.web =
- new Project("org.exoplatform.portal", "exo.portal.component.web",
"jar", module.version).
+ module.component.web = {}
+ module.component.web.controller =
+ new Project("org.exoplatform.portal",
"exo.portal.component.web.controller", "jar", module.version).
+ addDependency(module.component.common);
+
+ module.component.web.security =
+ new Project("org.exoplatform.portal",
"exo.portal.component.web.security", "jar", module.version).
+ addDependency(module.component.web.controller).
addDependency(module.component.scripting);
+ module.component.web.server =
+ new Project("org.exoplatform.portal",
"exo.portal.component.web.server", "jar", module.version).
+ addDependency(module.component.web.controller).
+ addDependency(module.component.scripting);
+
+ module.component.web.api =
+ new Project("org.exoplatform.portal",
"exo.portal.component.web.api", "jar", module.version);
+
module.component.portal =
new Project("org.exoplatform.portal",
"exo.portal.component.portal", "jar", module.version).
addDependency(new Project("org.gatein.mop", "mop-api",
"jar", mopVersion)).
@@ -118,7 +132,7 @@
addDependency(new Project("org.reflext", "reflext.spi",
"jar", reflectVersion)).
addDependency(new Project("org.reflext", "reflext.jlr",
"jar", reflectVersion)).
addDependency(new Project("org.reflext", "reflext.api",
"jar", reflectVersion)).
- addDependency(module.component.web);
+ addDependency(module.component.web.security);
module.component.identity =
new Project("org.exoplatform.portal",
"exo.portal.component.identity", "jar", module.version).
@@ -138,7 +152,10 @@
module.webui = {};
module.webui.framework =
new Project("org.exoplatform.portal",
"exo.portal.webui.framework", "jar", module.version).
- addDependency(module.component.web);
+ addDependency(module.component.web.server).
+ addDependency(module.component.web.security).
+ addDependency(module.component.web.api).
+ addDependency(module.component.web.controller);
module.webui.portlet =
new Project("org.exoplatform.portal", "exo.portal.webui.portlet",
"jar", module.version).
Modified: portal/trunk/pom.xml
===================================================================
--- portal/trunk/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -371,6 +371,26 @@
</dependency>
<dependency>
<groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.security</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.server</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.api</artifactId>
+ <version>3.2.0-Beta01-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
<artifactId>exo.portal.component.portal</artifactId>
<version>3.2.0-Beta01-SNAPSHOT</version>
</dependency>
Modified: portal/trunk/webui/core/pom.xml
===================================================================
--- portal/trunk/webui/core/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/webui/core/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -45,6 +45,14 @@
<artifactId>exo.portal.component.portal</artifactId>
</dependency>
<dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.server</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.web.api</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.gatein.common</groupId>
<artifactId>common-common</artifactId>
</dependency>
Modified:
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/wysiwyg/FCKEditor.java
===================================================================
---
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/wysiwyg/FCKEditor.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/webui/core/src/main/java/org/exoplatform/webui/form/wysiwyg/FCKEditor.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -19,8 +19,6 @@
package org.exoplatform.webui.form.wysiwyg;
-import com.sun.syndication.io.impl.PropertiesLoader;
-
import org.exoplatform.web.resource.config.xml.FCKConfigListener;
import java.util.regex.Matcher;
Modified: portal/trunk/webui/framework/pom.xml
===================================================================
--- portal/trunk/webui/framework/pom.xml 2010-07-23 11:14:58 UTC (rev 3698)
+++ portal/trunk/webui/framework/pom.xml 2010-07-23 21:22:58 UTC (rev 3699)
@@ -34,8 +34,16 @@
<dependencies>
<dependency>
<groupId>org.exoplatform.portal</groupId>
- <artifactId>exo.portal.component.web</artifactId>
+ <artifactId>exo.portal.component.web.controller</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.resources</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.exoplatform.portal</groupId>
+ <artifactId>exo.portal.component.scripting</artifactId>
+ </dependency>
</dependencies>
<build>
Modified:
portal/trunk/webui/framework/src/main/java/org/exoplatform/webui/core/UIComponent.java
===================================================================
---
portal/trunk/webui/framework/src/main/java/org/exoplatform/webui/core/UIComponent.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/webui/framework/src/main/java/org/exoplatform/webui/core/UIComponent.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -35,7 +35,6 @@
import org.exoplatform.webui.event.EventListener;
import org.exoplatform.webui.event.MonitorEvent;
-import java.util.ArrayList;
import java.util.List;
/** Created by The eXo Platform SAS May 7, 2006 */
Modified:
portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java
===================================================================
---
portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2010-07-23
11:14:58 UTC (rev 3698)
+++
portal/trunk/webui/portlet/src/main/java/org/exoplatform/webui/application/portlet/PortletApplication.java 2010-07-23
21:22:58 UTC (rev 3699)
@@ -37,7 +37,6 @@
import org.exoplatform.webui.event.Event.Phase;
import java.io.IOException;
-import java.io.Writer;
import java.util.Locale;
import java.util.ResourceBundle;