Ejemplo n.º 1
0
  public static void setLoginAttributes(
      HttpSession session, HttpServletRequest request, UserData user, String uuid, String loginType)
      throws Exception {

    String userName = user.getUserName();
    session.setAttribute("userName", userName);
    session.setAttribute("user", user);
    session.setAttribute("uuid", uuid);
    session.setAttribute(ClientConstants.LoginType, loginType);
    // session.setAttribute("password", password);

    log.info("User " + userName + " logged in from " + Utilities.getRemoteHostName(request));
    System.setProperty("adminDefaultLoginName", userName);
  }
Ejemplo n.º 2
0
  public String doPost() throws Exception {
    TEMPLATE_NAME = "index.vm";
    String type = request.getParameter("ltype");
    try {
      HttpSession session = request.getSession();
      Object userName = session.getAttribute("userName");
      if (type.equalsIgnoreCase("logout")) {
        session.invalidate();
        session = null;
      } else if (type.equalsIgnoreCase("login")) {
        String loginParameters = request.getParameter("loginParameters");

        // {"id":"1052698364","birthday":"11/28/1982","email":"*****@*****.**","first_name":"Srinivas","gender":"male",
        // "last_name":"Kummaragunta","link":"https://www.facebook.com/app_scoped_user_id/1052698364/",
        // "location":{"id":"115200305158163","name":"Hyderabad, India"},"locale":"en_US",
        // "name":"Srinivas Kummaragunta","timezone":5.5,"updated_time":"2015-11-23T01:37:00
        // 0000","verified":true}
        Gson gson = new Gson();
        UserData user = gson.fromJson(loginParameters, UserData.class);

        int timeOut = ClientConstants.COOKIE_AGE;
        String uuid = UUID.randomUUID().toString();
        // String encryptedUuid = Encryption.encrypt(uuid);
        Utilities.addCookie(
            response, ClientConstants.COOKIE_NAME, uuid, ClientConstants.COOKIE_AGE);
        // ClientConstants.sessions.put(uuid, user);
        timeOut = ClientConstants.PERSISTANCE_COOKIE_AGE;
        setLoginAttributes(session, request, user, uuid, LoginType.FULL_AUTHENTICATION.toString());
        // SessionHelper.createUserSession(request, uuid,
        // user.getId(),timeOut);s
        log.debug("After Login UUID ::" + uuid);
      } else if (type.equalsIgnoreCase("logout")) {
        session.invalidate();
        session = null;
      } else if (userName != null) {

      }
    } catch (Exception e) {
      log.debug(e);
    }
    return TEMPLATE_NAME;
  }
Ejemplo n.º 3
0
  private String handleLogin() throws Exception {
    String userName = addToContext("lusername", false);
    String password = request.getParameter("password");
    String rememberUserNameString = request.getParameter("rememberUserName");
    boolean rememberUserName = rememberUserNameString != null;

    HttpSession session = request.getSession();
    int loginFailureCount = getLoginFailureCount(session);

    if (loginFailureCount > 3) {
      if (verifyReCaptcha()) {
        log.debug("Answer was entered correctly!");
      } else {
        throw new Exception("ReCaptcha answer is incorrect!");
      }
    }

    // This is to signin user after signup
    userName = (String) ((userName == null) ? request.getParameter("suserName") : userName);
    password = (String) ((password == null) ? request.getParameter("spassword") : password);

    log.debug("User " + userName + " rememberUserName " + rememberUserName);
    UserData user = new UserData();
    try {
      log.debug("logging in: handleLogin");
      // TODO: Verify User Credentials
      user.setUserName(userName);
      if (userName == null
          || userName.trim().length() == 0
          || password == null
          || password.trim().length() == 0) {
        throw new LoginException("Invalid Credentials!");
      }
      user.setPassword(AuthenticationUtils.createPassword(password));

      UserDao userDao = (UserDao) ModelFactory.getImplementation(user);
      user = (UserData) userDao.read();

      if (user == null) {
        throw new LoginException("Invalid Credentials!");
      }
      log.debug("login attributes set");
    } catch (Exception e) {
      // request.getSession().invalidate();
      System.setProperty("loginName", "");
      log.info("Login failed. Username="******"Invalid username or password");
      log.debug(e);
      throw e;
    }

    int timeOut = ClientConstants.COOKIE_AGE;
    String uuid = UUID.randomUUID().toString();
    if (rememberUserName) {
      // String encryptedUuid = Encryption.encrypt(uuid);
      Utilities.addCookie(response, ClientConstants.COOKIE_NAME, uuid, ClientConstants.COOKIE_AGE);
      // ClientConstants.sessions.put(uuid, user);
      timeOut = ClientConstants.PERSISTANCE_COOKIE_AGE;
    }
    setLoginAttributes(
        request.getSession(), request, user, uuid, LoginType.FULL_AUTHENTICATION.toString());
    SessionHelper.createUserSession(request, uuid, user.getId(), timeOut);
    log.debug("After Login UUID ::" + uuid);

    redirectToPrevUrl(ClientConstants.servletPageWithDefaultAction);
    return null;
  }