Package org.hive2hive.core.security

Examples of org.hive2hive.core.security.UserCredentials


   * @throws NoPeerConnectionException
   */
  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());
      H2HSession session;
View Full Code Here


   *            list containing all nodes which need to have the same key pair
   * @throws NoPeerConnectionException
   */
  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());
      H2HSession session;
View Full Code Here

  public static String randomString() {
    return UUID.randomUUID().toString();
  }

  public static UserCredentials generateRandomCredentials() {
    return new UserCredentials(NetworkTestUtil.randomString(), NetworkTestUtil.randomString(),
        NetworkTestUtil.randomString());
  }
View Full Code Here

  @Test
  public void testFailOnExistingLocations() throws InvalidProcessStateException, NoPeerConnectionException {
    NetworkManager client = network.get(0);

    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();

    // already put a locations map
    FuturePut putLocations = client.getDataManager().putUnblocked(
        new Parameters().setLocationKey(credentials.getUserId())
            .setContentKey(H2HConstants.USER_LOCATIONS)
            .setData(new Locations(credentials.getUserId())));
    putLocations.awaitUninterruptibly();
    putLocations.getFutureRequests().awaitUninterruptibly();

    assertTrue(putLocations.isSuccess());
View Full Code Here

    // create 10 nodes and login 5 of them:
    // node 0-2: user A
    // node 3-4: user B
    // node 5: user C
    userACredentials = new UserCredentials("User A", NetworkTestUtil.randomString(),
        NetworkTestUtil.randomString());
    UseCaseTestUtil.register(userACredentials, network.get(0));

    userBCredentials = new UserCredentials("User B", NetworkTestUtil.randomString(),
        NetworkTestUtil.randomString());
    UseCaseTestUtil.register(userBCredentials, network.get(3));

    userCCredentials = new UserCredentials("User C", NetworkTestUtil.randomString(),
        NetworkTestUtil.randomString());
    UseCaseTestUtil.register(userCCredentials, network.get(5));

    // login all nodes
    UseCaseTestUtil.login(userACredentials, network.get(0), FileTestUtil.getTempDirectory());
View Full Code Here

      IOException, NoPeerConnectionException {
    NetworkManager putter = network.get(0); // where the process runs
    NetworkManager client = network.get(1); // where the user profile is stored

    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();

    UserProfile testProfile = new UserProfile(credentials.getUserId());
    IConsumeUserProfile context = new ConsumeProfileContext(testProfile);

    // initialize the process and the one and only step to test
    PutUserProfileStep step = new PutUserProfileStep(credentials, context, putter.getDataManager());
    UseCaseTestUtil.executeProcess(step);

    // get the user profile which should be stored at the proxy
    FutureGet global = client.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey()).setContentKey(
            H2HConstants.USER_PROFILE));
    global.awaitUninterruptibly();
    global.getFutureRequests().awaitUninterruptibly();
    EncryptedNetworkContent found = (EncryptedNetworkContent) global.getData().object();
    Assert.assertNotNull(found);

    // decrypt it using the same password as set above
    SecretKey decryptionKeys = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(),
        credentials.getPin(), H2HConstants.KEYLENGTH_USER_PROFILE);
    UserProfile decrypted = (UserProfile) H2HEncryptionUtil.decryptAES(found, decryptionKeys);

    // verify if both objects are the same
    Assert.assertEquals(credentials.getUserId(), decrypted.getUserId());
  }
View Full Code Here

    putter.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());
    NetworkManager proxy = network.get(1); // where the user profile is stored
    proxy.getConnection().getPeer().getPeerBean().storage(new DenyingPutTestStorage());

    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();
    UserProfile testProfile = new UserProfile(credentials.getUserId());
    IConsumeUserProfile context = new ConsumeProfileContext(testProfile);

    // initialize the process and the one and only step to test
    PutUserProfileStep step = new PutUserProfileStep(credentials, context, putter.getDataManager());
    TestProcessComponentListener listener = new TestProcessComponentListener();
    step.attachListener(listener);
    step.start();

    UseCaseTestUtil.waitTillFailed(listener, 20);

    // get the locations which should be stored at the proxy --> they should be null
    FutureGet futureGet = proxy.getDataManager().getUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey()).setContentKey(
            H2HConstants.USER_LOCATIONS));
    futureGet.awaitUninterruptibly();
    assertNull(futureGet.getData());
  }
View Full Code Here

      IllegalStateException, InvalidCipherTextException, ClassNotFoundException, IOException,
      NoPeerConnectionException, GetFailedException {
    NetworkManager putter = network.get(0); // where the process runs

    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();

    UserProfile testProfile = new UserProfile(credentials.getUserId());

    // add them already to the DHT
    SecretKey encryptionKeys = PasswordUtil.generateAESKeyFromPassword(credentials.getPassword(), credentials.getPin(),
        H2HConstants.KEYLENGTH_USER_PROFILE);
    EncryptedNetworkContent encrypted = H2HEncryptionUtil.encryptAES(testProfile, encryptionKeys);
    FuturePut putGlobal = putter.getDataManager().putUnblocked(
        new Parameters().setLocationKey(credentials.getProfileLocationKey())
            .setContentKey(H2HConstants.USER_PROFILE).setData(encrypted));
    putGlobal.awaitUninterruptibly();

    UserProfile profile = UseCaseTestUtil.getUserProfile(putter, credentials);

    // verify if both objects are the same
    Assert.assertEquals(credentials.getUserId(), profile.getUserId());
  }
View Full Code Here

  }

  @Test
  public void testStepSuccessWithNoUserProfile() throws NoPeerConnectionException {
    // create the needed objects
    UserCredentials credentials = NetworkTestUtil.generateRandomCredentials();
    try {
      UseCaseTestUtil.getUserProfile(network.get(0), credentials);
      Assert.fail("Should have triggered a GetFailedException");
    } catch (GetFailedException e) {
      // has to be triggered here
View Full Code Here

  }

  @Test(expected = NoSessionException.class)
  public void testInvalidPassword() throws NoSessionException, InvalidProcessStateException, NoPeerConnectionException,
      ProcessExecutionException {
    UserCredentials wrongCredentials = new UserCredentials(userCredentials.getUserId(), NetworkTestUtil.randomString(),
        userCredentials.getPin());

    loginAndWaitToFail(wrongCredentials);
  }
View Full Code Here

TOP

Related Classes of org.hive2hive.core.security.UserCredentials

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.