@Test
  public void testGetUserProfileNodeCreateFalse() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Existing Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(createdUser.getUid(), false);
    assertNotNull(userProfileNode);
  }
  @Test
  public void testGetUserProfileNodeCreateTrue() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Create Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(createdUser.getUid(), true);

    IOrionUserProfileNode generalProfilePart =
        userProfileNode.getUserProfileNode(IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      generalProfilePart.put("GitMail", email, false);
      generalProfilePart.put("GitName", name, false);
      generalProfilePart.flush();
    } catch (CoreException e) {
      fail("Could not update the user profile node: " + e.getLocalizedMessage());
    }

    // read back the profile node
    IOrionUserProfileNode readProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      String gitMail = readProfileNode.get("GitMail", null);
      assertNotNull(gitMail);
      assertEquals(email, gitMail);
      String gitName = readProfileNode.get("GitName", null);
      assertNotNull(gitName);
      assertEquals(name, gitName);
    } catch (CoreException e) {
      fail("Could not read the user profile node: " + e.getLocalizedMessage());
    }
  }
  @Test
  public void testGetUserProfileNode() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Profile Node";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);

    // set the last login timestamp
    String lastLogin = new Long(System.currentTimeMillis()).toString();
    try {
      userProfileNode.put(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, lastLogin, false);
      userProfileNode.flush();
    } catch (CoreException e) {
      fail("Could not put the user profile node: " + e.getLocalizedMessage());
    }

    // read back the profile node
    IOrionUserProfileNode readProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);
    try {
      String readLastLogin =
          readProfileNode.get(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, null);
      assertNotNull(readLastLogin);
      assertEquals(lastLogin, readLastLogin);
    } catch (CoreException e) {
      fail("Could not read the user profile node: " + e.getLocalizedMessage());
    }
  }
Example #4
0
 /**
  * Returns the existing WebProject corresponding to the provided path, or <code>null</code> if no
  * such project exists.
  *
  * @param path path in the form /file/{workspaceId}/{projectName}/[filePath]
  * @return the web project, or <code>null</code>
  */
 public static ProjectInfo projectFromPath(IPath path) {
   if (path == null || path.segmentCount() < 3) return null;
   String workspaceId = path.segment(1);
   String projectName = path.segment(2);
   try {
     return OrionConfiguration.getMetaStore().readProject(workspaceId, projectName);
   } catch (CoreException e) {
     return null;
   }
 }
Example #5
0
  public void start(BundleContext bundleContext) throws Exception {
    singleton = this;
    String metastore = OrionConfiguration.getMetaStorePreference();

    if (ServerConstants.CONFIG_META_STORE_SIMPLE.equals(metastore)
        || ServerConstants.CONFIG_META_STORE_SIMPLE_V2.equals(metastore)) {
      Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); // $NON-NLS-1$
      userCredentialsService =
          bundleContext.registerService(
              IOrionCredentialsService.class, new SimpleUserCredentialsService(), null);
      logger.debug("Started simple user credentials service."); // $NON-NLS-1$
      userProfileService =
          bundleContext.registerService(
              IOrionUserProfileService.class, new SimpleUserProfileService(), null);
      logger.debug("Started simple user profile service."); // $NON-NLS-1$
    }
  }
  @Test
  public void testGetUserNames() {
    // get the orion credentials service
    IOrionCredentialsService orionCredentialsService =
        UserServiceHelper.getDefault().getUserStore();

    // particulars for the new user
    String login = "******";
    String name = "Test Names";
    String email = "*****@*****.**";
    String password = "******";

    // create user pattern is to persist the new user in the metadata store first
    UserInfo userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      fail("Could not create user in IMetaStore: " + e.getLocalizedMessage());
    }

    // create the new user using the IOrionCredentialsService
    User user = new User(userInfo.getUniqueId(), login, name, password);
    user.setEmail(email);
    User createdUser = orionCredentialsService.createUser(user);
    assertNotNull(createdUser);

    // get the profile node
    IOrionUserProfileService orionUserProfileService =
        UserServiceHelper.getDefault().getUserProfileService();
    IOrionUserProfileNode userProfileNode =
        orionUserProfileService.getUserProfileNode(
            createdUser.getUid(), IOrionUserProfileConstants.GENERAL_PROFILE_PART);

    // set the last login timestamp
    String lastLogin = new Long(System.currentTimeMillis()).toString();
    try {
      userProfileNode.put(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, lastLogin, false);
      userProfileNode.flush();
    } catch (CoreException e) {
      fail("Could not put the user profile node: " + e.getLocalizedMessage());
    }

    // get the profile nodes
    orionUserProfileService = UserServiceHelper.getDefault().getUserProfileService();
    String[] userNames = orionUserProfileService.getUserNames();
    List<String> userNamesList = new ArrayList<String>(Arrays.asList(userNames));
    assertTrue(userNamesList.contains(userInfo.getUniqueId()));

    for (String userName : userNamesList) {
      if (userName.equals(userInfo.getUniqueId())) {
        IOrionUserProfileNode readUserProfileNode =
            orionUserProfileService.getUserProfileNode(userName, false);
        String[] childrenNames = readUserProfileNode.childrenNames();
        List<String> childrenNamesList = new ArrayList<String>(Arrays.asList(childrenNames));
        assertTrue(childrenNamesList.contains(IOrionUserProfileConstants.GENERAL_PROFILE_PART));
        assertEquals(1, childrenNamesList.size());
        for (String profilePart : childrenNamesList) {
          assertEquals(IOrionUserProfileConstants.GENERAL_PROFILE_PART, profilePart);
          IOrionUserProfileNode profilePartNode =
              readUserProfileNode.getUserProfileNode(profilePart);
          assertNotNull(profilePartNode);
          try {
            String readLastLogin =
                profilePartNode.get(IOrionUserProfileConstants.LAST_LOGIN_TIMESTAMP, null);
            assertEquals(lastLogin, readLastLogin);
          } catch (CoreException e) {
            fail("Could not read the user profile node: " + e.getLocalizedMessage());
          }
        }
      }
    }
  }