diff --git a/.classpath b/.classpath
new file mode 100644
index 0000000..0f4a4c2
--- /dev/null
+++ b/.classpath
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.project b/.project
new file mode 100644
index 0000000..9822942
--- /dev/null
+++ b/.project
@@ -0,0 +1,42 @@
+
+
+ landing-page-hook
+
+
+
+
+
+ org.eclipse.wst.jsdt.core.javascriptValidator
+
+
+
+
+ org.eclipse.jdt.core.javabuilder
+
+
+
+
+ org.eclipse.wst.common.project.facet.core.builder
+
+
+
+
+ org.eclipse.wst.validation.validationbuilder
+
+
+
+
+ org.eclipse.m2e.core.maven2Builder
+
+
+
+
+
+ org.eclipse.jem.workbench.JavaEMFNature
+ org.eclipse.wst.common.modulecore.ModuleCoreNature
+ org.eclipse.jdt.core.javanature
+ org.eclipse.m2e.core.maven2Nature
+ org.eclipse.wst.common.project.facet.core.nature
+ org.eclipse.wst.jsdt.core.jsNature
+
+
diff --git a/.settings/.jsdtscope b/.settings/.jsdtscope
new file mode 100644
index 0000000..b72a6a4
--- /dev/null
+++ b/.settings/.jsdtscope
@@ -0,0 +1,13 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..8fb0e26
--- /dev/null
+++ b/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+eclipse.preferences.version=1
+encoding//src/main/java=UTF-8
+encoding//src/main/resources=UTF-8
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..69c31cd
--- /dev/null
+++ b/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,8 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/.settings/org.eclipse.m2e.core.prefs b/.settings/org.eclipse.m2e.core.prefs
new file mode 100644
index 0000000..e6f7678
--- /dev/null
+++ b/.settings/org.eclipse.m2e.core.prefs
@@ -0,0 +1,4 @@
+activeProfiles=Liferay-v6.2-CE-(Tomcat-7)-(2)
+eclipse.preferences.version=1
+resolveWorkspaceProjects=true
+version=1
diff --git a/.settings/org.eclipse.wst.common.component b/.settings/org.eclipse.wst.common.component
new file mode 100644
index 0000000..9349422
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.component
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml
new file mode 100644
index 0000000..1e1fabd
--- /dev/null
+++ b/.settings/org.eclipse.wst.common.project.facet.core.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.container b/.settings/org.eclipse.wst.jsdt.ui.superType.container
new file mode 100644
index 0000000..3bd5d0a
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.container
@@ -0,0 +1 @@
+org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
diff --git a/.settings/org.eclipse.wst.jsdt.ui.superType.name b/.settings/org.eclipse.wst.jsdt.ui.superType.name
new file mode 100644
index 0000000..05bd71b
--- /dev/null
+++ b/.settings/org.eclipse.wst.jsdt.ui.superType.name
@@ -0,0 +1 @@
+Window
\ No newline at end of file
diff --git a/.settings/org.eclipse.wst.validation.prefs b/.settings/org.eclipse.wst.validation.prefs
new file mode 100644
index 0000000..04cad8c
--- /dev/null
+++ b/.settings/org.eclipse.wst.validation.prefs
@@ -0,0 +1,2 @@
+disabled=06target
+eclipse.preferences.version=1
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..dd4a107
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,98 @@
+
+
+
+ 4.0.0
+ org.gcube.portal.liferay
+ landing-page-hook
+ war
+ landing-page-hook Hook
+ 6.3.0-SNAPSHOT
+
+
+
+ com.liferay.maven.plugins
+ liferay-maven-plugin
+ ${liferay.maven.plugin.version}
+
+ ${liferay.auto.deploy.dir}
+ ${liferay.app.server.deploy.dir}
+ ${liferay.app.server.lib.global.dir}
+ ${liferay.app.server.portal.dir}
+ ${liferay.version}
+ hook
+
+
+
+ maven-compiler-plugin
+ 2.5
+
+ UTF-8
+ 1.6
+ 1.6
+
+
+
+ maven-resources-plugin
+ 2.5
+
+ UTF-8
+
+
+
+
+
+
+ com.liferay.portal
+ portal-service
+ ${liferay.version}
+ provided
+
+
+ com.liferay.portal
+ util-java
+ ${liferay.version}
+ provided
+
+
+ javax.portlet
+ portlet-api
+ 2.0
+ provided
+
+
+ javax.servlet
+ servlet-api
+ 2.4
+ provided
+
+
+ javax.servlet.jsp
+ jsp-api
+ 2.0
+ provided
+
+
+ org.slf4j
+ slf4j-log4j12
+ 1.6.4
+
+
+ org.slf4j
+ slf4j-api
+ 1.6.4
+
+
+
+
+ Liferay-v6.2-CE-(Tomcat-7)-(2)
+
+ 6.2.5
+ 6.2.5
+ /Users/massi/portal/liferay-portal-6.2-ce-ga6/deploy
+ /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps
+ /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/lib/ext
+ /Users/massi/portal/liferay-portal-6.2-ce-ga6/tomcat-7.0.62/webapps/ROOT
+
+
+
+
\ No newline at end of file
diff --git a/src/main/java/org/gcube/portal/events/LandingPageAction.java b/src/main/java/org/gcube/portal/events/LandingPageAction.java
new file mode 100644
index 0000000..6309bf2
--- /dev/null
+++ b/src/main/java/org/gcube/portal/events/LandingPageAction.java
@@ -0,0 +1,150 @@
+package org.gcube.portal.events;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpSession;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.liferay.portal.kernel.events.Action;
+import com.liferay.portal.kernel.events.ActionException;
+import com.liferay.portal.kernel.exception.PortalException;
+import com.liferay.portal.kernel.exception.SystemException;
+import com.liferay.portal.kernel.struts.LastPath;
+import com.liferay.portal.kernel.util.PropsKeys;
+import com.liferay.portal.kernel.util.PropsUtil;
+import com.liferay.portal.kernel.util.StringBundler;
+import com.liferay.portal.kernel.util.StringPool;
+import com.liferay.portal.kernel.util.WebKeys;
+import com.liferay.portal.model.Group;
+import com.liferay.portal.model.User;
+import com.liferay.portal.model.VirtualHost;
+import com.liferay.portal.service.GroupLocalServiceUtil;
+import com.liferay.portal.service.LayoutSetLocalServiceUtil;
+import com.liferay.portal.service.UserLocalServiceUtil;
+import com.liferay.portal.service.VirtualHostLocalServiceUtil;
+import com.liferay.portal.util.PortalUtil;
+
+public class LandingPageAction extends Action {
+
+ private static final Logger _log = LoggerFactory.getLogger(LandingPageAction.class);
+
+ public static final String GUEST_GROUP_FRIENDLY_URL = "/guest";
+ public static final String PRIVATE_GROUP_SERVLET_MAPPING = PropsUtil.get(PropsKeys.LAYOUT_FRIENDLY_URL_PRIVATE_GROUP_SERVLET_MAPPING);
+ public static final String PORTAL_CONTEXT = PortalUtil.getPathContext();
+
+ @Override
+ public void run(HttpServletRequest request, HttpServletResponse response) throws ActionException {
+
+ _log.info("LandingPageAction is ON");
+
+ HttpSession session = request.getSession();
+ String path = "";
+ try {
+ path = getCustomLandingPage(request);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ session.setAttribute(WebKeys.LAST_PATH, new LastPath(StringPool.BLANK, path));
+ }
+ /**
+ * Returns custom landing page path after user login
+ *
+ * @param request
+ * @return
+ * @throws PortalException
+ * @throws SystemException
+ */
+ private String getCustomLandingPage(final HttpServletRequest request) throws PortalException, SystemException {
+ String customLandingPagePath ="";
+ customLandingPagePath = getLandingPagePath(request);
+ _log.info("Provate Site LandingPage Path = " + customLandingPagePath);
+ return customLandingPagePath;
+ }
+
+
+ public String getLandingPagePath(final HttpServletRequest request) throws PortalException, SystemException {
+ String sitePath = StringPool.BLANK;
+
+ User currentUser = PortalUtil.getUser(request);
+
+ String currentVirtualHost = request.getServerName();
+ _log.debug("currentHost is " + currentVirtualHost);
+ Group site = null;
+ List vHosts = VirtualHostLocalServiceUtil.getVirtualHosts(0, VirtualHostLocalServiceUtil.getVirtualHostsCount());
+ for (VirtualHost virtualHost : vHosts) {
+ _log.debug("Found " + virtualHost.getHostname());
+ if (virtualHost.getHostname().compareTo("localhost") != 0 &&
+ virtualHost.getLayoutSetId() != 0 &&
+ virtualHost.getHostname().compareTo(currentVirtualHost) == 0) {
+ long layoutSetId = virtualHost.getLayoutSetId();
+ site = LayoutSetLocalServiceUtil.getLayoutSet(layoutSetId).getGroup();
+ _log.debug("Found match! Your site is " + site.getName());
+ List userSites = getSites(currentUser.getUserId());
+ boolean isRegistered = false;
+ for (Group group : userSites) {
+ if (group.getGroupId() == site.getGroupId()) {
+ isRegistered = true;
+ _log.debug("user " + currentUser.getFullName() + " is registered to " + site.getName() + ". redirecting ...");
+ break;
+ }
+ }
+ if (! isRegistered)
+ _log.debug("But user " + currentUser.getFullName() + " is not registered to " + site.getName() + ". going to register ...");
+ registerUserToSite(currentUser, site);
+ break;
+ }
+ }
+ if (site.getPrivateLayoutsPageCount() > 0) {
+ sitePath = getGroupFriendlyURL(request, site);
+ } else {
+ _log.debug(site.getName() + " site doesn't have any private page. Default landing page will be used");
+ }
+ return sitePath;
+ }
+ /**
+ * this method is used to register the user to the group if does not belong to it yet
+ * IMPORTANT: it does not add the user to the Site's private pages if the Site Membership type is different from Private
+ * @param user
+ * @param site
+ * @throws SystemException
+ */
+ private void registerUserToSite(User user, Group site) throws SystemException {
+ UserLocalServiceUtil.addGroupUser(site.getGroupId(), user.getUserId());
+ _log.debug("User " + user.getScreenName() +" registered to " + site.getName());
+ }
+
+ public static List getSites(final long userId) throws PortalException, SystemException {
+ List sites = new ArrayList();
+ for (Group group : GroupLocalServiceUtil.getUserGroups(userId)) {
+ if (group.isRegularSite()
+ && !GUEST_GROUP_FRIENDLY_URL.equalsIgnoreCase(group.getFriendlyURL())) {
+ sites.add(group);
+ }
+ }
+ return sites;
+ }
+
+ /**
+ * @param request
+ * @param currentGroup
+ * @param isPrivate
+ * @param isUser
+ * @return
+ * @throws PortalException
+ * @throws SystemException
+ */
+ public static String getGroupFriendlyURL(final HttpServletRequest request, final Group currentGroup) throws PortalException, SystemException {
+ String friendlyURL = PRIVATE_GROUP_SERVLET_MAPPING;
+ StringBundler sb = new StringBundler();
+ sb.append(PORTAL_CONTEXT);
+ sb.append(friendlyURL);
+ sb.append(currentGroup.getFriendlyURL());
+ return sb.toString();
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/resources/clientlog4j.properties b/src/main/resources/clientlog4j.properties
new file mode 100644
index 0000000..4a2e1cd
--- /dev/null
+++ b/src/main/resources/clientlog4j.properties
@@ -0,0 +1,12 @@
+log4j.rootLogger=DEBUG, A1
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+
+# Print the date in ISO 8601 format
+log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
+
+# Print only messages of level TRACE or above in the package org.gcube
+log4j.logger.org.gcube=TRACE
+log4j.logger.org.gcube.application.framework.core.session=INFO
+log4j.logger.org.gcube.common.scope.impl.DefaultScopeProvider=ERROR
+log4j.logger.com.netflix.astyanax.connectionpool.impl.CountingConnectionPoolMonitor=ERROR
\ No newline at end of file
diff --git a/src/main/resources/portal.properties b/src/main/resources/portal.properties
new file mode 100644
index 0000000..c56ed7e
--- /dev/null
+++ b/src/main/resources/portal.properties
@@ -0,0 +1,3 @@
+#
+#Wed Feb 24 09:56:00 CET 2016
+login.events.post=org.gcube.portal.events.LandingPageAction
diff --git a/src/main/webapp/WEB-INF/liferay-hook.xml b/src/main/webapp/WEB-INF/liferay-hook.xml
new file mode 100644
index 0000000..944195a
--- /dev/null
+++ b/src/main/webapp/WEB-INF/liferay-hook.xml
@@ -0,0 +1,6 @@
+
+
+
+
+ portal.properties
+
\ No newline at end of file
diff --git a/src/main/webapp/WEB-INF/liferay-plugin-package.properties b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
new file mode 100644
index 0000000..68b86d1
--- /dev/null
+++ b/src/main/webapp/WEB-INF/liferay-plugin-package.properties
@@ -0,0 +1,10 @@
+name=landing-page-hook
+module-group-id=liferay
+module-incremental-version=1
+tags=
+short-description=
+change-log=
+page-url=http://www.gcube-system.org
+author=M. Assante
+licenses=EUPL
+liferay-versions=6.2.0+,6.2.10+
diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..7d8c082
--- /dev/null
+++ b/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file