Package org.openqreg.bean

Examples of org.openqreg.bean.User


      return Response.status(Response.Status.FORBIDDEN).entity(rw)
          .build();
    }
   
   
    User user = Dispatcher.getInstance().getUser(la.getUserId());
    AjaxWidgetAnswer awa = new AjaxWidgetAnswer();
    // add default answer text, listboxtexts, guisettings, containers
    try {
      addDefaultAnswer(user, awr, awa);
    } catch (SQLException e) {
View Full Code Here


   */
  public void removeOldUsers() {
    this.getWriteLockUserTable();
    try {
      Vector<String> usersToRemove = new Vector<String>();
      User u = null;
      for (Iterator<User> e = currentUsers.values().iterator(); e
          .hasNext();) {
        u = e.next();
        // if current user has been inactive to long, remove from
        // currentusers
        if ((new Date().getTime() - u.getLastActivityTimeStamp()
            .getTime()) > (maxInactiveTimeBeforeRemoval * 60000L * 60)) {
          usersToRemove.add(u.getId());
        }
      }
      // remove from currentusers
      // this is done in a second loop to avoid problems when removing
      // from the treemap while itterating in the first loop
View Full Code Here

  public LoginAnswer LockUser(String userId, String token) {
    LoginAnswer la = isActive(userId, token);
    if (LoginAnswer.INACTIVE.equals(la.getStatus())) {
      return la;
    }
    User u = getUser(userId);
    GregorianCalendar gc = new GregorianCalendar();
//    gc.add(Calendar.YEAR, -10);
    gc.add(Calendar.MINUTE, -10000);
    u.setLastActivityTimeStamp(Converter.GCToSqlDate(gc));
    // return new
    // Long((Dispatcher.getInstance()).getTimeBeforeLogOut(userId));

    la = new LoginAnswer();
    la.setUserId(userId);
View Full Code Here

   * @return boolean: true if the users has unread systemmessages
   */
  public boolean showSystemMessage(String userId) {
    this.getReadLockSystemMessageTable();
    try {
      User currentUser = currentUsers.get(userId);
      String group = currentUser.getGroupid();

      // itterates all messages to check if we should show anny
      Set<Systemmessage> messages = systemMessageTable.containsKey(group) ? systemMessageTable
          .get(group) : new HashSet<Systemmessage>();
      Iterator<Systemmessage> messageIterator = messages.iterator();

      Date now = new Date();
      Date validFrom;
      Date validTo;
      Timestamp lastview;
      Systemmessage sm = null;

      while (messageIterator.hasNext()) {
        sm = messageIterator.next();
        validFrom = sm.getValidfrom();
        validTo = sm.getValidto();
        if (sm.getLanguageid().equals(currentUser.getLanguageid())
            && validFrom.before(now)) {
          if (null == validTo || validTo.after(now)) {
            // no validto date, or valid to date after now
            lastview = currentUser.getTslastviewedsystemmessage();
            if (null == lastview || lastview.before(validFrom)
                || lastview.before(sm.getTsupdated())) {
              // not seen any message
              // or last seen before validfrom date
              // or last view before message last updated
View Full Code Here

   *
   * @param userId
   *            of the user to populate
   */
  public void repopulateUser(String userId) {
    User user = this.getUser(userId);
    if (null != user) {
      UserBean updatedUser = null;
      try {
        updatedUser = (UserBean) UserFinderBase
            .findByPrimaryKey(new UserKey(user.getId()));
        ClassPopulater.populateFromObjectIgnoreNull(user, updatedUser);
        user.removeAllAttributes();
        Map<String, String> attr = updatedUser.getAttributes();
        Set<String> set = attr.keySet();
        for (String elem : set) {
          user.setAttribute(elem, updatedUser.getAttribute(elem));
        }
      } catch (SQLException sqle) {
        logger.log(Level.ERROR, "unable to repopulateUser", sqle);
      }
      updatedUser = null;
View Full Code Here

        answer.getFetch().removeValue("PASSWORD");
        // log to accessLog
        this.logToAccessLog(req, answer, "loginUser");
        return answer;
      }
      User userDB = findUser(userId);

      // change password is only done for users that arent logged in
      if (currentUsers.get(userId) != null) {
        answer.setRelogin(true);
        answer.setStatus("no relogins allowed");
        // there is never any reason to return a password to the client
        answer.getFetch().removeValue("PASSWORD");
        // log to accessLog
        this.logToAccessLog(req, answer, "changePassword");
        return answer;
      }

      answer.setRelogin(false);

      // if more than our loginwaittimeout we reset logintimedoubler
      GregorianCalendar calendar = new GregorianCalendar();
      calendar.add(Calendar.MINUTE, -loginWaitTimeOut);

      if (currentFailedUsers.containsKey(userId)
          && calendar.after(currentFailedUsers.get(userId)
              .getCalendar())) {
        currentFailedUsers.remove(userId);
        if (logger.isDebugEnabled()) {
          logger.log(Level.DEBUG, "changePassword:  reset user");
        }
      }
      // if to many tries no entry
      if (currentFailedUsers.containsKey(userId)
          && currentFailedUsers.get(userId).getNoOfWrongTries() > 10) {
        answer.setStatus(LoginAnswer.FAILED);
        answer.setInfo("To many tries");
        answer.getFetch().removeValue("PASSWORD");
        // log to accessLog
        this.logToAccessLog(req, answer, "changePassword");
        return answer;
      }

      // wrong password
      if (!passy.compareHashes(passWord, userDB.getPassword())) {
        // double wait time on wrong password....
        doubleLoginWait(userId);

        // create answer
        answer.setLoginWait(currentFailedUsers.get(userId).getWait()
            .intValue());
        answer.setStatus(LoginAnswer.FAILED);
        answer.setInfo("no match for username password in db");
        answer.getFetch().removeValue("PASSWORD");
        // log to accessLog
        this.logToAccessLog(req, answer, "changePassword");
        return answer;
      }

      try {
        // if password matches.. and not equal to old
        if (userDB.getPassword() != null
            && !newPassWord.equals(passWord)) {

          // !!!!!!!!!!!!!!!!!creating new
          // user!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
          if (logger.isDebugEnabled()) {
            logger.log(Level.DEBUG,
                "changePassword() creating new user: " + userId);
          }
          this.getWriteLockUserTable();
          try {
            // populate the user
            currentUsers.put(userId, findUser(userId));
            User user = currentUsers.get(userId);
            user.setTslastlogin(new Timestamp(System
                .currentTimeMillis()));
            user.setPassword(passy.generateHash(newPassWord));
            user.setChangepassword(new Integer(0));
            user.setTspassword(new Timestamp(System
                .currentTimeMillis()));
            ((UserBean) user).store();

            user.setLastActivityTimeStamp();
            user.setSessionId(req.getSession().getId());

            // set default sortlists from the dispatchers lists
            setStandardSortOrder(user);

            // we set users donelogin to true as we have done a
            // login or relogin
            user.setFromPage("login.jsp");
            // new user should be sent to start...
            answer.setReturnToPage("start.jsp");
            user.setDoneLogin(true);
            // removes user from currentFailedUsers on
            // successfull
            // login
            if (currentFailedUsers.containsKey(userId)) {
              currentFailedUsers.remove(userId);
View Full Code Here

        disp.logToAccessLog(answer, "loginUser");
        return answer;

      }

      User userDB = disp.findUser(userId);

      // if user exists it is a relogin....
      if (disp.currentUsers.get(userId) == null) {
        answer.setRelogin(false);
      } else {
        answer.setRelogin(true);
      }
      // if more than our loginwaittimeout we reset logintimedoubler
      // TODO: simplify this as getting x tries (10) then be locked out
      // for x(10) min, skipp doubling
      // TODO: perhaps have a small random time before answering
      // TODO: make sure this is per USERNAME and nothing else.
      GregorianCalendar calendar = new GregorianCalendar();
      calendar.add(Calendar.MINUTE, -disp.loginWaitTimeOut);
      if (disp.currentFailedUsers.containsKey(userId)) {
        if (Dispatcher.logger.isDebugEnabled()) {
          Dispatcher.logger.log(
              Level.DEBUG,
              "calendar: "
                  + new SimpleDateFormat(
                      "yyyy-MM-dd HH:mm:ss")
                      .format(calendar.getTime()));
          Dispatcher.logger
              .log(Level.DEBUG,
                  "usercalendar: "
                      + new SimpleDateFormat(
                          "yyyy-MM-dd HH:mm:ss")
                          .format(((Calendar) disp.currentFailedUsers
                              .get(userId)
                              .getCalendar())
                              .getTime()));
          Dispatcher.logger.log(
              Level.DEBUG,
              "after: "
                  + calendar.after(disp.currentFailedUsers
                      .get(userId).getCalendar()));
        }
      }
      if (disp.currentFailedUsers.containsKey(userId)
          && calendar.after(disp.currentFailedUsers.get(userId)
              .getCalendar())) {
        disp.currentFailedUsers.remove(userId);
        // currentFailedUsers.put(userId,new LoginWait());
        if (Dispatcher.logger.isDebugEnabled()) {
          Dispatcher.logger.log(Level.DEBUG,
              "loginUser():  reset user ");
        }

      }

      // if to many tries no entry
      if (disp.currentFailedUsers.containsKey(userId)
          && disp.currentFailedUsers.get(userId).getNoOfWrongTries() > 10) {
        answer.setStatus(LoginAnswer.FAILED);
        answer.setInfo("To many tries");
        // log to accessLog
        disp.logToAccessLog(answer, "loginUser");
        return answer;
      }

      // wrong password
      if (null == userDB
          || !disp.passy
              .compareHashes(passWord, userDB.getPassword())) {
        // double wait time on wrong password.... holds thread for wait
        // time
        // TODO: see todos above, only count no of tries..
        disp.doubleLoginWait(userId);

        // create answer
        answer.setLoginWait(disp.currentFailedUsers.get(userId)
            .getWait().intValue());
        answer.setStatus(LoginAnswer.FAILED);
        answer.setInfo("no match for username password in db");
        // log to accessLog
        disp.logToAccessLog(answer, "loginUser");
        return answer;
      }

      // no user with our userid in the internal user holder currentUsers
      if (disp.currentUsers.get(userId) == null) {
        // if we need to change password expired or forced
        if ((userDB.getTspassword() != null && ((new Date().getTime() / 1000) - (userDB
            .getTspassword().getTime() / 1000)) > disp
            .getPasswordLifeLength() * 60 * 60 * 24)
            || new Integer(1).equals(userDB.getChangepassword())) {
          // create answer
          answer.setStatus("changepassword");
          answer.setInfo("user needs to change password");
          // log to accessLog
          disp.logToAccessLog(answer, "loginUser");
          return answer;
        }
        // !!!!!!!!!!!!!!!!!creating new
        // user!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        if (Dispatcher.logger.isDebugEnabled()) {
          Dispatcher.logger.log(Level.DEBUG,
              "loginUser(): creating new user: " + userId);
        }

        disp.getWriteLockUserTable();
        disp.currentUsers.put(userId, disp.findUser(userId));

        try {
          // populate the user
          User user = disp.currentUsers.get(userId);

          // Is the User on an active centre?
          if (!new Integer(1).equals(disp.getCentre(
              user.getCentreid()).getStatus())) {
            // Users centre is inactive, try to find an active one
            Map<String, UsercentrerelBean> ucrMap = null;
            ucrMap = UsercentrerelFinder.findByUseridReturnMap(user
                .getId());
            Iterator<String> it = ucrMap.keySet().iterator();
            UsercentrerelBean ucrBean = null;
            String tempCentreid = null;
            while (it.hasNext()) { // Loop users all centres
              tempCentreid = it.next();
              ucrBean = ucrMap.get(tempCentreid);
              if (new Integer(1).equals(ucrBean.getStatus())) {
                Dispatcher.logger.log(
                    Level.INFO,
                    "loginUser(): users centre inactive: "
                        + user.getCentreid()
                        + ", moved to: "
                        + ucrBean.getCentreid()
                        + ", userid: " + userId);
                // Active centre found, set info to user
                user.setCentreid(ucrBean.getCentreid());
                user.setGroupid(ucrBean.getGroupid());
                break;
              }
            }
          }
          user.setPrevTslastlogin(user.getTslastlogin());
          user.setTslastlogin(new Timestamp(System
              .currentTimeMillis()));
          ((UserBean) user).store();
          user.setLastActivityTimeStamp();

          // Set user's default sortlist from dispatcher's
          // list
          disp.setStandardSortOrder(user);

          // we set users donelogin to true as we have done a
          // login or relogin
          user.setFromPage("login.jsp");
          // new user should be sent to start, or something...
          answer.setReturnToPage(disp.getUserReturnToPage(user));

          // create answer
          // answer.setUserId(userId);
          answer.setStatus("loggedin");
          answer.setInfo("new user created");

        } finally {
          disp.releaseWriteLockUserTable();
        }
        if (Dispatcher.logger.isDebugEnabled()) {
          Dispatcher.logger.log(Level.DEBUG,
              "loginUser() new user complete: " + userId);
        }

      } else {
        // user exists in currentUsers
        User u = disp.currentUsers.get(userId);
        // update timestamp in user...
        u.setLastActivityTimeStamp();

        // we set users frompage to login.jsp as we have done a
        // login or
        // relogin saving frompage in answer
        answer.setReturnToPage(u.getFromPage());

        // creating answer
        answer.setStatus("loggedin");
        answer.setInfo("old user checked password successfully");
        answer.setFetch(u.getFetch());
      }
      // removes user from currentFailedUsers on successfull login
      if (disp.currentFailedUsers.containsKey(userId)) {
        disp.currentFailedUsers.remove(userId);
      }
View Full Code Here

      rw.setLinks(getLinks(""));
      return Response.status(Response.Status.FORBIDDEN).entity(rw)
          .build();
    }

    User user = Dispatcher.getInstance().getUser(userId);

    rw.setSuccess(true);
    rw.setLinks(getLinks(userId));

    // **************** end break out? ******************
 
View Full Code Here

      rw.setLinks(getLinks(""));
      return Response.status(Response.Status.FORBIDDEN).entity(rw)
          .build();
    }

    User user = Dispatcher.getInstance().getUser(userId);

    rw.setSuccess(true);
    rw.setLinks(getLinks(userId));

    // **************** end break out? ******************
 
View Full Code Here

   */
  public String getListOfUsers() {
    this.getReadLockUserTable();
    try {
      String users = new String();
      User u = null;
      for (Iterator<User> e = currentUsers.values().iterator(); e
          .hasNext();) {
        u = e.next();
        users = users + "<span onClick=\"sendUser('" + u.getId()
            + "')\">" + u.getId() + ", </span> ";
      }
      return users;
    } finally {
      this.releaseReadLockUserTable();
    }
View Full Code Here

TOP

Related Classes of org.openqreg.bean.User

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.