Package org.hive2hive.core.model

Examples of org.hive2hive.core.model.UserProfile


  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    logger.debug("Starting to encrypt and put the user profile for user '{}'.", credentials.getUserId());

    // consume the profile from the context
    UserProfile userProfile = context.consumeUserProfile();

    // encrypt user profile
    SecretKey encryptionKey = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
        credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);

    EncryptedNetworkContent encryptedProfile = null;
    try {
      encryptedProfile = H2HEncryptionUtil.encryptAES(userProfile, encryptionKey);
    } catch (DataLengthException | IllegalStateException | InvalidCipherTextException | IOException e) {
      throw new ProcessExecutionException("User profile could not be encrypted.");
    }

    try {
      encryptedProfile.generateVersionKey();
    } catch (IOException e) {
      throw new ProcessExecutionException("User profile version key could not be generated.", e);
    }

    // assign ttl value
    encryptedProfile.setTimeToLive(userProfile.getTimeToLive());
   
    // put encrypted user profile
    try {
      put(credentials.getProfileLocationKey(), H2HConstants.USER_PROFILE, encryptedProfile,
          userProfile.getProtectionKeys());
      logger.debug("User profile successfully put for user {}.", credentials.getUserId());
    } catch (PutFailedException e) {
      throw new ProcessExecutionException(e);
    }
  }
View Full Code Here


    this.context = context;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    UserProfile profile = new UserProfile(userId);
    context.provideUserProfile(profile);
  }
View Full Code Here

  private void processSharedWithOther() throws Hive2HiveException {
    /** Add the new user to the permission list of the folder index */
    UserProfileManager profileManager = networkManager.getSession().getProfileManager();
    String pid = UUID.randomUUID().toString();
    UserProfile userProfile = profileManager.getUserProfile(pid, true);
    FolderIndex index = (FolderIndex) userProfile.getFileById(sharedIndex.getFilePublicKey());
    if (index == null) {
      throw new Hive2HiveException("I'm not the newly shared user but don't have the shared folder");
    }

    index.addUserPermissions(addedFriend);
View Full Code Here

  private void processSharedWithMe() throws Hive2HiveException {
    /** 1. add the tree to the root node in the user profile */
    UserProfileManager profileManager = networkManager.getSession().getProfileManager();
    String pid = UUID.randomUUID().toString();
    UserProfile userProfile = profileManager.getUserProfile(pid, true);

    // add it to the root (by definition)
    userProfile.getRoot().addChild(sharedIndex);
    sharedIndex.setParent(userProfile.getRoot());
    profileManager.readyToPut(userProfile, pid);
    logger.debug("Added the newly shared folder to the own user profile.");

    /** 2. Notify others that files are available */
    notifyOtherClients(new UploadNotificationMessageFactory(sharedIndex, null));
View Full Code Here

  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    // get user profile
    UserProfile profile = null;
    try {
      profile = profileManager.getUserProfile(getID(), true);
    } catch (GetFailedException e) {
      throw new ProcessExecutionException("Could not get user profile.", e);
    }

    index = profile.getFileByPath(file, root);

    // validate
    if (index == null) {
      throw new ProcessExecutionException("File index not found in user profile");
    } else if (!index.canWrite()) {
View Full Code Here

  @Override
  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    if (index != null && parentIndexKey != null) {

      // get user profile
      UserProfile profile = null;
      try {
        profile = profileManager.getUserProfile(getID(), true);
      } catch (GetFailedException e) {
        logger.warn("Rollback failed: {}.", e.getMessage());
        return;
      }

      // TODO this is buggy! rather use list to check for containment instead of above if-statement
      // re-add file to user profile
      FolderIndex parent = (FolderIndex) profile.getFileById(parentIndexKey);
      parent.addChild(index);
      index.setParent(parent);

      try {
        profileManager.readyToPut(profile, getID());
View Full Code Here

    try {
      H2HSession session = networkManager.getSession();
      String pid = UUID.randomUUID().toString();

      Path root = session.getRoot();
      UserProfile userProfile = session.getProfileManager().getUserProfile(pid, false);
      Index parentNode = userProfile.getFileById(parentFileKey);

      if (parentNode == null) {
        throw new FileNotFoundException("Got notified about a file we don't know the parent of.");
      } else {
        boolean deleted = new File(FileUtil.getPath(root, parentNode).toFile(), fileName).delete();
View Full Code Here

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    logger.debug("Updating user profile for sharing folder '{}'.", context.getFolder().getName());

    try {
      UserProfile userProfile = profileManager.getUserProfile(getID(), true);
      FolderIndex folderIndex = (FolderIndex) userProfile.getFileByPath(context.getFolder(), root);

      if (!folderIndex.canWrite()) {
        throw new ProcessExecutionException(String.format(
            "Cannot share folder '%s' with read-only access.", folderIndex.getName()));
      } else if (!folderIndex.getSharedFlag() && folderIndex.isSharedOrHasSharedChildren()) {
View Full Code Here

  @Override
  protected void doRollback(RollbackReason reason) throws InvalidProcessStateException {
    if (modified) {
      // return to original domain key and put the userProfile
      try {
        UserProfile userProfile = profileManager.getUserProfile(getID(), true);
        FolderIndex folderNode = (FolderIndex) userProfile.getFileById(context.consumeMetaFile()
            .getId());

        // unshare the fileNode
        folderNode.unshare();
View Full Code Here

    // 1. download the file with new name <filename>_<date>
    // 2. add the file with an AddFileProcess (which also notifies other clients)
    try {
      // find the node at the user profile
      UserProfileManager profileManager = networkManager.getSession().getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(getID(), false);
      Index selectedNode = userProfile.getFileById(metaFileSmall.getId());
      if (selectedNode == null) {
        throw new Hive2HiveException("File node not found");
      }

      // ask the user for the new file name
View Full Code Here

TOP

Related Classes of org.hive2hive.core.model.UserProfile

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.