Package org.eclipse.orion.server.core.metastore

Examples of org.eclipse.orion.server.core.metastore.UserInfo


    } while ((System.currentTimeMillis() - start) < SLEEP_TIME);
  }

  private UserInfo getUserForCredentials(String login, String password) {
    try {
      UserInfo userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, login, false, false);
      if (userInfo != null && userInfo.getProperty(UserConstants2.PASSWORD) != null) {
        String userPassword = userInfo.getProperty(UserConstants2.PASSWORD);
        if (password.equals(userPassword)) {
          return userInfo;
        }
      }
    } catch (CoreException e) {
View Full Code Here


import org.junit.Test;

public class MetaStoreTest extends AbstractServerTest {
  private WorkspaceInfo createWorkspace() throws CoreException {
    IMetaStore store = getMetaStore();
    UserInfo user = new UserInfo();
    user.setUserName("MetaStoreTestUser");
    store.createUser(user);
    WorkspaceInfo workspace = new WorkspaceInfo();
    workspace.setFullName(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
    workspace.setUserId(user.getUniqueId());
    store.createWorkspace(workspace);
    return workspace;
  }
View Full Code Here

  }

  @Test
  public void testCreateUser() throws CoreException {
    IMetaStore store = getMetaStore();
    UserInfo user = new UserInfo();
    user.setUserName("testCreateUser");
    store.createUser(user);
    assertNotNull(user.getUniqueId());
  }
View Full Code Here

          Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
          IMetaStore metaStore = getMetaStore();
          String currentThreadName = Thread.currentThread().getName();
          for (int i = 0; i < PROPERTY_COUNT; i++) {
            // read the user
            UserInfo userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to add a property.");
              continue;
            }

            // set a new property
            JSONObject propertyValue = createProperty();
            String propertyKey = "property/" + currentThreadName + "/" + propertyValue.getString("property");
            userInfo.setProperty(propertyKey, propertyValue.toString());
            metaStore.updateUser(userInfo);

            // read the user again
            userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to verify the property.");
            } else if (userInfo.getProperty(propertyKey) == null) {
              logger.debug("Meta File Error, JSONObject is missing " + propertyKey + " that was just added.");
            }
          }
        } catch (JSONException e) {
          Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
View Full Code Here

  }

  @Test
  public void testUpdateUser() throws CoreException {
    IMetaStore store = getMetaStore();
    UserInfo user = new UserInfo();
    user.setUserName("testUpdateUser");
    //should not be able to update user that does not exist
    try {
      store.updateUser(user);
      assertTrue("Update should have failed", false);
    } catch (Exception e) {
      //expected
    }
    store.createUser(user);
    //now update should succeed
    try {
      store.updateUser(user);
    } catch (Exception e) {
      assertTrue("Update should have succeeded", false);
    }
    store.deleteUser(user.getUniqueId());
    //should not be able to update user that does not exist
    try {
      store.updateUser(user);
      assertTrue("Update should have failed", false);
    } catch (Exception e) {
View Full Code Here

          IMetaStore metaStore = getMetaStore();
          String currentThreadName = Thread.currentThread().getName();
          List<String> propertyKeys = new ArrayList<String>();

          // read the user
          UserInfo userInfo = metaStore.readUser("anthony");
          if (userInfo == null) {
            logger.debug("Meta File Error, could not read user anthony to delete a property.");
            return;
          }

          // get the list of properties to delete

          for (String key : userInfo.getProperties().keySet()) {
            if (key.startsWith("property/" + currentThreadName)) {
              propertyKeys.add(key);
            }
          }

          // now delete the properties
          for (String key : propertyKeys) {
            // read the user
            userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to delete a property.");
              continue;
            }

            // set a new property
            userInfo.setProperty(key, null);
            metaStore.updateUser(userInfo);

            // read the user again
            userInfo = metaStore.readUser("anthony");
            if (userInfo == null) {
              logger.debug("Meta File Error, could not read user anthony to verify the property.");
            } else if (userInfo.getProperty(key) != null) {
              logger.debug("Meta File Error, JSONObject contains " + key + " that was just deleted.");
            }
          }

        } catch (CoreException e) {
View Full Code Here

  public void testSimpleMetaStoreCreatePropertyConcurrency() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = getMetaStore();

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName("anthony");
    userInfo.setFullName("Anthony Hunter");
    metaStore.createUser(userInfo);

    // add properties to the user in multiple threads
    Thread threads[] = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = createPropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure the properties are there
    userInfo = metaStore.readUser("anthony");
    int count = 0;
    Map<String, String> properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    // delete the user
    metaStore.deleteUser(userInfo.getUniqueId());

    assertEquals("Incomplete number of properties added for the user", THREAD_COUNT * PROPERTY_COUNT, count);
  }
View Full Code Here

  public void testSimpleMetaStoreDeletePropertyConcurrency() throws CoreException {
    // create the MetaStore
    IMetaStore metaStore = getMetaStore();

    // create the user
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName("anthony");
    userInfo.setFullName("Anthony Hunter");
    metaStore.createUser(userInfo);

    // add properties to the user in multiple threads
    Thread threads[] = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = createPropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure the properties are there
    userInfo = metaStore.readUser("anthony");
    int count = 0;
    Map<String, String> properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    assertEquals("Incomplete number of properties added for the user", THREAD_COUNT * PROPERTY_COUNT, count);

    // delete properties in multiple threads
    threads = new Thread[THREAD_COUNT];
    for (int i = 0; i < threads.length; i++) {
      threads[i] = deletePropertyThread(i);
    }

    for (int i = 0; i < threads.length; i++) {
      try {
        threads[i].join();
      } catch (InterruptedException e) {
        // just continue
      }
    }

    // read the user and make sure there are no properties are there
    userInfo = metaStore.readUser("anthony");
    count = 0;
    properties = userInfo.getProperties();
    for (String key : properties.keySet()) {
      if (key.startsWith("property/")) {
        count++;
      }
    }

    // delete the user
    metaStore.deleteUser(userInfo.getUniqueId());

    assertEquals("Incomplete number of properties deleted for the user", 0, count);
  }
View Full Code Here

  public static void setAuthentication(WebRequest request) {
    setAuthentication(request, testUserLogin, testUserPassword);
  }

  public void setUpAuthorization() throws CoreException {
    UserInfo testUser = createUser(testUserLogin, testUserPassword);
    testUserId = testUser.getUniqueId();
    //by default allow tests to modify anything
    AuthorizationService.addUserRight(testUserId, "/");
    AuthorizationService.addUserRight(testUserId, "/*");
  }
 
View Full Code Here

  /**
   * Returns the user with the given login. If the user doesn't exist,
   * one is created with the provided id and password.
   */
  protected UserInfo createUser(String login, String password) {
    UserInfo userInfo = null;
    try {
      // see if the user exists already
      IMetaStore metaStore = OrionConfiguration.getMetaStore();
      userInfo = metaStore.readUserByProperty(UserConstants2.USER_NAME, login, false, false);
      if (userInfo != null) {
        return userInfo;
      }

      // create new user in the metadata storage
      userInfo = new UserInfo();
      userInfo.setUserName(login);
      userInfo.setFullName(login);
      userInfo.setProperty(UserConstants2.PASSWORD, password);

      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      LogHelper.log(new Status(IStatus.ERROR, ServerTestsActivator.PI_TESTS, 1, "An error occured when creating a user", e));
    }
View Full Code Here

TOP

Related Classes of org.eclipse.orion.server.core.metastore.UserInfo

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.