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

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


    for (String projectName : workspaceInfo.getProjectNames()) {
      deleteProject(workspaceId, projectName);
    }

    // Update the user remove the deleted workspaceId
    UserInfo userInfo;
    try {
      userInfo = readUser(userId);
    } catch (CoreException exception) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.deleteWorkspace: could not find user with id:" + userId + ", user does not exist.", null));
    }
    List<String> newWorkspaceIds = new ArrayList<String>();
    newWorkspaceIds.addAll(userInfo.getWorkspaceIds());
    newWorkspaceIds.remove(workspaceId);
    userInfo.setWorkspaceIds(newWorkspaceIds);
    updateUser(userInfo);

    // delete the meta file and folder
    if (!SimpleMetaStoreUtil.deleteMetaFile(userMetaFolder, workspaceId)) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.deleteWorkspace: could not delete workspace: " + encodedWorkspaceName, null));
View Full Code Here


        if (jsonObject == null) {
          Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
          logger.info("SimpleMetaStore.readUser: could not read user " + userId); //$NON-NLS-1$
          return null;
        }
        UserInfo userInfo = new UserInfo();
        try {
          SimpleMetaStoreMigration migration = new SimpleMetaStoreMigration();
          if (migration.isMigrationRequired(jsonObject)) {
            // Migration to the latest version is required for this user
            lock.readLock().unlock();
            lock.writeLock().lock();
            try {
              migration.doMigration(getRootLocation(), userMetaFolder);
              lock.readLock().lock();
            } finally {
              lock.writeLock().unlock();
            }
            jsonObject = SimpleMetaStoreUtil.readMetaFile(userMetaFolder, SimpleMetaStore.USER);
          }
          userInfo.setUniqueId(jsonObject.getString(MetadataInfo.UNIQUE_ID));
          userInfo.setUserName(jsonObject.getString(UserConstants2.USER_NAME));
          if (jsonObject.isNull(UserConstants2.FULL_NAME)) {
            userInfo.setFullName("Unnamed User");
          } else {
            userInfo.setFullName(jsonObject.getString(UserConstants2.FULL_NAME));
          }
          List<String> userWorkspaceIds = new ArrayList<String>();
          JSONArray workspaceIds = jsonObject.getJSONArray("WorkspaceIds");
          if (workspaceIds.length() > 0) {
            for (int i = 0; i < workspaceIds.length(); i++) {
              userWorkspaceIds.add(workspaceIds.getString(i));
            }
          }
          userInfo.setWorkspaceIds(userWorkspaceIds);
          if (userInfo.getWorkspaceIds().size() > 1) {
            // It is currently unexpected that a user has more than one workspace. See Bug 439735
            Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
            logger.warn("SimpleMetaStore.readUser: user id " + userInfo.getUniqueId() + " has a multiple workspace conflict: workspace: " + userInfo.getWorkspaceIds().get(0) + " and workspace: " + userInfo.getWorkspaceIds().get(1));
          }
          setProperties(userInfo, jsonObject.getJSONObject("Properties"));
          userInfo.flush();
        } catch (JSONException e) {
          throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.readUser: could not read user " + userId, e));
        }
        return userInfo;
      }
    } finally {
      lock.readLock().unlock();
    }

    // user does not exist for this userId, create it ( see Bug 415505 )
    UserInfo userInfo = new UserInfo();
    userInfo.setUniqueId(userId);
    userInfo.setUserName(userId);
    userInfo.setFullName("Unnamed User");
    createUser(userInfo);
    return userInfo;
  }
View Full Code Here

    }

    if (user != null && ! pathInfo.startsWith("/oauth")) {
      try {
        // try to store the login timestamp in the user profile
        UserInfo userInfo = OrionConfiguration.getMetaStore().readUser(user);
        userInfo.setProperty(UserConstants2.LAST_LOGIN_TIMESTAMP, new Long(System.currentTimeMillis()).toString());
        OrionConfiguration.getMetaStore().updateUser(userInfo);
      } catch (CoreException e) {
        // just log that the login timestamp was not stored
        LogHelper.log(e);
      }
View Full Code Here

   */
  public static LoginResult performAuthentication(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.login"); //$NON-NLS-1$
    String login = req.getParameter(UserConstants.KEY_LOGIN);
    // TODO: Bug 444864 should be "Password"
    UserInfo userInfo = getUserForCredentials(login, req.getParameter("password"));

    if (userInfo != null) {
      if (userInfo.getProperties().containsKey(UserConstants2.BLOCKED)) {
        return LoginResult.BLOCKED;
      }
      String userId = userInfo.getUniqueId();
      if (logger.isInfoEnabled())
        logger.info("Login success: " + login); //$NON-NLS-1$
      req.getSession().setAttribute("user", userId); //$NON-NLS-1$

      if (getEventService() != null) {
        JSONObject message = new JSONObject();
        try {
          SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", Locale.US);
          Date date = new Date(System.currentTimeMillis());
          message.put("event", "login");
          message.put("published", format.format(date));
          message.put("user", userId);
        } catch (JSONException e1) {
          LogHelper.log(e1);
        }
        getEventService().publish("orion/login", message);
      }

      try {
        // try to store the login timestamp in the user profile
        userInfo.setProperty(UserConstants2.LAST_LOGIN_TIMESTAMP, new Long(System.currentTimeMillis()).toString());
        OrionConfiguration.getMetaStore().updateUser(userInfo);
      } catch (CoreException e) {
        // just log that the login timestamp was not stored
        LogHelper.log(e);
      }
View Full Code Here

    return LoginResult.FAIL;
  }

  private static 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;
        } else {
          // password verification failed
          return null;
View Full Code Here

  public static JSONObject getUserJson(String uid, String contextPath) throws JSONException {
    JSONObject obj = new JSONObject();
    obj.put(UserConstants.KEY_LOGIN, uid);
    try {
      UserInfo userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, uid, false, false);
      if (userInfo == null) {
        return null;
      }
      obj.put(UserConstants.KEY_UID, uid);
      obj.put(UserConstants.KEY_LOGIN, userInfo.getUserName());
      obj.put(UserConstants.KEY_LOCATION, contextPath + '/' + UserConstants.KEY_USERS + '/' + uid);
      obj.put(UserConstants2.FULL_NAME, userInfo.getFullName());
      if (userInfo.getProperties().containsKey(UserConstants2.LAST_LOGIN_TIMESTAMP)) {
        Long lastLoginTimestamp = Long.parseLong(userInfo.getProperty(UserConstants2.LAST_LOGIN_TIMESTAMP));
        obj.put(UserConstants2.LAST_LOGIN_TIMESTAMP, lastLoginTimestamp);
      }
      if (userInfo.getProperties().containsKey(UserConstants2.DISK_USAGE_TIMESTAMP)) {
        Long diskUsageTimestamp = Long.parseLong(userInfo.getProperty(UserConstants2.DISK_USAGE_TIMESTAMP));
        obj.put(UserConstants2.DISK_USAGE_TIMESTAMP, diskUsageTimestamp);
      }
      if (userInfo.getProperties().containsKey(UserConstants2.DISK_USAGE)) {
        String diskUsage = userInfo.getProperty(UserConstants2.DISK_USAGE);
        obj.put(UserConstants2.DISK_USAGE, diskUsage);
      }
    } catch (IllegalArgumentException e) {
      LogHelper.log(e);
    } catch (CoreException e) {
View Full Code Here

    setUpAuthorization();
  }

  @Override
  public void setUpAuthorization() throws CoreException {
    UserInfo testUser = createUser(getTestUserName(), getTestUserPassword());
    setTestUserRights(testUser);
    UserInfo adminUser = createUser("admin", "admin");
    setAdminRights(adminUser);
  }
View Full Code Here

    assertEquals(fullName, userInfo.getFullName());
  }

  @Test
  public void testUserName() {
    UserInfo userInfo = new UserInfo();
    String userName = "test";
    userInfo.setUserName(userName);
    assertEquals(userName, userInfo.getUserName());
  }
View Full Code Here

    assertEquals(userName, userInfo.getUserName());
  }

  @Test
  public void testProperties() {
    UserInfo userInfo = new UserInfo();
    String key1 = "key1";
    String value1 = "value1";
    String key2 = "key2";
    String value2 = "value2";
    assertNull(userInfo.getProperty(key1));
    assertNull(userInfo.getProperty(key2));
    assertEquals(0, userInfo.getProperties().size());
    userInfo.setProperty(key1, value1);
    assertEquals(value1, userInfo.getProperty(key1));
    assertEquals(1, userInfo.getProperties().size());
    userInfo.setProperty(key2, value2);
    assertEquals(value1, userInfo.getProperty(key1));
    assertEquals(value2, userInfo.getProperty(key2));
    assertEquals(2, userInfo.getProperties().size());
    userInfo.setProperty(key2, null);
    assertNull(userInfo.getProperty(key2));
    assertEquals(1, userInfo.getProperties().size());
    userInfo.setProperty(key1, null);
    assertNull(userInfo.getProperty(key1));
    assertEquals(0, userInfo.getProperties().size());
  }
View Full Code Here

    assertEquals(0, userInfo.getProperties().size());
  }

  @Test
  public void testWorkspaceIds() {
    UserInfo userInfo = new UserInfo();
    String id1 = "id1";
    String id2 = "id2";
    List<String> ids = new ArrayList<String>();
    assertEquals(0, userInfo.getWorkspaceIds().size());
    ids.add(id1);
    userInfo.setWorkspaceIds(ids);
    assertEquals(1, userInfo.getWorkspaceIds().size());
    assertTrue(userInfo.getWorkspaceIds().contains(id1));
    ids.add(id2);
    userInfo.setWorkspaceIds(ids);
    assertEquals(2, userInfo.getWorkspaceIds().size());
    assertTrue(userInfo.getWorkspaceIds().contains(id1));
    assertTrue(userInfo.getWorkspaceIds().contains(id2));
    ids.remove(id1);
    userInfo.setWorkspaceIds(ids);
    assertFalse(userInfo.getWorkspaceIds().contains(id1));
    assertEquals(1, userInfo.getWorkspaceIds().size());
    ids.remove(id2);
    userInfo.setWorkspaceIds(ids);
    assertFalse(userInfo.getWorkspaceIds().contains(id2));
    assertEquals(0, userInfo.getWorkspaceIds().size());
  }
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.