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

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


      return false;
    }

    String userId = userPathInfo.split("\\/")[1]; //$NON-NLS-1$
    try {
      UserInfo userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userId, false, false);
      if (userInfo == null) {
        return false;
      }

      PrintWriter writer = response.getWriter();
      writer.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2 Final//EN\">"); //$NON-NLS-1$
      writer.println("<html>"); //$NON-NLS-1$
      writer.println(" <head>"); //$NON-NLS-1$
      writer.println("<title>Details of " + userId + "</title>"); //$NON-NLS-1$ //$NON-NLS-2$
      writer.println("</head>"); //$NON-NLS-1$
      writer.println("<body>"); //$NON-NLS-1$
      writer.println("<h1>Details of " + userId + "</h1>"); //$NON-NLS-1$ //$NON-NLS-2$

      if (userInfo.getProperties().containsKey(UserConstants2.LAST_LOGIN_TIMESTAMP)) {
        String lastLoginTimestamp = userInfo.getProperty(UserConstants2.LAST_LOGIN_TIMESTAMP);
        writer.println(UserConstants2.LAST_LOGIN_TIMESTAMP + " : " + lastLoginTimestamp + "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
      }
      if (userInfo.getProperties().containsKey(UserConstants2.DISK_USAGE)) {
        String diskUsage = userInfo.getProperty(UserConstants2.DISK_USAGE);
        writer.println(UserConstants2.DISK_USAGE + " : " + diskUsage + "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
      }
      if (userInfo.getProperties().containsKey(UserConstants2.DISK_USAGE_TIMESTAMP)) {
        String diskUsageTimestamp = userInfo.getProperty(UserConstants2.DISK_USAGE_TIMESTAMP);
        writer.println(UserConstants2.DISK_USAGE_TIMESTAMP + " : " + diskUsageTimestamp + "<br/>"); //$NON-NLS-1$ //$NON-NLS-2$
      }

      writer.println("<hr>"); //$NON-NLS-1$
      writer.println("</pre>"); //$NON-NLS-1$
View Full Code Here


    String[] userPathInfoParts = req.getPathInfo().split("\\/", 2);

    // handle calls to /users/[userId]
    String userId = userPathInfoParts[1];

    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userId, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      resp.sendError(HttpServletResponse.SC_NOT_FOUND, "User " + userId + " not found.");
View Full Code Here

    List<UserInfo> users = new ArrayList<UserInfo>();

    if (userLogin != null && userLogin.trim().length() > 0) {
      //reset using login
      UserInfo userInfo = null;
      try {
        userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userLogin.trim(), false, false);
      } catch (CoreException e) {
        LogHelper.log(e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
        return;
      }

      if (userInfo == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, "User " + userLogin + " not found.");
        return;
      }
      if (userEmail != null && userEmail.trim().length() > 0) {
        if (!isEmailConfirmed(userInfo)) {
          resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "User " + userLogin + " email has not been yet confirmed." + " Please follow the instructions from the confirmation email in your inbox and then request a password reset again.");
          return;
        }
        if (!userEmail.equals(userInfo.getProperty(UserConstants2.EMAIL))) {
          resp.sendError(HttpServletResponse.SC_NOT_FOUND, "User " + userLogin + " with email " + userEmail + " does not exist.");
          return;
        }
      }
      users.add(userInfo);
    } else if (userEmail != null && userEmail.trim().length() > 0) {
      //reset using email address
      UserInfo userInfo = null;
      try {
        userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.EMAIL, userEmail.trim().toLowerCase(), false, false);
      } catch (CoreException e) {
        LogHelper.log(e);
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
View Full Code Here

   */
  private void initializeAdminUser() {
    try {
      // initialize the admin account in the IMetaStore
      String adminDefaultPassword = PreferenceHelper.getString(ServerConstants.CONFIG_AUTH_ADMIN_DEFAULT_PASSWORD);
      UserInfo admin = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, ADMIN_LOGIN_VALUE, false, false);
      if (admin == null && adminDefaultPassword != null) {
        UserInfo userInfo = new UserInfo();
        userInfo.setUserName(ADMIN_LOGIN_VALUE);
        userInfo.setFullName(ADMIN_NAME_VALUE);
        userInfo.setProperty(UserConstants2.PASSWORD, adminDefaultPassword);
        OrionConfiguration.getMetaStore().createUser(userInfo);
        Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.account"); //$NON-NLS-1$
        if (logger.isInfoEnabled()) {
          logger.info("Account created: " + ADMIN_LOGIN_VALUE); //$NON-NLS-1$
        }
View Full Code Here

   * @throws CoreException If an error occurred persisting user rights.
   */
  public static void addUserRight(String userId, String uri) throws CoreException {
    try {
      //TODO probably want caller to pass in UserInfo for performance
      UserInfo user = OrionConfiguration.getMetaStore().readUser(userId);
      JSONArray userRightArray = AuthorizationReader.getAuthorizationData(user);

      // adds all rights for the uri
      JSONObject userRight = createUserRight(uri);

View Full Code Here

      // except don't allow access to metadata
      if ("/file/".equals(uri) || uri.startsWith("/file/.metadata/")) //$NON-NLS-1$//$NON-NLS-2$
        return false;
      return true;
    }
    UserInfo user = OrionConfiguration.getMetaStore().readUser(userId);
    JSONArray userRightArray = AuthorizationReader.getAuthorizationData(user);
    for (int i = 0; i < userRightArray.length(); i++) {
      try {
        JSONObject userRight = (JSONObject) userRightArray.get(i);
        String patternToMatch = userRight.getString(ProtocolConstants.KEY_USER_RIGHT_URI);
View Full Code Here

   */
  public static void removeUserRight(String userId, String uri) throws CoreException {
    try {
      @SuppressWarnings("unused")
      Activator r = Activator.getDefault();
      UserInfo user = OrionConfiguration.getMetaStore().readUser(userId);
      JSONArray userRightArray = AuthorizationReader.getAuthorizationData(user);
      for (int i = 0; i < userRightArray.length(); i++) {
        if (uri.equals(((JSONObject) userRightArray.get(i)).get(ProtocolConstants.KEY_USER_RIGHT_URI)))
          userRightArray.remove(i);
      }
View Full Code Here

    UserEmailUtil util = UserEmailUtil.getUtil();
    if (!util.isEmailConfigured()) {
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
          "Smpt server not configured", null));
    }
    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, login, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(request, response, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(),
          e));
    }
    try {
      if (reviewRequestEmail == null) {
        reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE);
      }

      String emailAdress = userInfo.getProperty(UserConstants2.EMAIL);

      util.sendEmail(
          reviewRequestEmail.getTitle(),
          reviewRequestEmail.getContent().replaceAll(EMAIL_COMMITER_NAME, authorName).replaceAll(EMAIL_URL_LINK, url)
              .replaceAll(EMAIL_COMMIT_MESSAGE, message), emailAdress);
View Full Code Here

      // The workspace name you create must be Orion Content. See Bug 439735
      Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
      logger.info("SimpleMetaStore.createWorkspace: workspace name conflict: name will be \"Orion Content\": user " + workspaceInfo.getUserId() + " provided " + workspaceInfo.getFullName() + " instead.");
      workspaceInfo.setFullName(SimpleMetaStore.DEFAULT_WORKSPACE_NAME);
    }
    UserInfo userInfo;
    try {
      userInfo = readUser(workspaceInfo.getUserId());
    } catch (CoreException exception) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createWorkspace: could not find user with id: " + workspaceInfo.getUserId() + ", user does not exist.", null));
    }
    if (userInfo == null) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createWorkspace: could not find user with id: " + workspaceInfo.getUserId() + ", user does not exist.", null));
    }
    if (!userInfo.getWorkspaceIds().isEmpty()) {
      // We have an existing workspace already, you cannot create a second workspace. See Bug 439735
      String existingWorkspaceIds = userInfo.getWorkspaceIds().get(0);
      Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.config"); //$NON-NLS-1$
      logger.info("SimpleMetaStore.createWorkspace: workspace conflict: cannot create a second workspace for user id: " + userInfo.getUniqueId() + ", existing workspace is being used: " + existingWorkspaceIds);
      workspaceInfo.setUniqueId(existingWorkspaceIds);
      return;
    }
    // We create a meta folder for the workspace using the encoded workspace name
    String workspaceId = SimpleMetaStoreUtil.encodeWorkspaceId(workspaceInfo.getUserId(), workspaceInfo.getFullName());
    String encodedWorkspaceName = SimpleMetaStoreUtil.decodeWorkspaceNameFromWorkspaceId(workspaceId);
    // It is possible to have two workspaces with the same name, so append an integer if this is a duplicate name.
    File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(getRootLocation(), userInfo.getUniqueId());
    workspaceInfo.setUniqueId(workspaceId);
    JSONObject jsonObject = new JSONObject();
    try {
      jsonObject.put(SimpleMetaStore.ORION_VERSION, VERSION);
      jsonObject.put(MetadataInfo.UNIQUE_ID, workspaceInfo.getUniqueId());
      jsonObject.put("UserId", workspaceInfo.getUserId());
      jsonObject.put(UserConstants2.FULL_NAME, workspaceInfo.getFullName());
      jsonObject.put("ProjectNames", new JSONArray());
      JSONObject properties = updateProperties(jsonObject, workspaceInfo);
      jsonObject.put("Properties", properties);
    } catch (JSONException e) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createWorkspace: could not create workspace: " + encodedWorkspaceName + " for user " + userInfo.getUserName(), e));
    }
    if (!SimpleMetaStoreUtil.createMetaFolder(userMetaFolder, encodedWorkspaceName)) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createWorkspace: could not create workspace: " + encodedWorkspaceName + " for user " + userInfo.getUserName(), null));
    }
    if (!SimpleMetaStoreUtil.createMetaFile(userMetaFolder, workspaceId, jsonObject)) {
      throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.createWorkspace: could not create workspace: " + encodedWorkspaceName + " for user " + userInfo.getUserName(), null));
    }

    // Update the user with the new workspaceId
    List<String> newWorkspaceIds = new ArrayList<String>();
    newWorkspaceIds.addAll(userInfo.getWorkspaceIds());
    newWorkspaceIds.add(workspaceId);
    userInfo.setWorkspaceIds(newWorkspaceIds);
    updateUser(userInfo);
  }
View Full Code Here

  public void deleteUser(String userId) throws CoreException {
    ReadWriteLock lock = getLockForUser(userId);
    lock.writeLock().lock();
    try {
      UserInfo userInfo;
      try {
        userInfo = readUser(userId);
      } catch (CoreException exception) {
        throw new CoreException(new Status(IStatus.ERROR, ServerConstants.PI_SERVER_CORE, 1, "SimpleMetaStore.deleteUser: could not delete user with id: " + userId + ", user does not exist.", null));
      }

      // First delete the workspaces
      for (String workspaceId : userInfo.getWorkspaceIds()) {
        deleteWorkspace(userId, workspaceId);
      }

      File userMetaFolder = SimpleMetaStoreUtil.readMetaUserFolder(getRootLocation(), userId);
      if (!SimpleMetaStoreUtil.deleteMetaFile(userMetaFolder, SimpleMetaStore.USER)) {
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.