public FormValidation doCheckUsername(@QueryParameter String username) {
   if (Strings.isNullOrEmpty(username)) {
     return FormValidation.error("Must be set");
   } else {
     return FormValidation.ok();
   }
 }
  public FormValidation validate() throws IOException {

    HttpClient hc = createClient();

    PostMethod post = new PostMethod(url + "Login");
    post.addParameter("userName", getUsername());

    if (getPassword() != null) {
      //          post.addParameter("password",getPassword());
      post.addParameter("password", getPassword().getPlainText());
    } else {
      post.addParameter("password", "");
    }

    hc.executeMethod(post);

    // if the login succeeds, we'll see a redirect
    Header loc = post.getResponseHeader("Location");
    if (loc != null && loc.getValue().endsWith("/Central")) return FormValidation.ok("Success!");

    if (!post.getResponseBodyAsString().contains("SOASTA"))
      return FormValidation.error(getUrl() + " doesn't look like a CloudTest server");

    // if it fails, the server responds with 200!
    return FormValidation.error("Invalid credentials.");
  }
 public FormValidation doCheckPassword(@QueryParameter String value) {
   if (value == null || value.trim().isEmpty()) {
     return FormValidation.error("Required.");
   } else {
     return FormValidation.ok();
   }
 }
    /**
     * For test Server Address if it available
     *
     * @param value String from Server Address form
     * @return OK if ping, ERROR otherwise
     */
    public FormValidation doCheckServerAddress(@QueryParameter String value) {

      try {

        if (value == null || value.matches("\\s*")) {
          return FormValidation.warning("Set Address");
        }

        if (value.startsWith("$")) {
          return FormValidation.ok();
        }

        new Socket(value, 22).close();

      } catch (UnknownHostException e) {
        return FormValidation.error("Unknown Host\t" + value + "\t" + e.getLocalizedMessage());
      } catch (IOException e) {
        return FormValidation.error(
            "Input Output Exception while connecting to \t"
                + value
                + "\t"
                + e.getLocalizedMessage());
      }
      return FormValidation.ok();
    }
  /**
   * @param res
   * @param rsp
   * @param regex
   * @return FormValidation.Kind.OK if the regex is valid, FormValidation.Kind.WARNING if the regex
   *     is valid but consists only of whitespaces or has leading and/or trailing whitespaces, and
   *     FormValidation.Kind.ERROR if the regex syntax is invalid.
   */
  public FormValidation doCheckExcludedFilesRegex(
      final StaplerRequest res,
      final StaplerResponse rsp,
      @QueryParameter("value") final String regex) {

    if ((regex == null) || (regex.isEmpty())) {
      return FormValidation.ok();
    }

    try {
      Pattern.compile(regex);
    } catch (final PatternSyntaxException pse) {
      return FormValidation.error("Regex syntax is invalid.");
    }

    if (regex.trim().isEmpty()) {
      return FormValidation.warning(
          "Regex is valid, but consists entirely of whitespaces - is this intentional?");
    }

    if (!regex.trim().equals(regex)) {
      return FormValidation.warning(
          "Regex is valid, but contains leading and/or trailing whitespaces - is this intentional?");
    }

    return FormValidation.ok();
  }
Exemple #6
0
    public FormValidation doCheckUrl(
        @AncestorInPath Item project,
        @QueryParameter String credentialsId,
        @QueryParameter String value)
        throws IOException, InterruptedException {

      if (project == null || !project.hasPermission(Item.CONFIGURE)) {
        return FormValidation.ok();
      }

      String url = Util.fixEmptyAndTrim(value);
      if (url == null) return FormValidation.error("Please enter repository url.");

      // get git executable on master
      final EnvVars environment = new EnvVars(EnvVars.masterEnvVars);

      GitClient git =
          Git.with(TaskListener.NULL, environment)
              .using(GitTool.getDefaultInstallation().getGitExe())
              .getClient();
      if (credentialsId != null) {
        StandardCredentials credentials = lookupCredentials(project, credentialsId, url);
        if (credentials != null) git.addDefaultCredentials(credentials);
      }

      // attempt to connect the provided URL
      try {
        git.getHeadRev(url, "HEAD");
      } catch (GitException e) {
        return FormValidation.error(Messages.UserRemoteConfig_FailedToConnect(e.getMessage()));
      }

      return FormValidation.ok();
    }
 public FormValidation doCheckWorkspacePath(@QueryParameter String workspacePath) {
   if (Strings.isNullOrEmpty(workspacePath)) {
     return FormValidation.error("Must be set");
   } else {
     return FormValidation.ok();
   }
 }
 public FormValidation doTestConnection(
     @QueryParameter("slackTeamDomain") final String teamDomain,
     @QueryParameter("slackToken") final String authToken,
     @QueryParameter("slackRoom") final String room,
     @QueryParameter("slackBuildServerUrl") final String buildServerUrl)
     throws FormException {
   try {
     String targetDomain = teamDomain;
     if (StringUtils.isEmpty(targetDomain)) {
       targetDomain = this.teamDomain;
     }
     String targetToken = authToken;
     if (StringUtils.isEmpty(targetToken)) {
       targetToken = this.token;
     }
     String targetRoom = room;
     if (StringUtils.isEmpty(targetRoom)) {
       targetRoom = this.room;
     }
     String targetBuildServerUrl = buildServerUrl;
     if (StringUtils.isEmpty(targetBuildServerUrl)) {
       targetBuildServerUrl = this.buildServerUrl;
     }
     SlackService testSlackService = getSlackService(targetDomain, targetToken, targetRoom);
     String message = "Slack/Jenkins plugin: you're all set on " + targetBuildServerUrl;
     boolean success = testSlackService.publish(message, "good");
     return success ? FormValidation.ok("Success") : FormValidation.error("Failure");
   } catch (Exception e) {
     return FormValidation.error("Client error : " + e.getMessage());
   }
 }
    public FormValidation doVerifyConfiguration(
        @QueryParameter String subscriptionId,
        @QueryParameter String serviceManagementCert,
        @QueryParameter String passPhrase,
        @QueryParameter String serviceManagementURL) {

      if (AzureUtil.isNull(subscriptionId)) {
        return FormValidation.error("Error: Subscription ID is missing");
      }

      if (AzureUtil.isNull(serviceManagementCert)) {
        return FormValidation.error("Error: Management service certificate is missing");
      }

      if (AzureUtil.isNull(serviceManagementURL)) {
        serviceManagementURL = Constants.DEFAULT_MANAGEMENT_URL;
      }

      String response =
          AzureManagementServiceDelegate.verifyConfiguration(
              subscriptionId, serviceManagementCert, passPhrase, serviceManagementURL);

      if (response.equalsIgnoreCase("Success")) {
        return FormValidation.ok(Messages.Azure_Config_Success());
      } else {
        return FormValidation.error(response);
      }
    }
 /**
  * Check method to validate the authentication details
  *
  * @param request the {@link StaplerRequest}
  * @return the {@link FormValidation} result
  * @throws IOException in case of IO exceptions
  */
 public FormValidation doLoginCheck(StaplerRequest request) throws IOException {
   String url = Util.fixEmpty(request.getParameter("url"));
   if (url == null) {
     return FormValidation.ok();
   }
   JIRASite site =
       new JIRASite(
           "Login Check",
           new URL(url),
           request.getParameter("user"),
           request.getParameter("pass"),
           false,
           null,
           false);
   try {
     site.createClient();
     return FormValidation.ok();
   } catch (RemoteAuthenticationException e) {
     return FormValidation.error(e.getMessage());
   } catch (AxisFault e) {
     return FormValidation.error(e.getFaultString());
   } catch (ServiceException e) {
     return FormValidation.error(e.getMessage());
   }
 }
 public FormValidation doValidate(
     @QueryParameter String username,
     @QueryParameter String apiKey,
     @QueryParameter boolean disableStatusColumn,
     @QueryParameter boolean reuseSauceAuth) {
   try {
     SauceOnDemandAuthentication credential =
         reuseSauceAuth
             ? new SauceOnDemandAuthentication()
             : new SauceOnDemandAuthentication(
                 username, Secret.toString(Secret.fromString(apiKey)));
     // we aren't interested in the results of the REST API call - just the fact that we executed
     // without an error is enough to verify the connection
     if (reuseSauceAuth
         && StringUtils.isBlank(credential.getUsername())
         && StringUtils.isBlank(credential.getAccessKey())) {
       return FormValidation.error("Unable to find ~/.sauce-ondemand file");
     } else {
       String response =
           new SauceREST(credential.getUsername(), credential.getAccessKey())
               .retrieveResults("tunnels");
       if (response != null && !response.equals("")) {
         return FormValidation.ok("Success");
       } else {
         return FormValidation.error("Failed to connect to Sauce OnDemand");
       }
     }
   } catch (Exception e) {
     return FormValidation.error(e, "Failed to connect to Sauce OnDemand");
   }
 }
 /*
  * --- Validation methods ---
  */
 public FormValidation doCheckMandatory(@QueryParameter String value) {
   FormValidation returnValue = FormValidation.ok();
   if (StringUtils.isBlank(value)) {
     returnValue = FormValidation.error("Required value.");
   }
   return returnValue;
 }
Exemple #13
0
    protected FormValidation doTestConnection(
        URL ec2endpoint,
        boolean useInstanceProfileForCredentials,
        String accessId,
        String secretKey,
        String privateKey)
        throws IOException, ServletException {
      try {
        AWSCredentialsProvider credentialsProvider =
            createCredentialsProvider(useInstanceProfileForCredentials, accessId, secretKey);
        AmazonEC2 ec2 = connect(credentialsProvider, ec2endpoint);
        ec2.describeInstances();

        if (privateKey == null)
          return FormValidation.error(
              "Private key is not specified. Click 'Generate Key' to generate one.");

        if (privateKey.trim().length() > 0) {
          // check if this key exists
          EC2PrivateKey pk = new EC2PrivateKey(privateKey);
          if (pk.find(ec2) == null)
            return FormValidation.error(
                "The EC2 key pair private key isn't registered to this EC2 region (fingerprint is "
                    + pk.getFingerprint()
                    + ")");
        }

        return FormValidation.ok(Messages.EC2Cloud_Success());
      } catch (AmazonClientException e) {
        LOGGER.log(Level.WARNING, "Failed to check EC2 credential", e);
        return FormValidation.error(e.getMessage());
      }
    }
 public FormValidation doCheckRequired(@QueryParameter String value) {
   value = StringUtils.strip(value);
   if (value == null || value.equals("")) {
     return FormValidation.error("This field is required.");
   }
   return FormValidation.ok();
 }
    public FormValidation doCheckMemorySize(@QueryParameter String value)
        throws IOException, ServletException {

      if (value.length() == 0)
        return FormValidation.error(Messages.validation_required("Memory Size"));
      return FormValidation.ok();
    }
    public FormValidation doCheckWorkflowName(
        @QueryParameter final String serverUrl,
        @QueryParameter final String userName,
        @QueryParameter final String password,
        @QueryParameter final String tenant,
        @QueryParameter final String workflowName)
        throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException, IOException,
            URISyntaxException {

      String workflowNameValue = Util.fixEmptyAndTrim(workflowName);
      if (workflowNameValue == null) {
        return FormValidation.error("Please enter workflow name.");
      }

      if (workflowNameValue.indexOf('$') >= 0) {
        // set by variable, can't validate
        return FormValidation.ok();
      }
      // Call server and validate
      BuildParam buildParam = new BuildParam(serverUrl, userName, password, tenant, null);
      OrchestratorClient client = new OrchestratorClient(buildParam);
      List<Workflow> workflows = client.fetchWorkflows();

      boolean isWorkflowFound = false;
      for (Workflow workflow : workflows) {
        if (workflow.getName().equals(workflowName)) {
          isWorkflowFound = true;
        }
      }
      if (!isWorkflowFound) {
        return FormValidation.error("Workflow with the given name doesn't exist in the server.");
      }
      return FormValidation.ok();
    }
 public FormValidation doCheckReposUrl(@QueryParameter String value) {
   FormValidation result;
   final Matcher matcher = URL_PATTERN.matcher(value);
   if (matcher.matches()) {
     try {
       final URL repUrl = new URL(matcher.group(URL_PATTERN_BASE_URL_GROUP));
       final String repName = matcher.group(URL_PATTERN_REPNAME_GROUP);
       if (repName == null || "".equals(repName)) { // Go online??
         result =
             FormValidation.okWithMarkup(
                 "Please set a url including the repname property if needed.");
       } else {
         result = FormValidation.ok();
       }
     } catch (MalformedURLException ex) {
       result =
           FormValidation.error("The entered url is not accepted: " + ex.getLocalizedMessage());
     }
   } else if ("".equals(value)) {
     result =
         FormValidation.okWithMarkup(
             "Please set a WebSVN url in the form "
                 + "https://<i>server</i>/websvn/listing.php?repname=<i>rep</i>&path=/trunk/..");
   } else {
     result = FormValidation.error("Please set a url including the WebSVN php script.");
   }
   return result;
 }
Exemple #18
0
 public FormValidation doCheckValue(@QueryParameter String value)
     throws IOException, ServletException {
   if (value.isEmpty()) {
     return FormValidation.warning("You must fill this box!");
   }
   return FormValidation.ok();
 }
    /** Performs on-the-fly validation of the URL. */
    public FormValidation doCheckUrl(@QueryParameter(fixEmpty = true) String value)
        throws IOException, ServletException {
      if (value == null) // nothing entered yet
      return FormValidation.ok();

      if (!value.endsWith("/")) value += '/';
      if (!URL_PATTERN.matcher(value).matches())
        return FormValidation.errorWithMarkup(
            "The URL should end like <tt>.../browse/foobar/</tt>");

      // Connect to URL and check content only if we have admin permission
      if (!Hudson.getInstance().hasPermission(Hudson.ADMINISTER)) return FormValidation.ok();

      final String finalValue = value;
      return new URLCheck() {
        @Override
        protected FormValidation check() throws IOException, ServletException {
          try {
            if (findText(open(new URL(finalValue)), "FishEye")) {
              return FormValidation.ok();
            }
            return FormValidation.error("This is a valid URL but it doesn't look like FishEye");
          } catch (IOException e) {
            return handleIOException(finalValue, e);
          }
        }
      }.check();
    }
Exemple #20
0
    public FormValidation doTestConnection(
        @QueryParameter("hygieiaAPIUrl") final String hygieiaAPIUrl,
        @QueryParameter("hygieiaToken") final String hygieiaToken,
        @QueryParameter("hygieiaJenkinsName") final String hygieiaJenkinsName,
        @QueryParameter("useProxy") final String sUseProxy)
        throws FormException {

      String hostUrl = hygieiaAPIUrl;
      if (StringUtils.isEmpty(hostUrl)) {
        hostUrl = this.hygieiaAPIUrl;
      }
      String targetToken = hygieiaToken;
      if (StringUtils.isEmpty(targetToken)) {
        targetToken = this.hygieiaToken;
      }
      String name = hygieiaJenkinsName;
      if (StringUtils.isEmpty(name)) {
        name = this.hygieiaJenkinsName;
      }
      boolean bProxy = "true".equalsIgnoreCase(sUseProxy);
      if (StringUtils.isEmpty(sUseProxy)) {
        bProxy = this.useProxy;
      }
      HygieiaService testHygieiaService = getHygieiaService(hostUrl, targetToken, name, bProxy);
      if (testHygieiaService != null) {
        boolean success = testHygieiaService.testConnection();
        return success ? FormValidation.ok("Success") : FormValidation.error("Failure");
      } else {
        return FormValidation.error("Failure");
      }
    }
 public static FormValidation validateWarnIfEmpty(
     final String fieldValue, final String displayName) {
   if (StringUtils.trimToNull(fieldValue) == null) {
     return FormValidation.warning("Don't forget to include the " + displayName + ".");
   }
   return FormValidation.ok();
 }
    public FormValidation doCheckWorkflowActionName(@QueryParameter String value) {
      if (Util.fixNull(value).trim().length() == 0) {
        return FormValidation.warning(Messages.JiraIssueUpdateBuilder_NoWorkflowAction());
      }

      return FormValidation.ok();
    }
 public FormValidation doCheckLucenePath(@QueryParameter final String lucenePath) {
   try {
     new File(lucenePath);
     return FormValidation.ok();
   } catch (RuntimeException e) {
     return FormValidation.error(e.getMessage());
   }
 }
    private FormValidation checkFieldNotEmpty(String value, String field) {
      value = StringUtils.strip(value);

      if (value == null || value.equals("")) {
        return FormValidation.error(field + " is required.");
      }
      return FormValidation.ok();
    }
 public FormValidation doCheckUrl(@QueryParameter(value = "url", fixEmpty = true) String url) {
   try {
     new URL(url);
   } catch (MalformedURLException e) {
     return FormValidation.error(e.getMessage());
   }
   return FormValidation.ok();
 }
Exemple #26
0
 public FormValidation doCheckAccessId(@QueryParameter String value)
     throws IOException, ServletException {
   if (value.trim().length() != 20) {
     return FormValidation.error(Messages.EC2Cloud_InvalidAccessId());
   }
   return FormValidation.validateBase64(
       value, false, false, Messages.EC2Cloud_InvalidAccessId());
 }
 public FormValidation doCheckProjects(@QueryParameter String value) {
   String v = fixEmpty(value);
   if (v == null) {
     return FormValidation.error("No project specified");
   } else {
     return FormValidation.ok();
   }
 }
    /**
     * Performs on-the-fly validation of the form field 'Jql'.
     *
     * @param value This parameter receives the value that the user has typed.
     * @return Indicates the outcome of the validation. This is sent to the browser.
     */
    public FormValidation doCheckJqlSearch(@QueryParameter String value)
        throws IOException, ServletException {
      if (value.length() == 0) {
        return FormValidation.error(Messages.JiraIssueUpdateBuilder_NoJqlSearch());
      }

      return FormValidation.ok();
    }
 public FormValidation doCheckWspFilter(@QueryParameter String value) {
   try {
     WspFilter.parseSimpleSpec(value);
     return FormValidation.ok();
   } catch (RuntimeException e) {
     return FormValidation.error(e.getMessage());
   }
 }
Exemple #30
0
 /** Checks if the value is a valid CVS tag name. */
 public synchronized FormValidation doCheckTag(@QueryParameter String value) {
   String tag = fixNull(value).trim();
   if (tag.length() == 0) // nothing entered yet
   {
     return FormValidation.ok();
   }
   return FormValidation.error(isInvalidTag(tag));
 }