Exemplo n.º 1
0
 /**
  * insert a user in the list
  *
  * @param u
  * @throws AlreadyRegisteredUserException
  */
 public void insert(User u) throws AlreadyRegisteredUserException {
   String log = u.getLogin();
   if (!tabUser.containsKey(log)) tabUser.put(u.getLogin(), u);
   else {
     throw new AlreadyRegisteredUserException(u);
   }
 }
Exemplo n.º 2
0
  /* get/create device list entry */
  public static GroupList getGroupList(User user, String groupID, boolean createOK)
      throws DBException {
    // does not return null, if 'createOK' is true

    /* User specified? */
    if (user == null) {
      throw new DBException("User not specified.");
    }
    String accountID = user.getAccountID();
    String userID = user.getUserID();

    /* group exists? */
    if (StringTools.isBlank(groupID)) {
      throw new DBException("DeviceGroup ID not specified.");
    } else if (!DeviceGroup.exists(accountID, groupID)) {
      throw new DBException("DeviceGroup does not exist: " + accountID + "/" + groupID);
    }

    /* create/save record */
    GroupList.Key grpListKey = new GroupList.Key(accountID, userID, groupID);
    if (grpListKey.exists()) { // may throw DBException
      // already exists
      GroupList listItem = grpListKey.getDBRecord(true);
      listItem.setUser(user);
      return listItem;
    } else if (createOK) {
      GroupList listItem = grpListKey.getDBRecord();
      listItem.setCreationDefaultValues();
      listItem.setUser(user);
      return listItem;
    } else {
      // record doesn't exist, and caller doesn't want us to create it
      return null;
    }
  }
Exemplo n.º 3
0
  private Tweet getTweetObjectFromStatus(Status status) {

    Tweet tweet = new Tweet();
    tweet.setId(Long.toString(status.getId()));
    tweet.setText(status.getText());
    tweet.setCreatedAt(status.getCreatedAt());

    tweet.setFavCount(status.getFavoriteCount());

    User user = status.getUser();

    tweet.setUserId(user.getId());
    tweet.setUserName(user.getName());
    tweet.setUserScreenName(user.getScreenName());

    HashtagEntity[] hashtagEntities = status.getHashtagEntities();
    List<String> hashtags = new ArrayList<String>();

    for (HashtagEntity hashtagEntity : hashtagEntities) {
      hashtags.add(hashtagEntity.getText());
    }

    tweet.setHashTags(hashtags.toArray(new String[hashtags.size()]));

    GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
      double[] coordinates = {geoLocation.getLongitude(), geoLocation.getLatitude()};
      tweet.setCoordinates(coordinates);
    }

    return tweet;
  }
Exemplo n.º 4
0
 /**
  * return the list of all drone which may be controled by the user
  *
  * @param log
  * @return
  */
 public Iterator<String> getItrUsr(String log) {
   Iterator<String> res = null;
   User usr = tabUser.get(log);
   if (usr != null) {
     res = usr.getSetItr();
   }
   return res;
 }
Exemplo n.º 5
0
 /**
  * Check if the login is correct
  *
  * @param log
  * @param pwd
  * @return
  */
 public boolean checkUser(String log, String pwd) {
   boolean res = false;
   User usr = tabUser.get(log);
   if (usr != null) {
     res = usr.IsPwdTrue(pwd);
   }
   return res;
 }
Exemplo n.º 6
0
  private boolean sendNotification(
      HttpServletRequest request,
      HttpServletResponse response,
      Repository db,
      String login,
      String commit,
      String url,
      String authorName,
      String message)
      throws ServletException, URISyntaxException, IOException, JSONException, CoreException,
          Exception {
    UserEmailUtil util = UserEmailUtil.getUtil();
    if (!util.isEmailConfigured()) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "Smpt server not configured",
              null));
    }
    IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore();
    User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login);
    try {
      if (reviewRequestEmail == null) {
        reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE);
      }

      String emailAdress = user.getEmail();

      util.sendEmail(
          reviewRequestEmail.getTitle(),
          reviewRequestEmail
              .getContent()
              .replaceAll(EMAIL_COMMITER_NAME, authorName)
              .replaceAll(EMAIL_URL_LINK, url)
              .replaceAll(EMAIL_COMMIT_MESSAGE, message),
          emailAdress);

      JSONObject result = new JSONObject();
      result.put(GitConstants.KEY_RESULT, "Email sent");
      OrionServlet.writeJSONResponse(
          request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "User doesn't exist",
              null));
    }
  };
Exemplo n.º 7
0
 @Override
 public User updateUser(
     long userId, String username, String password, String firstName, String lastName) {
   User user = userRepository.findOne(userId);
   user.setUsername(username);
   user.setFirstName(firstName);
   user.setLastName(lastName);
   user.setPassword(password);
   return this.userRepository.save(user);
 }
Exemplo n.º 8
0
 @Override
 public Customer removeCustomer(long userId, long customerId) {
   User user = userRepository.findOne(userId);
   Customer customer = customerRepository.findOne(customerId);
   user.getCustomers().remove(customer);
   this.userRepository.save(user);
   customer.setUser(null);
   this.customerRepository.delete(customer);
   return customer;
 }
Exemplo n.º 9
0
 @RequestMapping(value = "/{id:.+}", method = RequestMethod.PUT)
 @ApiOperation(value = "Updates the User instance associated with the given id.")
 public User editUser(@PathVariable("id") Integer id, @RequestBody User instance)
     throws EntityNotFoundException {
   LOGGER.debug("Editing User with id: {}", instance.getUserid());
   instance.setUserid(id);
   instance = userService.update(instance);
   LOGGER.debug("User details with id: {}", instance);
   return instance;
 }
Exemplo n.º 10
0
 /**
  * Gets the list of the vnmrj users(operators) for the current unix user logged in
  *
  * @return the list of vnmrj users
  */
 protected Object[] getOperators() {
   String strUser = System.getProperty("user.name");
   User user = LoginService.getDefault().getUser(strUser);
   ArrayList<String> aListOperators = user.getOperators();
   if (aListOperators == null || aListOperators.isEmpty())
     aListOperators = new ArrayList<String>();
   Collections.sort(aListOperators);
   if (aListOperators.contains(strUser)) aListOperators.remove(strUser);
   aListOperators.add(0, strUser);
   return (aListOperators.toArray());
 }
Exemplo n.º 11
0
  private void handleSignupPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {
    String userId = request.getParameter(PARAM_USER_ID);
    String userName = request.getParameter(PARAM_USER_NAME);
    String email = request.getParameter(PARAM_EMAIL);
    String stringPassword = request.getParameter(PARAM_PASSWORD);
    String stringPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM);

    if (!stringPassword.equals(stringPasswordConfirm)) {
      WebUtils.redirectToError(
          "Mismatch between password and password confirmation", request, httpServletResponse);
      return;
    }

    SecureRandom secureRandom = new SecureRandom();
    String salt = "" + secureRandom.nextLong();
    byte[] password = User.computeHashedPassword(stringPassword, salt);
    User user = userDb.get(userId);
    if (user != null) {
      WebUtils.redirectToError(
          "There already exists a user with the ID " + userId, request, httpServletResponse);
      return;
    }

    user =
        new User(
            userId,
            userName,
            password,
            salt,
            email,
            new ArrayList<String>(),
            Config.getConfig().activateAccountsAtCreation,
            false);
    // ttt2 add confirmation by email, captcha, ...
    List<String> fieldErrors = user.checkFields();
    if (!fieldErrors.isEmpty()) {
      StringBuilder bld =
          new StringBuilder("Invalid values when trying to create user with ID ")
              .append(userId)
              .append("<br/>");
      for (String s : fieldErrors) {
        bld.append(s).append("<br/>");
      }
      WebUtils.redirectToError(bld.toString(), request, httpServletResponse);
      return;
    }

    // ttt2 2 clients can add the same userId simultaneously
    userDb.add(user);

    httpServletResponse.sendRedirect("/");
  }
  public User getUser(String name) {
    User user = null;

    for (User entry : getUsers()) {
      if (entry != null && entry.getName().equals(name)) {
        user = entry;
        break;
      }
    }

    return user;
  }
Exemplo n.º 13
0
 void placeOrder(final User user, String cmd, Company comp, int qty, int id) {
   int cmdID = commID++;
   connect(user.getName(), user.getPassword());
   try {
     out.println(cmdID + ";" + cmd + ":" + comp.name + ":" + Integer.toString(qty) + ":" + id);
     out.flush();
     Shares pen = (Shares) receiveReply(cmdID);
     user.getPendingShares().add(pen);
     user.dataChanged();
   } catch (Exception r) {
     r.printStackTrace();
   }
 }
Exemplo n.º 14
0
 /**
  * Converts the contents of the GroupInvite to a {@link java.lang.String} in order to save it to
  * file. The toString method will save the invite as follows: Sender: senderID Receiver:
  * receiverID Text: text ID : groupID
  */
 public String toString() {
   return ("Type:"
       + type
       + "\nSender:"
       + sender.getID()
       + "\nReceiver:"
       + receiver.getID()
       + "\nGroup:"
       + group.getID()
       + "\nText:"
       + text
       + "\n"); // Just for compile
 }
  public boolean setUserConfig(String name, String[] config) {
    User user = getUser(name);

    for (int i = 0; i < 3; i++) {
      try {
        if (!config[i].isEmpty()) {
          System.out.println("Changing config " + i);
          user.setConfig(i, config[i]);
        }
      } catch (Exception e) {
      }
    }
    return true;
  }
Exemplo n.º 16
0
 public void testReservedTableOrderBy() throws Exception {
   // Drop the table
   removeAll(User.class);
   // Create
   User user = new User();
   user.setName("demon");
   getStore().save(user);
   User aUser = new User();
   aUser.setName("root");
   getStore().save(aUser);
   // Do query
   List result = getStore().find("find user order by user.name");
   Assert.assertEquals(result.size(), 2);
 }
Exemplo n.º 17
0
  private void handleChangePasswordPost(Request request, HttpServletResponse httpServletResponse)
      throws Exception {

    LoginInfo loginInfo = userHelpers.getLoginInfo(request);
    if (loginInfo == null) {
      WebUtils.redirectToError("Couldn't determine the current user", request, httpServletResponse);
      return;
    }

    String userId = loginInfo.userId;
    String stringCrtPassword = request.getParameter(PARAM_CURRENT_PASSWORD);
    String stringNewPassword = request.getParameter(PARAM_PASSWORD);
    String stringNewPasswordConfirm = request.getParameter(PARAM_PASSWORD_CONFIRM);

    if (!stringNewPassword.equals(stringNewPasswordConfirm)) {
      showResult(
          "Mismatch between password and password confirmation",
          PATH_SETTINGS,
          request,
          httpServletResponse);
      return;
    }

    User user =
        userDb.get(
            userId); // ttt1 crashes for wrong ID; 2013.07.20 - no longer have an idea what this is
                     // about
    if (user == null) {
      WebUtils.redirectToError("Couldn't find the current user", request, httpServletResponse);
      return;
    }

    if (!user.checkPassword(stringCrtPassword)) {
      showResult("Incorrect current password", PATH_SETTINGS, request, httpServletResponse);
      return;
    }

    SecureRandom secureRandom = new SecureRandom();
    String salt = "" + secureRandom.nextLong();
    byte[] password = User.computeHashedPassword(stringNewPassword, salt);
    user.salt = salt;
    user.password = password;

    // ttt3 2 clients can change the password simultaneously
    userDb.add(user);

    // httpServletResponse.sendRedirect(PATH_SETTINGS);
    showResult("Password changed", PATH_SETTINGS, request, httpServletResponse);
  }
Exemplo n.º 18
0
 @Override
 public ProfilePhoto readUserProfilePhoto(long userId) {
   InputStream fileInputSteam = null;
   try {
     User user = findById(userId);
     fileInputSteam = new FileInputStream(fileForPhoto(userId));
     byte[] data = IOUtils.toByteArray(fileInputSteam);
     return new ProfilePhoto(
         userId, data, MediaType.parseMediaType(user.getProfilePhotoMediaType()));
   } catch (Exception e) {
     throw new UserProfilePhotoReadException(userId, e);
   } finally {
     IOUtils.closeQuietly(fileInputSteam);
   }
 }
  public void getTestCase() throws Exception {

    TestCase testCaseObj = tmsManager.getTestCase("15");

    System.out.println(testCaseObj.getTestCaseId());
    System.out.println(testCaseObj.getTestCaseDescription());
    System.out.println(testCaseObj.getTestCasePhase());
    Project projectObj = testCaseObj.getProjectObj();
    System.out.println(projectObj.getProjectId());
    User userObj = testCaseObj.getUserObj();
    System.out.println(userObj.getUserId());
    Activity activityObj = testCaseObj.getActivityObj();
    System.out.println(activityObj.getActivityId());
    System.out.println(testCaseObj.getExpectedBehaviour());
  }
Exemplo n.º 20
0
  public static User loadUserDatabase(String location) {
    try {
      FileInputStream fi = new FileInputStream(location + "/users.odb");
      ObjectInputStream ois = new ObjectInputStream(fi);
      User loaduser = (User) ois.readObject();
      ois.close();
      fi.close();
      return loaduser;
    } catch (Exception ex) {

      User tempuser = new User();
      tempuser.addUser("admin", "admin", UserType.gebruiker);
      return tempuser;
    }
  }
  public void getTestCaseExecutionDetails() throws Exception {
    //                testCaseObj.setTestCaseId("001");
    TestCase testCaseObj = tmsManager.getTestCaseExecutionDetails("001");

    Activity activityObj = testCaseObj.getActivityObj();
    System.out.println(activityObj.getActivityId());
    System.out.println(testCaseObj.getTestCaseId());
    User userObj = testCaseObj.getUserObj();
    System.out.println(userObj.getUserId());
    System.out.println(testCaseObj.getActualDate());

    System.out.println(testCaseObj.getTestCaseStatus());
    System.out.println(testCaseObj.getComments());
    System.out.println(testCaseObj.getActualBehaviour());
  }
  public boolean deleteUser(String name) {
    boolean success = true;

    Iterator users = this.user_list.iterator();
    while (users.hasNext()) {
      User entry = (User) users.next();
      if (entry.getName().equals(name)) {
        success = this.user_list.remove(entry);
        removeUserLocation(name); // remove user entry
        break;
      }
    }

    return success;
  }
Exemplo n.º 23
0
 public boolean isVoice(String sender, String channel) {
   User users[] = getUsers(channel);
   User u = null;
   for (User usa : users) {
     if (sender.equals(usa.getNick())) {
       u = usa;
       break;
     }
   }
   if (u.hasVoice()) {
     return true;
   } else {
     return false;
   }
 }
Exemplo n.º 24
0
  private void drawBalance(Graphics g)
        //  POST: Draws the balance of the current player
      {

    Font font; // Font used to draw balance
    String message; // Message for balance
    Color oldColor; // Sets for color
    int x1; // Upper-left x coordinate
    int y1; // Upper-left y coordinate
    int x2; // Bottom-right x coordinate
    int y2; // Bottom-right y coordinate
    int width; // Width of the dialogue box
    int height; // Height of the dialogue box
    int offset; // Offset so the dialogue box is positioned
    int balance; // Offset so the dialogue box is positioned
    User player; // User value for the player

    player = usersArray[0];

    balance = player.getBalance();
    oldColor = g.getColor();

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.81);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.86);
    width = x2 - x1;
    height = y2 - y1;
    message = "Balance:";
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.setColor(Color.WHITE);
    g.drawString(message, x1 + offset, y2);

    x1 = ScaledPoint.scalerToX(0.72);
    y1 = ScaledPoint.scalerToY(0.865);
    x2 = ScaledPoint.scalerToX(0.88);
    y2 = ScaledPoint.scalerToY(0.915);

    width = x2 - x1;
    height = y2 - y1;
    message = "$" + Integer.toString(balance);
    font = Drawing.getFont(message, width, height, FONTNAME, FONTSTYLE);
    offset = (width - getFontMetrics(font).stringWidth(message)) / 2;
    g.drawString(message, x1 + offset, y2);

    g.setColor(oldColor);
  }
Exemplo n.º 25
0
  private Point createFeedPoint(final User user) throws NimbitsException {

    final EntityName name =
        CommonFactoryLocator.getInstance().createName(Const.TEXT_DATA_FEED, EntityType.point);

    final Entity entity =
        EntityModelFactory.createEntity(
            name,
            "",
            EntityType.feed,
            ProtectionLevel.onlyConnection,
            user.getKey(),
            user.getKey(),
            UUID.randomUUID().toString());
    // final Entity r = EntityServiceFactory.getInstance().addUpdateEntity(user, entity);

    Point point = PointModelFactory.createPointModel(entity);

    final Point result = (Point) EntityServiceFactory.getInstance().addUpdateEntity(point);

    postToFeed(
        user,
        "A new data point has been created for your data feed. Your data feed is just "
            + "a data point. Points are capable of storing numbers, text, json and xml data. Nimbits uses "
            + "a single data point to drive this feed.",
        FeedType.info);
    return result;
  }
  public void getTestActivityEffort(String activityId) throws Exception {
    Effort effortObj = tmsManager.getTestActivityEffort(activityId);

    Activity activityObj = effortObj.getActivityObj();

    System.out.println(activityObj.getActivityId());
    User userObj = effortObj.getUserObj();

    System.out.println(userObj.getEmpNo());
    System.out.println(effortObj.getEffortDate());
    System.out.println(effortObj.getStartDate());
    System.out.println(effortObj.getEndDate());
    System.out.println(effortObj.getEffort());
    System.out.println(effortObj.getEffortDescription());
    System.out.println(effortObj.getEffortTimeStamp());
  }
  private void read() {
    try {
      line = is.readLine();
      while (line.compareTo("QUIT") != 0) {
        // System.out.println("Response from Client  :  " + line);
        if (line.toLowerCase().contains("@101|")) {
          send("Got username");
          String name =
              line.substring(line.indexOf('|', 0) + 1, line.indexOf('|', line.indexOf('|', 0) + 1));
          user.setName(name);
          System.out.println("Got username = "******"IO Error/ Client " + line + " terminated abruptly");
    } catch (NullPointerException e) {
      line = this.getName(); // reused String line for getting thread name
      System.out.println("Client " + line + " Closed");
    }
  }
Exemplo n.º 28
0
 private void changePassword() throws Exception {
   String name = (String) list_read.get(1);
   String pass1 = (String) list_read.get(2);
   String pass2 = (String) list_read.get(3);
   User.changePassword(name, pass1, pass2);
   reInput();
 }
Exemplo n.º 29
0
 GroupInvite(User sender, User receiver, Group group) {
   this.sender = sender;
   this.receiver = receiver;
   this.group = group;
   this.text =
       "<a href = profile.jsp?ID="
           + sender.getID()
           + ">"
           + sender.getDisplayName()
           + "</a>"
           + " has invited you to join "
           + "<a href profile.jsp?ID="
           + group.getID()
           + ">"
           + group.getDisplayName()
           + "</a>";
   type = "GroupInvite";
 }
Exemplo n.º 30
0
  public static void checkUsername(String username) {
    Boolean result = true;
    User user = User.find("username=?", username).first();
    if (user != null) {
      result = false;
    }

    renderJSON(result);
  }