コード例 #1
0
  @Override
  public void addAtributesFor(HttpServletRequest req, URI resource, JSONObject representation) {
    IPath path = new Path(req.getPathInfo() == null ? "" : req.getPathInfo());

    if (!(("/" + SITE_CONFIGURATION_SERVLET_ALIAS).equals(req.getServletPath()))) return;

    try {
      WebUser webUser = getWebUser(req);
      if (path.segmentCount() == 0) {
        if ("GET".equals(req.getMethod())) { // $NON-NLS-1$
          // GET /site/ (get all site configs)
          JSONArray siteConfigurations =
              representation.optJSONArray(SiteConfigurationConstants.KEY_SITE_CONFIGURATIONS);
          if (siteConfigurations != null) {
            for (int i = 0; i < siteConfigurations.length(); i++) {
              addStatus(req, siteConfigurations.getJSONObject(i), webUser, resource);
            }
          }
        } else if ("POST".equals(req.getMethod())) { // $NON-NLS-1$
          // POST /site/ (create a site config)
          addStatus(req, representation, webUser, resource);
        }
      } else if (path.segmentCount() == 1) {
        // GET /site/siteConfigId (get a single site config)
        addStatus(req, representation, webUser, resource);
      }
    } catch (JSONException e) {
      // Shouldn't happen, but since we are just decorating someone else's response we shouldn't
      // cause a failure
      LogHelper.log(e);
    }
  }
コード例 #2
0
  @Override
  public boolean handleRequest(
      HttpServletRequest request, HttpServletResponse response, String path)
      throws ServletException {
    try {
      switch (getMethod(request)) {
        case GET:
          return handleGet(request, response, path);
        case PUT:
          return handlePut(request, response, path);
        case POST:
          return handlePost(request, response, path);
        case DELETE:
          return handleDelete(request, response, path);
        default:
          // we don't know how to handle this request
          return false;
      }

    } catch (Exception e) {
      String msg = NLS.bind("Failed to handle /git/clone request for {0}", path);
      ServerStatus status =
          new ServerStatus(IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg, e);
      LogHelper.log(status);
      return statusHandler.handleRequest(request, response, status);
    }
  }
コード例 #3
0
 public static void log(Throwable t) {
   log(
       new Status(
           IStatus.ERROR,
           ServerConstants.PI_SERVER_CORE,
           "Internal server error",
           t)); //$NON-NLS-1$
 }
コード例 #4
0
 private static byte[] encryptPassword(byte[] password, byte[] salt) {
   try {
     byte[] encryptedPassword = null;
     PBEKeySpec pbeKeySpec = new PBEKeySpec(getPassword(), salt, 1024, 256);
     SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance(ENCRYPTION_ALGORITHM);
     SecretKey secretKey = secretKeyFactory.generateSecret(pbeKeySpec);
     PBEParameterSpec pbeParameterSpec = new PBEParameterSpec(salt, 10);
     Cipher cipher = Cipher.getInstance(ENCRYPTION_ALGORITHM);
     cipher.init(Cipher.ENCRYPT_MODE, secretKey, pbeParameterSpec);
     encryptedPassword = cipher.doFinal(password);
     return encryptedPassword;
   } catch (NoSuchAlgorithmException e) {
     LogHelper.log(e);
   } catch (InvalidKeySpecException e) {
     LogHelper.log(e);
   } catch (InvalidKeyException e) {
     LogHelper.log(e);
   } catch (IllegalBlockSizeException e) {
     LogHelper.log(e);
   } catch (BadPaddingException e) {
     LogHelper.log(e);
   } catch (NoSuchPaddingException e) {
     LogHelper.log(e);
   } catch (InvalidAlgorithmParameterException e) {
     LogHelper.log(e);
   }
   return null;
 }
コード例 #5
0
  // temp code for grabbing files from filesystem
  protected IFileStore tempGetFileStore(IPath path) {
    // first check if we have an alias registered
    if (path.segmentCount() > 0) {
      URI alias = aliasRegistry.lookupAlias(path.segment(0));
      if (alias != null)
        try {
          return EFS.getStore(alias).getFileStore(path.removeFirstSegments(1));
        } catch (CoreException e) {
          LogHelper.log(
              new Status(
                  IStatus.WARNING,
                  HostingActivator.PI_SERVER_HOSTING,
                  1,
                  "An error occured when getting file store for path '"
                      + path
                      + "' and alias '"
                      + alias
                      + '\'',
                  e)); //$NON-NLS-1$ //$NON-NLS-2$
          // fallback is to try the same path relatively to the root
        }
    }
    // assume it is relative to the root
    try {
      return EFS.getStore(rootStoreURI).getFileStore(path);
    } catch (CoreException e) {
      LogHelper.log(
          new Status(
              IStatus.WARNING,
              HostingActivator.PI_SERVER_HOSTING,
              1,
              "An error occured when getting file store for path '"
                  + path
                  + "' and root '"
                  + rootStoreURI
                  + '\'',
              e)); //$NON-NLS-1$ //$NON-NLS-2$
      // fallback and return null
    }

    return null;
  }
コード例 #6
0
 public static String encryptPassword(String password) {
   try {
     byte[] salt = generateSalt();
     byte[] encryptedPassword = encryptPassword(password.getBytes(), salt);
     byte[] saltBase64 = Base64.encode(salt);
     byte[] encryptedPasswordBase64 = Base64.encode(encryptedPassword);
     String saltString = new String(saltBase64, CHAR_ENCODING);
     String encryptedPasswordString = new String(encryptedPasswordBase64, CHAR_ENCODING);
     StringBuffer stringBuffer = new StringBuffer();
     stringBuffer.append(saltString);
     stringBuffer.append(SALT_SEPARATOR);
     stringBuffer.append(encryptedPasswordString);
     return stringBuffer.toString();
   } catch (NoSuchAlgorithmException e) {
     LogHelper.log(e);
   } catch (UnsupportedEncodingException e) {
     LogHelper.log(e);
   }
   return null;
 }
コード例 #7
0
 public static boolean verifyPassword(String password, String encryptedText) {
   try {
     int saltPos = encryptedText.indexOf(SALT_SEPARATOR);
     if (saltPos == -1) {
       throw new RuntimeException("Invalid Data Format");
     }
     byte[] saltBase64 = encryptedText.substring(0, saltPos).getBytes(CHAR_ENCODING);
     byte[] encryptedPasswordBase64 = encryptedText.substring(saltPos + 1).getBytes(CHAR_ENCODING);
     byte[] salt = Base64.decode(saltBase64);
     byte[] encryptedPassword = Base64.decode(encryptedPasswordBase64);
     return verifyPassword(password, encryptedPassword, salt);
   } catch (NoSuchAlgorithmException e) {
     LogHelper.log(e);
   } catch (InvalidKeySpecException e) {
     LogHelper.log(e);
   } catch (UnsupportedEncodingException e) {
     LogHelper.log(e);
   }
   return false;
 }
コード例 #8
0
 /** Returns the platform instance location. */
 public Location getInstanceLocation() {
   if (instanceLocationTracker == null) {
     Filter filter;
     try {
       filter = bundleContext.createFilter(Location.INSTANCE_FILTER);
     } catch (InvalidSyntaxException e) {
       LogHelper.log(e);
       return null;
     }
     instanceLocationTracker = new ServiceTracker<Location, Location>(bundleContext, filter, null);
     instanceLocationTracker.open();
   }
   return instanceLocationTracker.getService();
 }
コード例 #9
0
 private User getUserForCredentials(String login, String password) {
   IOrionCredentialsService userAdmin = defaultUserAdmin;
   if (userAdmin == null) {
     LogHelper.log(
         new Status(
             IStatus.ERROR,
             Activator.PI_SERVER_AUTHENTICATION_BASIC,
             "User admin server is not available"));
     return null;
   }
   User user = userAdmin.getUser("login", login); // $NON-NLS-1$
   if (user != null && user.hasCredential("password", password)) { // $NON-NLS-1$
     return user;
   }
   return null;
 }
コード例 #10
0
 public static String decryptPassword(String encryptedText) {
   try {
     int saltPos = encryptedText.indexOf(SALT_SEPARATOR);
     if (saltPos == -1) {
       throw new RuntimeException("Invalid Data Format");
     }
     byte[] saltBase64 = encryptedText.substring(0, saltPos).getBytes(CHAR_ENCODING);
     byte[] encryptedPasswordBase64 = encryptedText.substring(saltPos + 1).getBytes(CHAR_ENCODING);
     byte[] salt = Base64.decode(saltBase64);
     byte[] encryptedPassword = Base64.decode(encryptedPasswordBase64);
     byte[] decryptedPassword = decryptPassword(encryptedPassword, salt);
     return new String(decryptedPassword);
   } catch (UnsupportedEncodingException e) {
     LogHelper.log(e);
   }
   return null;
 }
コード例 #11
0
 @Override
 protected void doGet(HttpServletRequest req, HttpServletResponse resp)
     throws ServletException, IOException {
   traceRequest(req);
   SolrQuery query = buildSolrQuery(req);
   if (query == null) {
     handleException(resp, "Invalid search request", null, HttpServletResponse.SC_BAD_REQUEST);
     return;
   }
   try {
     QueryResponse solrResponse = SearchActivator.getInstance().getSolrServer().query(query);
     writeResponse(query, req, resp, solrResponse);
   } catch (SolrServerException e) {
     LogHelper.log(e);
     resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
   }
 }
コード例 #12
0
 @Override
 public boolean handleRequest(
     HttpServletRequest request, HttpServletResponse response, IFileStore dir)
     throws ServletException {
   try {
     switch (getMethod(request)) {
       case GET:
         return handleGet(request, response, dir);
       case PUT:
         return handlePut(request, response, dir);
       case POST:
         return handlePost(request, response, dir);
       case DELETE:
         return handleDelete(request, response, dir);
     }
   } catch (JSONException e) {
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_BAD_REQUEST, "Syntax error in request", e));
   } catch (CoreException e) {
     // core exception messages are designed for end user consumption, so use message directly
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage(), e));
   } catch (Exception e) {
     // the exception message is probably not appropriate for end user consumption
     LogHelper.log(e);
     return statusHandler.handleRequest(
         request,
         response,
         new ServerStatus(
             IStatus.ERROR,
             HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
             "An unknown failure occurred. Consult your server log or contact your system administrator.",
             e));
   }
   return false;
 }
コード例 #13
0
  public void addAtributesFor(HttpServletRequest request, URI resource, JSONObject representation) {
    if (!decorate) {
      return;
    }

    if (!"/users".equals(request.getServletPath())) return;

    try {
      addPluginLinks(request, resource, representation);

      JSONArray children = representation.optJSONArray("users");
      if (children != null) {
        for (int i = 0; i < children.length(); i++) {
          JSONObject child = children.getJSONObject(i);
          addPluginLinks(request, resource, child);
        }
      }
    } catch (Exception e) {
      // log and continue
      LogHelper.log(e);
    }
  }
コード例 #14
0
  public void start(BundleContext context) throws Exception {
    singleton = this;
    bundleContext = context;

    packageAdminTracker =
        new ServiceTracker<PackageAdmin, PackageAdmin>(context, PackageAdmin.class.getName(), null);
    packageAdminTracker.open();

    authServiceTracker = new AuthServiceTracker(context);
    authServiceTracker.open();

    IEclipsePreferences preferences =
        DefaultScope.INSTANCE.getNode(ServerConstants.PREFERENCE_SCOPE);
    Boolean httpsEnabled =
        new Boolean(preferences.get(ConfigurationFormat.HTTPS_ENABLED, "false")); // $NON-NLS-1$

    Dictionary<String, Object> properties = new Hashtable<String, Object>();
    properties.put(
        JettyConstants.CONTEXT_SESSIONINACTIVEINTERVAL, new Integer(4 * 60 * 60)); // 4 hours
    // properties.put(JettyConstants.CONTEXT_PATH, "/cc");
    if (httpsEnabled) {
      LogHelper.log(
          new Status(IStatus.INFO, PI_CONFIGURATOR, "Https is enabled", null)); // $NON-NLS-1$

      properties.put(JettyConstants.HTTPS_ENABLED, true);
      properties.put(
          JettyConstants.HTTPS_PORT,
          new Integer(
              preferences.get(
                  HTTPS_PORT,
                  System.getProperty(
                      "org.eclipse.equinox.http.jetty.https.port",
                      "8443")))); //$NON-NLS-1$//$NON-NLS-2$
      properties.put(
          JettyConstants.SSL_KEYSTORE, preferences.get(SSL_KEYSTORE, "keystore")); // $NON-NLS-1$

      LogHelper.log(
          new Status(
              IStatus.INFO,
              PI_CONFIGURATOR,
              "Keystore absolute path is "
                  + preferences.get(SSL_KEYSTORE, "keystore"))); // $NON-NLS-1$ //$NON-NLS-2$

      properties.put(
          JettyConstants.SSL_PASSWORD, preferences.get(SSL_PASSWORD, "password")); // $NON-NLS-1$
      properties.put(
          JettyConstants.SSL_KEYPASSWORD,
          preferences.get(SSL_KEYPASSWORD, "password")); // $NON-NLS-1$
      properties.put(
          JettyConstants.SSL_PROTOCOL, preferences.get(SSL_PROTOCOL, "SSLv3")); // $NON-NLS-1$

      String httpsHost =
          System.getProperty("org.eclipse.equinox.http.jetty.https.host"); // $NON-NLS-1$
      if (httpsHost != null) {
        properties.put(JettyConstants.HTTPS_HOST, httpsHost);
      }
    }

    String port = null;
    if (!httpsEnabled) {
      properties.put(JettyConstants.HTTP_ENABLED, true);
      port =
          preferences.get(
              HTTP_PORT,
              System.getProperty(
                  "org.eclipse.equinox.http.jetty.http.port", "8080")); // $NON-NLS-1$ //$NON-NLS-2$
      properties.put(JettyConstants.HTTP_PORT, new Integer(port));

      String httpHost =
          System.getProperty("org.eclipse.equinox.http.jetty.http.host"); // $NON-NLS-1$
      if (httpHost != null) {
        properties.put(JettyConstants.HTTP_HOST, httpHost);
      }
    }

    // properties to help us filter orion content
    properties.put("other.info", "org.eclipse.orion"); // $NON-NLS-1$ //$NON-NLS-2$

    try {
      JettyConfigurator.startServer("MasterJetty", properties); // $NON-NLS-1$
    } catch (Exception e) {
      throw new Exception("Error starting Jetty on port: " + port, e);
    }
  }