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

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


   * @param site <code>null</code>
   */
  private boolean handlePost(HttpServletRequest req, HttpServletResponse resp, SiteInfo site) throws CoreException, IOException, JSONException {
    if (site != null)
      throw new IllegalArgumentException("Can't POST to an existing site");
    UserInfo user = OrionConfiguration.getMetaStore().readUser(getUserName(req));
    JSONObject requestJson = getRequestJson(req);
    try {
      site = doCreateSiteConfiguration(req, requestJson, user);
      changeHostingStatus(req, resp, requestJson, user, site);
    } catch (CoreException e) {
View Full Code Here


    resp.addHeader(ProtocolConstants.HEADER_LOCATION, result.getString(ProtocolConstants.KEY_LOCATION));
    return true;
  }

  private boolean handlePut(HttpServletRequest req, HttpServletResponse resp, SiteInfo site) throws IOException, CoreException, JSONException {
    UserInfo user = OrionConfiguration.getMetaStore().readUser(getUserName(req));
    JSONObject requestJson = OrionServlet.readJSONRequest(req);
    copyProperties(requestJson, site, true);

    // Start/stop the site if necessary
    changeHostingStatus(req, resp, requestJson, user, site);
View Full Code Here

    OrionServlet.writeJSONResponse(req, resp, result, JsonURIUnqualificationStrategy.LOCATION_ONLY);
    return true;
  }

  private boolean handleDelete(HttpServletRequest req, HttpServletResponse resp, SiteInfo site) throws CoreException {
    UserInfo user = OrionConfiguration.getMetaStore().readUser(getUserName(req));
    ISiteHostingService hostingService = getHostingService();
    IHostedSite runningSite = hostingService.get(site, user);
    if (runningSite != null) {
      String msg = NLS.bind("Site configuration is running at {0}. Must be stopped before it can be deleted", runningSite.getHost());
      throw new CoreException(new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CONFLICT, msg, null));
View Full Code Here

      if (count >= start + rows)
        break;
      if (count++ < start)
        continue;
      URI userLocation = URIUtil.append(location, userId);
      UserInfo userInfo = OrionConfiguration.getMetaStore().readUser(userId);
      userJSONs.add(formJson(userInfo, userLocation, req.getContextPath()));
    }
    JSONObject json = new JSONObject();
    json.put(UserConstants.KEY_USERS, userJSONs);
    json.put(UserConstants.KEY_USERS_START, start);
View Full Code Here

    OrionServlet.writeJSONResponse(req, resp, json);
    return true;
  }

  private boolean handleUserGet(HttpServletRequest req, HttpServletResponse resp, String userId) throws IOException, JSONException, ServletException, CoreException {
    UserInfo userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userId, false, false);

    if (userInfo == null)
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "User not found " + userId, null));

    URI location = ServletResourceHandler.getURI(req);
View Full Code Here

    String password = req.getParameter("password");

    if (login == null || login.length() == 0)
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User login not specified.", null));

    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, login, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    }

    if (userInfo == null)
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_NOT_FOUND, "User " + login + " could not be found.", null));

    String passwordMsg = validatePassword(password);
    if (passwordMsg != null) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, passwordMsg, null));
    }

    try {
      userInfo.setProperty(UserConstants2.PASSWORD, password);
      OrionConfiguration.getMetaStore().updateUser(userInfo);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    }
View Full Code Here

    if (isEmailRequired && (email == null || email.length() == 0)) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User email is mandatory.", null));
    }

    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, login, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    }

    if (userInfo != null) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User " + login + " already exists.", null));
    }
    if (email != null && email.length() > 0) {
      if (!email.contains("@")) { //$NON-NLS-1$
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Invalid user email.", null));
      }

      userInfo = null;
      try {
        userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.EMAIL, email.toLowerCase(), false, false);
      } catch (CoreException e) {
        LogHelper.log(e);
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
      }

      if (userInfo != null) {
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Email address already in use: {0}.", email), null));
      }
    }

    userInfo = new UserInfo();
    userInfo.setUserName(login);
    userInfo.setFullName(name);
    userInfo.setProperty(UserConstants2.PASSWORD, password);
    if (identifier != null) {
      userInfo.setProperty(UserConstants2.OAUTH, identifier);
    }
    if (email != null && email.length() > 0) {
      userInfo.setProperty(UserConstants2.EMAIL, email);
    }
    if (isEmailRequired) {
      userInfo.setProperty(UserConstants2.BLOCKED, "true");
      userInfo.setProperty(UserConstants2.EMAIL_CONFIRMATION_ID, getUniqueEmailConfirmationId());
    }

    try {
      OrionConfiguration.getMetaStore().createUser(userInfo);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, NLS.bind("Error creating user: {0}", login), null));
    }

    Logger logger = LoggerFactory.getLogger("org.eclipse.orion.server.account"); //$NON-NLS-1$
    if (logger.isInfoEnabled())
      logger.info("Account created: " + login); //$NON-NLS-1$

    try {
      //give the user access to their own user profile
      String location = '/' + UserConstants.KEY_USERS + '/' + userInfo.getUniqueId();
      AuthorizationService.addUserRight(userInfo.getUniqueId(), location);
    } catch (CoreException e) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User rights could not be added.", e));
    }

    URI userLocation = URIUtil.append(ServletResourceHandler.getURI(req), userInfo.getUniqueId());

    if (isEmailRequired) {
      try {
        UserEmailUtil.getUtil().sendEmailConfirmation(req, userInfo);
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_CREATED, NLS.bind("Your account {0} has been successfully created. You have been sent an email address verification. Follow the instructions in this email to login to your Orion account.", login), null));
      } catch (URISyntaxException e) {
        LogHelper.log(e);
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Could not send confirmation email to " + userInfo.getProperty(UserConstants2.EMAIL), null));
      }
    }
    OrionServlet.writeJSONResponse(req, resp, formJson(userInfo, userLocation, req.getContextPath()));
    if (email != null && email.length() > 0 && UserEmailUtil.getUtil().isEmailConfigured()) {
      try {
View Full Code Here

  }

  private boolean handleUserPut(HttpServletRequest req, HttpServletResponse resp, String userId) throws ServletException, IOException, CoreException, JSONException {
    JSONObject data = OrionServlet.readJSONRequest(req);

    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userId, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    }

    if (userInfo == null) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User " + userId + " could not be found.", null));
    }
    String emailConfirmationid = userInfo.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID);

    //users other than admin have to know the old password to set a new one
    if (!isAdmin(req.getRemoteUser())) {
      // TODO: Bug 444864 should be "Password"
      if (data.has("password") && userInfo.getProperty(UserConstants2.PASSWORD) != null && (!data.has(UserConstants.KEY_OLD_PASSWORD) || !userInfo.getProperty(UserConstants2.PASSWORD).equals(data.getString(UserConstants.KEY_OLD_PASSWORD)))) {
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Invalid old password", null));
      }
    }

    String newPassword = null;
    // TODO: Bug 444864 should be "Password"
    if (data.has("password")) {
      newPassword = data.getString("password");
    }
    String passwordMsg = validatePassword(newPassword);
    if (data.has(UserConstants.KEY_OLD_PASSWORD) && passwordMsg != null) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, passwordMsg, null));
    }

    if (data.has(UserConstants.KEY_LOGIN)) {
      userInfo.setUserName(data.getString(UserConstants.KEY_LOGIN));
    }
    if (data.has(UserConstants2.FULL_NAME)) {
      userInfo.setFullName(data.getString(UserConstants2.FULL_NAME));
    }
    // TODO: Bug 444864 should be "Password"
    if (data.has("password")) {
      userInfo.setProperty(UserConstants2.PASSWORD, data.getString("password"));
    }
    // TODO: Bug 444864 should be "Email"
    if (data.has("email")) {
      userInfo.setProperty(UserConstants2.EMAIL, data.getString("email"));
    }

    if (data.has(UserConstants.KEY_PROPERTIES)) {
      JSONObject propertiesObject = data.getJSONObject(UserConstants.KEY_PROPERTIES);
      Iterator<?> propertyIterator = propertiesObject.keys();
      while (propertyIterator.hasNext()) {
        String propertyKey = (String) propertyIterator.next();
        userInfo.setProperty(propertyKey, propertiesObject.getString(propertyKey));
      }
    }

    try {
      OrionConfiguration.getMetaStore().updateUser(userInfo);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
    }

    if (userInfo.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID) != null && !userInfo.getProperty(UserConstants2.EMAIL_CONFIRMATION_ID).equals(emailConfirmationid)) {
      try {
        UserEmailUtil.getUtil().sendEmailConfirmation(req, userInfo);
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.INFO, HttpServletResponse.SC_OK, "Confirmation email has been sent to " + userInfo.getProperty(UserConstants2.EMAIL), null));
      } catch (Exception e) {
        LogHelper.log(new Status(IStatus.ERROR, Activator.PI_SERVER_SERVLETS, "Error while sending email" + (e.getMessage() == null ? "" : ": " + e.getMessage()) + ". See http://wiki.eclipse.org/Orion/Server_admin_guide#Email_configuration for email configuration guide."));
        return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Could not send confirmation email to " + userInfo.getProperty(UserConstants2.EMAIL), null));
      }
    }

    return true;
  }
View Full Code Here

    }
    return false;
  }

  private boolean handleUserDelete(HttpServletRequest req, HttpServletResponse resp, String userId) throws ServletException {
    UserInfo userInfo = null;
    try {
      userInfo = OrionConfiguration.getMetaStore().readUserByProperty(UserConstants2.USER_NAME, userId, false, false);
    } catch (CoreException e) {
      LogHelper.log(e);
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Removing " + userId + " failed.", e));
    }

    if (userInfo == null) {
      return statusHandler.handleRequest(req, resp, new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "User " + userId + " could not be found.", null));
    }

    // Delete user from metadata store
    try {
      @SuppressWarnings("unused")
      Activator r = Activator.getDefault();
      final IMetaStore metastore = OrionConfiguration.getMetaStore();
      if (userInfo.getWorkspaceIds().size() > 0) {
        for (String workspaceId : userInfo.getWorkspaceIds()) {
          WorkspaceInfo workspaceInfo = metastore.readWorkspace(workspaceId);
          if (workspaceInfo.getProjectNames().size() > 0) {
            for (String projectName : workspaceInfo.getProjectNames()) {
              ProjectInfo projectInfo = metastore.readProject(workspaceId, projectName);
              if (projectInfo != null) {
View Full Code Here

    traceRequest(req);
    String pathInfo = req.getPathInfo();

    if (pathInfo != null && !pathInfo.equals("/")) {
      String userId = pathInfo.split("\\/")[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_INTERNAL_SERVER_ERROR, e.getMessage());
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.