Package org.hive2hive.core.network.data

Examples of org.hive2hive.core.network.data.UserProfileManager


  public static void login(UserCredentials credentials, NetworkManager networkManager, File root)
      throws NoPeerConnectionException {
    SessionParameters sessionParameters = new SessionParameters();
    sessionParameters.setFileConfig(new TestFileConfiguration());
    sessionParameters.setRoot(root.toPath());
    sessionParameters.setProfileManager(new UserProfileManager(networkManager.getDataManager(), credentials));
    IProcessComponent process = ProcessFactory.instance().createLoginProcess(credentials, sessionParameters,
        networkManager);
    executeProcess(process);
  }
View Full Code Here


    login(credentials, networkManager, root);
  }

  public static UserProfile getUserProfile(NetworkManager networkManager, UserCredentials credentials)
      throws GetFailedException, NoPeerConnectionException {
    UserProfileManager manager = new UserProfileManager(networkManager.getDataManager(), credentials);
    return manager.getUserProfile(UUID.randomUUID().toString(), false);
  }
View Full Code Here

  @Override
  public void start() {
    try {
      H2HSession session = networkManager.getSession();
      String randomPID = UUID.randomUUID().toString();
      UserProfileManager profileManager = session.getProfileManager();
      UserProfile userProfile = profileManager.getUserProfile(randomPID, true);

      // get and check the file nodes to be rearranged
      FolderIndex oldParent = (FolderIndex) userProfile.getFileById(oldParentKey);
      if (oldParent == null) {
        logger.error("Could not find the old parent.");
        return;
      } else if (!oldParent.canWrite(sender)) {
        logger.error("User was not allowed to change the source directory.");
        return;
      }

      Index child = oldParent.getChildByName(sourceFileName);
      if (child == null) {
        logger.error("File node that should be moved not found.");
        return;
      }

      FolderIndex newParent = (FolderIndex) userProfile.getFileById(newParentKey);
      if (newParent == null) {
        logger.error("Could not find the new parent.");
        return;
      } else if (!newParent.canWrite(sender)) {
        logger.error("User was not allowed to change the destination directory.");
        return;
      }

      // rearrange
      oldParent.removeChild(child);
      newParent.addChild(child);
      child.setParent(newParent);

      // change the child's name
      child.setName(destFileName);

      profileManager.readyToPut(userProfile, randomPID);

      // move the file on disk
      FileUtil.moveFile(session.getRoot(), sourceFileName, destFileName, oldParent, newParent);
    } catch (Hive2HiveException | IOException e) {
      logger.error("Could not process the user profile task.", e);
View Full Code Here

    }
  }

  private void getFileKeys() throws GetFailedException, InvalidProcessStateException, NoSessionException,
      IllegalStateException {
    UserProfileManager profileManager = networkManager.getSession().getProfileManager();
    UserProfile userProfile = profileManager.getUserProfile(getID(), false);

    // get the keys for the file to move
    Index fileNode = userProfile
        .getFileByPath(context.getSource(), networkManager.getSession().getRoot());
    if (fileNode == null) {
View Full Code Here

   */
  public static void createKeyPairs(List<NetworkManager> network) throws NoPeerConnectionException {
    for (NetworkManager node : network) {
      KeyPair keyPair = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
      UserCredentials userCredentials = generateRandomCredentials();
      UserProfileManager profileManager = new UserProfileManager(node.getDataManager(), userCredentials);
      PublicKeyManager keyManager = new PublicKeyManager(userCredentials.getUserId(), keyPair, node.getDataManager());
      IFileConfiguration config = FileConfiguration.createDefault();
      DownloadManager downloadManager = new DownloadManager(node.getDataManager(), node.getMessageManager(),
          keyManager, config);
      File root = new File(System.getProperty("java.io.tmpdir"), NetworkTestUtil.randomString());
View Full Code Here

   */
  public static void createSameKeyPair(List<NetworkManager> network) throws NoPeerConnectionException {
    KeyPair keyPair = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    UserCredentials userCredentials = generateRandomCredentials();
    for (NetworkManager node : network) {
      UserProfileManager profileManager = new UserProfileManager(node.getDataManager(), userCredentials);
      PublicKeyManager keyManager = new PublicKeyManager(userCredentials.getUserId(), keyPair, node.getDataManager());
      IFileConfiguration config = FileConfiguration.createDefault();
      DownloadManager downloadManager = new DownloadManager(node.getDataManager(), node.getMessageManager(),
          keyManager, config);
      File root = new File(System.getProperty("java.io.tmpdir"), NetworkTestUtil.randomString());
View Full Code Here

  public H2HSession loginAndWaitToFail(UserCredentials wrongCredentials) throws InvalidProcessStateException,
      NoSessionException, NoPeerConnectionException {
    NetworkManager client = network.get(new Random().nextInt(networkSize));
    SessionParameters sessionParameters = new SessionParameters();
    sessionParameters.setProfileManager(new UserProfileManager(client.getDataManager(), wrongCredentials));

    IProcessComponent loginProcess = ProcessFactory.instance().createLoginProcess(wrongCredentials, sessionParameters,
        client);
    TestProcessComponentListener listener = new TestProcessComponentListener();
    loginProcess.attachListener(listener);
View Full Code Here

    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();
View Full Code Here

    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();
View Full Code Here

    String userId = NetworkTestUtil.randomString();
    TestUserProfileTask userProfileTask = new TestUserProfileTask();
    KeyPair key = EncryptionUtil.generateRSAKeyPair(H2HConstants.KEYLENGTH_USER_KEYS);
    NetworkManager node = network.get(random.nextInt(networkSize));
    PublicKeyManager publicKeyManager = new PublicKeyManager(userId, key, node.getDataManager());
    node.setSession(new H2HSession(new UserProfileManager(node.getDataManager(), new UserCredentials(userId, "password",
        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();
View Full Code Here

TOP

Related Classes of org.hive2hive.core.network.data.UserProfileManager

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.