2 Replies Latest reply on Aug 16, 2010 6:40 AM by xuamao

    how redirect to URL after login?

    fernando2010

      Hi

       

      assuming that i have several portals with their respectly set of users, how can I redirect to a specific URL depending of user?


      per example exist two portals:


      1) http://localhost:8080/portal/private/pepsi
      with an user:
      - pepsi1


      2) http://localhost:8080/portal/private/coca_cola
      with an user:
      - coca1


      then, when the user "pepsi1" sign in, I want that redirect to:
      http://localhost:8080/portal/private/pepsi
      Is posssible this? how do it?

       

      isn't so, how change the default URL after login? what configuration file i must to edit?

       

      regards

        • 1. Re: how redirect to URL after login?
          trong.tran

          then, when the user "pepsi1" sign in, I want that redirect to:
          http://localhost:8080/portal/private/pepsi
          Is  posssible this? how do it?

           

          No, it's not possible for now and it has been addressed by https://jira.jboss.org/browse/GTNPORTAL-879. You could add more information that you need for that feature to the JIRA issue, so hopefully it will be available soon.

          isn't so, how change the default URL after login? what configuration  file i must to edit?

          It is not configurable for now too, but you can customize our login form and use a parameter initialURI to specify a URL which will be redirected to after login. For instance in your case, initialURI=/portal/private/pepsi.

          • 2. Re: how redirect to URL after login?
            xuamao

            in exo.portal.component.web.jar there is java class called PortalLoginController.java

             

            Here is the code of function

             

            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";

                      //You can insert your functional component, to control the redirection after login.

                      //and overwrite the original PortalLoginController.java in web.xml


                     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);
               }

            1 of 1 people found this helpful