title: How to land users to different page as per their roles
body: <p>I am using Liferay and want to show different landing pages after users log in: If the admin of a portal try to login-in, he will land to page A and if a guest login into the portal he will login to page B.
  @Today15 I have done this..</p>
  
  <pre><code>    package com.landing.page.pagetwo;
  import java.util.ArrayList;
  import java.util.List;
  
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  import javax.servlet.http.HttpSession;
  
  import com.liferay.portal.kernel.log.LogFactoryUtil;
  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.log.Log;
  import com.liferay.portal.kernel.struts.LastPath;
  import com.liferay.portal.kernel.util.PrefsPropsUtil;
  import com.liferay.portal.kernel.util.PropsKeys;
  import com.liferay.portal.kernel.util.StringPool;
  import com.liferay.portal.kernel.util.Validator;
  import com.liferay.portal.kernel.util.WebKeys;
  import com.liferay.portal.model.Group;
  import com.liferay.portal.model.User;
  import com.liferay.portal.service.GroupLocalServiceUtil;
  import com.liferay.portal.util.PortalUtil;
  
  public class LandingPage extends Action {
  
  @Override
  public void run(HttpServletRequest httpsreq, HttpServletResponse httpsres)
                throws ActionException {
      try {
          doRun(httpsreq, httpsres);
      }
      catch (Exception e) {
          throw new ActionException(e);
      }
  }
  protected void doRun(
          HttpServletRequest request, HttpServletResponse response)
          throws Exception {
  
          long companyId = PortalUtil.getCompanyId(request);
  
          String path =
              PrefsPropsUtil.getString(
                  companyId, PropsKeys.DEFAULT_LANDING_PAGE_PATH);
  
          if (_log.isInfoEnabled()) {
              _log.info(PropsKeys.DEFAULT_LANDING_PAGE_PATH + StringPool.EQUAL +
                  path);
          }
  
          if (Validator.isNull(path)) {
              path = getCustomLandingPage(request);
          }
  
          HttpSession session = request.getSession();
          session.setAttribute(WebKeys.LAST_PATH, new LastPath(
              StringPool.BLANK, path));
  
      }
  private String getCustomLandingPage(HttpServletRequest request)
          throws PortalException, SystemException {
  
          String customLandingPagePath = StringPool.BLANK;
  
  
          customLandingPagePath = getSitePath(PortalUtil.getUser(request), false);
  
          return customLandingPagePath;
      }
      private String getSitePath(User user, boolean includeLanguage)
              throws PortalException, SystemException {
  
              String sitePath = StringPool.BLANK;
              List&lt;Group&gt; userSites = getSites(user.getUserId());
  
              String language = StringPool.BLANK;
  
              if (includeLanguage) {
                  language = StringPool.SLASH + user.getLocale().getLanguage();
              }
  
              if ((userSites != null) &amp;&amp; !userSites.isEmpty()) {
                  String siteFriendlyURL = userSites.get(0).getFriendlyURL();
                  sitePath = language + "/group" + siteFriendlyURL + "/pagetwo";
              }
  
              return sitePath;
          }
      private List&lt;Group&gt; getSites(long userId)
              throws PortalException, SystemException {
  
              List&lt;Group&gt; sites = new ArrayList&lt;Group&gt;();
  
              for (Group group : GroupLocalServiceUtil.getUserGroups(userId)) {
                  if (group.isRegularSite() &amp;&amp;
                      !"Guest".equalsIgnoreCase(group.getName())) {
                      sites.add(group);
                      break;
                  }
              }
              return sites;
          }
  
          private static Log _log =
              LogFactoryUtil.getLog(LandingPage.class);
  }
  </code></pre>
  
  <p>Now i can land on my site's custom page. but how to ristrict other user to land from this page, and how to land them to other page.</p>