コード例 #1
0
 @Override
 public void removeUsers(User user) {
   if (user.isRoot() || user.isGuest()) {
     throw new IllegalRemovalException("You can't remove " + user.getName());
   } else {
     super.removeUsers(user);
   }
 }
コード例 #2
0
 protected void removeUsers(String username) throws IllegalRemovalException, UserUnknownException {
   hasUser(username);
   if (username.equals(ROOT_USER)) throw new IllegalRemovalException(username);
   else {
     User toRemove = getUserByUsername(username);
     toRemove.remove();
     super.removeUsers(toRemove);
   }
 }
コード例 #3
0
 @Override
 public void addUsers(User user) throws UserAlreadyExistsException, PasswordIsTooWeakException {
   try {
     hasUser(user.getUsername());
   } catch (UserUnknownException e) {
     super.addUsers(user);
     return;
   }
   throw new UserAlreadyExistsException(user.getUsername());
 }
コード例 #4
0
  public FileSystem(MyDriveManager mdm) {
    super();
    setMyDriveManager(mdm);

    super.setIdSeed(0);

    Root root = new Root();
    this.addUsers(root);

    try {
      super.setFsRoot(
          new Directory(this.generateUniqueId(), PATH_DELIM, root.getUmask(), root, this));

    } catch (InvalidFileNameException | InvalidMaskException e) {
      /* This exception should not occur it only exists to protect the method against
       * bad programming
       */
      log.trace(e.getMessage());
      e.printStackTrace();
    }

    Directory home = new Directory(generateUniqueId(), HOME_DIR, root.getUmask(), root, getSlash());

    addToSlash(home);

    Directory rootHomeDirectory =
        new Directory(generateUniqueId(), root.getUsername(), root.getUmask(), root, home);
    home.addFile(rootHomeDirectory);
    root.setHomeDirectory((Directory) home.getFileByName(ROOT_USER));

    Guest guest = new Guest();
    Directory guestHomeDirectory =
        new Directory(generateUniqueId(), guest.getUsername(), guest.getUmask(), guest, home);
    home.addFile(guestHomeDirectory);
    guest.setHomeDirectory((Directory) home.getFileByName(GUEST_USER));
    addUsers(guest);
  }
コード例 #5
0
 public void addUsers(String username)
     throws UserAlreadyExistsException, InvalidUsernameException, PasswordIsTooWeakException {
   try {
     hasUser(username);
   } catch (UserUnknownException e) {
     User toCreate = new User(username, this);
     Directory homeDirectory =
         new Directory(
             this.generateUniqueId(), username, toCreate.getUmask(), toCreate, getHomeDirectory());
     this.addDirectoryToHome(homeDirectory);
     toCreate.setHomeDirectory(homeDirectory);
     super.addUsers(toCreate);
     return;
   }
   throw new UserAlreadyExistsException(username);
 }
コード例 #6
0
  private void xmlImportUser(List<Element> user)
      throws ImportDocumentException, PasswordIsTooWeakException {
    for (Element node : user) {
      String username = node.getAttributeValue("username");
      User toInsert;

      try {
        this.getUserByUsername(username);
      } catch (UserAlreadyExistsException e) {
        e.getMessage();
        throw new ImportDocumentException();
      } catch (UserUnknownException e) {
        toInsert = new User(username, this);

        if (node.getChild("password") != null)
          toInsert.setPassword(node.getChild("password").getValue());

        if (node.getChild("name") != null) toInsert.setName(node.getChild("name").getValue());

        if (node.getChild("mask") != null) toInsert.setUmask(node.getChild("mask").getValue());

        if (node.getChild("home") != null) {
          String[] tokens = node.getChild("home").getValue().split(PATH_DELIM);
          toInsert.setHomeDirectory(
              createDir(
                  createPath(node.getChild("home").getValue()),
                  tokens[tokens.length - 1],
                  toInsert));
        } else {
          Directory homeDirectory =
              new Directory(
                  this.generateUniqueId(),
                  username,
                  toInsert.getUmask(),
                  toInsert,
                  getHomeDirectory());
          toInsert.setHomeDirectory(homeDirectory);
          this.addDirectoryToHome(homeDirectory);
        }
        super.addUsers(toInsert);
      }
    }
  }
コード例 #7
0
 @Override
 public void setMyDriveManager(MyDriveManager mngr) {
   if (mngr == null) {
     super.setMyDriveManager(null);
   } else mngr.setFilesystem(this);
 }
コード例 #8
0
 private void addToSlash(File file) {
   super.getFsRoot().addFile(file);
 }
コード例 #9
0
 /* Uniques Ids */
 private int generateUniqueId() {
   Integer idSeed = super.getIdSeed();
   super.setIdSeed(++idSeed);
   return idSeed;
 }