private String getKey(OAuthParameters oauthParameters) {
   return (new StringBuilder())
       .append(OAuthUtil.encode(oauthParameters.getOAuthConsumerSecret()))
       .append("&")
       .append(OAuthUtil.encode(oauthParameters.getOAuthTokenSecret()))
       .toString();
 }
 @BeforeClass(
     alwaysRun = true,
     groups = {Constants.DashboardAPIChecker.DASHBOARD_TEST_CASES_GROUP})
 public void initTest() throws Exception {
   super.init(TestUserMode.SUPER_TENANT_ADMIN);
   String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPURL, backendHTTPSURL);
   this.client = new MDMHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
 }
 @BeforeClass(
     alwaysRun = true,
     groups = {Constants.LicenseManagement.LICENSE_MANAGEMENT_GROUP})
 public void initTest() throws Exception {
   super.init(TestUserMode.SUPER_TENANT_ADMIN);
   String accessTokenString =
       "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
   this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
 }
示例#4
0
  public static String toPostForm(HttpServletRequest req, HttpServletResponse res) {

    OAuthUtil.debugMessage("toPostForm: started");

    String action = OAuthUtil.findCookie(req, COOKIE_ORIG_URL);

    if (OAuthUtil.isEmpty(action)) {
      return getError("Request not valid !");
    }

    Map<String, String> params = req.getParameterMap();
    // if (params.size() != 1) {
    //    OAuthUtil.debugError("OAuthProxy.toPostForm: More or less "
    //            + "than 1 parameters in the request");
    //    return getError("Request not valid");
    // }

    if (!params.keySet().contains(PARAM_CODE) && !params.keySet().contains(PARAM_ACTIVATION)) {
      OAuthUtil.debugError(
          "OAuthProxy.toPostForm: Parameters "
              + PARAM_CODE
              + " or "
              + PARAM_ACTIVATION
              + " were not present in the request");
      return getError("Request not valid, perhaps a permission problem");
    }

    StringBuilder html = new StringBuilder();

    try {
      String onLoad = "document.postform.submit()";

      html.append("<html>\n").append("<body onLoad=\"").append(onLoad).append("\">\n");
      html.append("<form name=\"postform\" action=\"")
          .append(action)
          .append("\" method=\"post\">\n");

      String code = req.getParameter(PARAM_CODE);
      if (code != null && !OAuthUtil.isEmpty(code)) {
        if (ESAPI.validator().isValidInput(PARAM_CODE, code, "HTTPParameterValue", 512, true)) {
          html.append(input(PARAM_CODE, code));
        } else {
          OAuthUtil.debugError(
              "OAuthProxy.toPostForm: Parameter " + PARAM_CODE + " is not valid!! : " + code);
          return getError("Request not valid");
        }
      }

      String activation = req.getParameter(PARAM_ACTIVATION);
      if (activation != null && !OAuthUtil.isEmpty(activation)) {
        if (ESAPI
            .validator()
            .isValidInput(PARAM_ACTIVATION, activation, "HTTPParameterValue", 512, true)) {
          html.append(input(PARAM_ACTIVATION, activation));
        } else {
          OAuthUtil.debugError(
              "OAuthProxy.toPostForm: Parameter "
                  + PARAM_ACTIVATION
                  + " is not valid!! : "
                  + activation);
          return getError("Request not valid");
        }
      }

    } catch (Exception e) {
      return getError(e.getMessage());
    }

    html.append("<noscript>\n<center>\n");
    html.append(
        "<p>Your browser does not have JavaScript enabled, you must click"
            + " the button below to continue</p>\n");
    html.append("<input type=\"submit\" value=\"submit\" />\n");
    html.append("</center>\n</noscript>\n");
    html.append("</form>\n").append("</body>\n").append("</html>\n");

    OAuthUtil.debugMessage("OAuthProxy.toPostForm: form html:\n" + html);

    return html.toString();
  }