param username is the string object that contains the username of a given user

Param username is the string object that contains the

This preview shows page 4 - 5 out of 5 pages.

* @param username is the string object that contains the username of a given user * @return boolean value that specifies if the method was able to remove a user */ public boolean removeUser(String username) { if (currentUser == null || currentUser.getIsAdmin() == false) { return false; // Checks that the current user exists and is an admin } if (currentUser.getUsername().equals(username)) { System.out.println("You cannot remove the current user."); // User cannot remove themselves } for (int i = 0; i < users.size(); i++) { if (users.get(i).getUsername().equals(username)) { users.remove(i); return true; } } return false;
Image of page 4
} /** * Give a user admin access * @param username is the string object that contains the username of a given user * @return boolean value that specifies if the method was able to give a user admin access */ public boolean giveAdmin(String username) { if (currentUser == null || currentUser.getIsAdmin() == false) { return false; // Checks that the current user exists and is an admin } for (User user : users) { if (user.getUsername().equals(username)) { user.setIsAdmin(true); return true; } } return false; } /** * Remove a user's admin access * @param username is the string object that contains the username of a given user * @return boolean value that specifies if the method was able to take a user's admin access */ public boolean takeAdmin(String username) { if (currentUser == null || currentUser.getIsAdmin() == false) { return false; // Checks that the current user exists and is an admin } for (User user : users) { if (user.getUsername().equals(username)) { user.setIsAdmin(false); return true; } } return false; } /** * Resets a user's password * @param username is the string object that contains the username of a given user * @return boolean value that specifies if the method was able to reset a user's password */ public boolean resetPassword(String username) { if (currentUser == null || currentUser.getIsAdmin() == false) { return false; // Checks that the current user exists and is an admin } for (User user : users) { if (user.getUsername().equals(username)) { user.setPassword(DEFAULT_PASSWORD); return true; } } return false; } }
Image of page 5

You've reached the end of your free preview.

Want to read all 5 pages?

  • Fall '19
  • Login, partner, public class AccessControl

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture