コード例 #1
0
  /**
   * Method called when user has finished updating a constraint.
   *
   * @param mapping The ActionMapping used to select this instance
   * @param form The optional ActionForm bean for this request (if any)
   * @param request The HTTP request we are processing
   * @param response The HTTP response we are creating
   * @return an ActionForward object defining where control goes next
   * @exception Exception if the application business logic throws an exception
   */
  @Override
  public ActionForward execute(
      ActionMapping mapping,
      ActionForm form,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {
    HttpSession session = request.getSession();
    final InterMineAPI im = SessionMethods.getInterMineAPI(session);
    ProfileManager pm = im.getProfileManager();
    String username = ((CreateAccountForm) form).getUsername();
    String password = ((CreateAccountForm) form).getPassword();
    pm.createNewProfile(username, password);
    Properties webProperties = SessionMethods.getWebProperties(session.getServletContext());
    try {
      MailUtils.email(username, webProperties);
      if (((CreateAccountForm) form).getMailinglist()
          && webProperties.getProperty("mail.mailing-list") != null
          && webProperties.getProperty("mail.mailing-list").length() > 0) {
        MailUtils.subscribe(username, webProperties);
      }
      SessionMethods.recordMessage(
          "You have successfully created an account, and logged in.", session);
    } catch (Exception e) {
      SessionMethods.recordError("Failed to send confirmation email", session);
    }

    /*
     * This code generates an MD5 key for the given username which is then
     * encoded in Hexadecimal. This could later be used for account
     * activation.
     *
     * try { MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[]
     * buffer = username.getBytes(); md5.update(buffer); byte[] array =
     * md5.digest(); String encoded = HexBin.encode(array); } catch
     * (NoSuchAlgorithmException e) { }
     */
    doLogin(request, username, password);
    return new ActionForward("/begin.do");
  }
コード例 #2
0
ファイル: Registrar.java プロジェクト: yeastgenome/intermine
  /**
   * Send a post request to the registry service, if one has been set up. As Registrar extends
   * Thread, the request will be executed in a separate Thread.
   */
  @Override
  public void run() {
    // Check to see whether we should run at all
    String registryAddress = props.getProperty("registration.address");
    if (registryAddress == null || registryAddress.isEmpty()) {
      LOG.info("No registry address supplied: " + "will not attempt to register.");
      return;
    }
    String authToken = props.getProperty("registration.authToken");
    if (authToken == null || authToken.isEmpty()) {
      LOG.info("No registration authentication supplied: " + "will not attempt to register.");
      return;
    }

    // Get the data to send to the server
    Map<String, String> params = new HashMap<String, String>();

    params.put("name", props.getProperty("project.title"));
    params.put("description", props.getProperty("project.subtitle"));
    params.put("authToken", authToken);
    params.put("format", "json");
    params.put("url", props.getProperty("webapp.baseurl") + "/" + props.getProperty("webapp.path"));
    populateParams(params);

    try {
      Thread.sleep(60000);
      URL registry = new URL(registryAddress);
      String data = getQueryString(params);

      // Send data
      URLConnection conn = registry.openConnection();
      conn.setDoOutput(true);
      Writer out = new OutputStreamWriter(conn.getOutputStream());
      out.write(data);
      out.flush();
      out.close();

      // Get the response
      BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String line;
      StringBuilder sb = new StringBuilder();
      while ((line = rd.readLine()) != null) {
        sb.append(line);
      }
      rd.close();

      String response = sb.toString();

      // Handle the response
      LOG.debug("Registration response: " + response);
      JSONObject jo = new JSONObject(response);
      String status = jo.getString("status");
      if (CREATED.equals(status)) {
        String receivedToken = jo.getString("authToken");
        if (!authToken.equals(receivedToken)) {
          handleProblem(
              "Mine registered incorrectly: "
                  + "authToken does not match the one supplied. "
                  + "I gave "
                  + authToken
                  + ", but got back "
                  + receivedToken);
        } else {
          LOG.info("Mine successfully registered");
        }
      } else if (UPDATED.equals(status)) {
        LOG.info("Mine registration details successfully updated");
      } else {
        handleProblem("Problem registering mine: " + jo.getString("text"));
      }

    } catch (InterruptedException e) {
      handleProblem("Registration was interrupted" + e);
    } catch (UnsupportedEncodingException e) {
      handleProblem("Could not encode query string for parameters: " + params);
    } catch (MalformedURLException e) {
      handleProblem("Could not connect to registry - bad address: " + registryAddress);
    } catch (JSONException e) {
      handleProblem("Problem registering mine - server returned bad response: " + e);
    } catch (IOException e) {
      handleProblem("Problem connecting to registry: " + e);
    } catch (Exception e) {
      handleProblem("Unanticipated problem encountered registering mine: " + e);
    }
    if (!emailContent.isEmpty()) {
      String feedbackEmail = props.getProperty("registration.emailto");
      if (feedbackEmail == null) {
        feedbackEmail = props.getProperty("superuser.account");
      }
      try {
        MailUtils.email(feedbackEmail, subject, emailIntro + emailContent, props);
      } catch (MessagingException e) {
        LOG.error("Problem emailing information about problems to " + feedbackEmail);
      }
    }
  }