예제 #1
0
 /**
  * Copy constructor.
  *
  * @param config the Config object to be copied.
  */
 public Config(IGerritHudsonTriggerConfig config) {
   gerritHostName = config.getGerritHostName();
   gerritSshPort = config.getGerritSshPort();
   gerritProxy = config.getGerritProxy();
   gerritUserName = config.getGerritUserName();
   gerritEMail = config.getGerritEMail();
   notificationLevel = config.getNotificationLevel();
   gerritAuthKeyFile = new File(config.getGerritAuthKeyFile().getPath());
   gerritAuthKeyFilePassword = Secret.fromString(config.getGerritAuthKeyFilePassword());
   useRestApi = config.isUseRestApi();
   gerritHttpUserName = config.getGerritHttpUserName();
   gerritHttpPassword = Secret.fromString(config.getGerritHttpPassword());
   restCodeReview = config.isRestCodeReview();
   restVerified = config.isRestVerified();
   gerritBuildCurrentPatchesOnly = config.isGerritBuildCurrentPatchesOnly();
   numberOfWorkerThreads = config.getNumberOfReceivingWorkerThreads();
   numberOfSendingWorkerThreads = config.getNumberOfSendingWorkerThreads();
   gerritBuildStartedVerifiedValue = config.getGerritBuildStartedVerifiedValue();
   gerritBuildStartedCodeReviewValue = config.getGerritBuildStartedCodeReviewValue();
   gerritBuildSuccessfulVerifiedValue = config.getGerritBuildSuccessfulVerifiedValue();
   gerritBuildSuccessfulCodeReviewValue = config.getGerritBuildSuccessfulCodeReviewValue();
   gerritBuildFailedVerifiedValue = config.getGerritBuildFailedVerifiedValue();
   gerritBuildFailedCodeReviewValue = config.getGerritBuildFailedCodeReviewValue();
   gerritBuildUnstableVerifiedValue = config.getGerritBuildUnstableVerifiedValue();
   gerritBuildUnstableCodeReviewValue = config.getGerritBuildUnstableCodeReviewValue();
   gerritBuildNotBuiltVerifiedValue = config.getGerritBuildNotBuiltVerifiedValue();
   gerritBuildNotBuiltCodeReviewValue = config.getGerritBuildNotBuiltCodeReviewValue();
   gerritVerifiedCmdBuildStarted = config.getGerritCmdBuildStarted();
   gerritVerifiedCmdBuildFailed = config.getGerritCmdBuildFailed();
   gerritVerifiedCmdBuildSuccessful = config.getGerritCmdBuildSuccessful();
   gerritVerifiedCmdBuildUnstable = config.getGerritCmdBuildUnstable();
   gerritVerifiedCmdBuildNotBuilt = config.getGerritCmdBuildNotBuilt();
   gerritFrontEndUrl = config.getGerritFrontEndUrl();
   enableManualTrigger = config.isEnableManualTrigger();
   enablePluginMessages = config.isEnablePluginMessages();
   buildScheduleDelay = config.getBuildScheduleDelay();
   dynamicConfigRefreshInterval = config.getDynamicConfigRefreshInterval();
   enableProjectAutoCompletion = config.isEnableProjectAutoCompletion();
   projectListFetchDelay = config.getProjectListFetchDelay();
   projectListRefreshInterval = config.getProjectListRefreshInterval();
   if (config.getCategories() != null) {
     categories = new LinkedList<VerdictCategory>();
     for (VerdictCategory cat : config.getCategories()) {
       categories.add(new VerdictCategory(cat.getVerdictValue(), cat.getVerdictDescription()));
     }
   }
   if (config.getReplicationConfig() != null) {
     replicationConfig = new ReplicationConfig(config.getReplicationConfig());
   }
   watchdogTimeoutMinutes = config.getWatchdogTimeoutMinutes();
   watchTimeExceptionData = addWatchTimeExceptionData(config.getExceptionData());
 }
예제 #2
0
 public static AWSCredentialsProvider createCredentialsProvider(
     final boolean useInstanceProfileForCredentials,
     final String accessId,
     final String secretKey) {
   return createCredentialsProvider(
       useInstanceProfileForCredentials, accessId.trim(), Secret.fromString(secretKey.trim()));
 }
예제 #3
0
  protected EC2Cloud(
      String id,
      boolean useInstanceProfileForCredentials,
      String accessId,
      String secretKey,
      String privateKey,
      String instanceCapStr,
      List<? extends SlaveTemplate> templates) {
    super(id);
    this.useInstanceProfileForCredentials = useInstanceProfileForCredentials;
    this.accessId = accessId.trim();
    this.secretKey = Secret.fromString(secretKey.trim());
    this.privateKey = new EC2PrivateKey(privateKey);

    if (templates == null) {
      this.templates = Collections.emptyList();
    } else {
      this.templates = templates;
    }

    if (instanceCapStr.equals("")) {
      this.instanceCap = Integer.MAX_VALUE;
    } else {
      this.instanceCap = Integer.parseInt(instanceCapStr);
    }

    readResolve(); // set parents
  }
예제 #4
0
파일: Mailer.java 프로젝트: pfeuffer/hudson
    @Override
    public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
      // this code is brain dead
      smtpHost = nullify(json.getString("smtpServer"));
      setAdminAddress(json.getString("adminAddress"));

      defaultSuffix = nullify(json.getString("defaultSuffix"));
      String url = nullify(json.getString("url"));
      if (url != null && !url.endsWith("/")) url += '/';
      hudsonUrl = url;

      if (json.has("useSMTPAuth")) {
        JSONObject auth = json.getJSONObject("useSMTPAuth");
        smtpAuthUsername = nullify(auth.getString("smtpAuthUserName"));
        smtpAuthPassword = Secret.fromString(nullify(auth.getString("smtpAuthPassword")));
      } else {
        smtpAuthUsername = null;
        smtpAuthPassword = null;
      }
      smtpPort = nullify(json.getString("smtpPort"));
      useSsl = json.getBoolean("useSsl");
      charset = json.getString("charset");
      if (charset == null || charset.length() == 0) charset = "UTF-8";

      save();
      return true;
    }
 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");
   }
 }
 public void stagingRepository(
     String repository, String user, String password, boolean skipDeletion) {
   this.stagingRepository = repository;
   this.stagingUser = user;
   this.stagingPassword = Secret.fromString(password);
   this.skipDeletion = skipDeletion;
 }
예제 #7
0
 public FormValidation doValidate(
     @QueryParameter String url,
     @QueryParameter String username,
     @QueryParameter String password,
     @QueryParameter String id,
     @QueryParameter String name)
     throws IOException {
   return new Composition(name, url, username, Secret.fromString(password), id).validate();
 }
 @Override
 public void configure(StaplerRequest req, JSONObject formData)
     throws IOException, ServletException, Descriptor.FormException {
   reuseSauceAuth = formData.getBoolean("reuseSauceAuth");
   disableStatusColumn = formData.getBoolean("disableStatusColumn");
   username = formData.getString("username");
   apiKey = Secret.fromString(formData.getString("apiKey"));
   sauceConnectDirectory = formData.getString("sauceConnectDirectory");
   save();
 }
    @Override
    public boolean configure(StaplerRequest req, JSONObject formData) throws FormException {

      // to persist global configuration information,
      // set that to properties and call save().
      stashUser = formData.getString("stashUser");
      stashPassword = Secret.fromString(formData.getString("stashPassword"));
      stashRootUrl = formData.getString("stashRootUrl");
      ignoreUnverifiedSsl = formData.getBoolean("ignoreUnverifiedSsl");
      includeBuildNumberInKey = formData.getBoolean("includeBuildNumberInKey");
      save();
      return super.configure(req, formData);
    }
예제 #10
0
 public void put(String url) throws IOException {
   DBObject token = getToken(url);
   GithubAuthenticationToken auth =
       (GithubAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
   GitHub gh = auth.getGitHub();
   if (token != null) {
     delete(token);
   }
   String accessToken = Secret.fromString(auth.getAccessToken()).getEncryptedValue();
   BasicDBObject doc =
       new BasicDBObject("user", gh.getMyself().getLogin())
           .append("access_token", accessToken)
           .append("repo_url", url);
   save(doc);
 }
 /**
  * Constructor SSHLauncher creates a new SSHLauncher instance.
  *
  * @param port The port to connect on.
  * @param username The username to connect as.
  * @param password The password to connect with.
  * @param privatekey The ssh privatekey to connect with.
  * @param jvmOptions jvm options.
  * @param javaPath optional path to java.
  */
 @DataBoundConstructor
 public SSHConnector(
     int port,
     String username,
     String password,
     String privatekey,
     String jvmOptions,
     String javaPath) {
   this.jvmOptions = jvmOptions;
   this.port = port == 0 ? 22 : port;
   this.username = username;
   this.password = Secret.fromString(fixEmpty(password));
   this.privatekey = privatekey;
   this.javaPath = javaPath;
 }
  @DataBoundConstructor
  public ActiveDirectorySecurityRealm(
      String domain, String site, String bindName, String bindPassword, String server) {
    this.domain = fixEmpty(domain);
    this.site = fixEmpty(site);
    this.bindName = fixEmpty(bindName);
    this.bindPassword = Secret.fromString(fixEmpty(bindPassword));

    // append default port if not specified
    server = fixEmpty(server);
    if (server != null) {
      if (!server.contains(":")) server += ":3268";
    }

    this.server = server;
  }
 @Before
 public void setup() throws IOException {
   for (CredentialsStore credentialsStore :
       CredentialsProvider.lookupStores(Jenkins.getInstance())) {
     if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
       List<Domain> domains = credentialsStore.getDomains();
       credentialsStore.addCredentials(
           domains.get(0),
           new StringCredentialsImpl(
               CredentialsScope.SYSTEM,
               API_TOKEN_ID,
               "GitLab API Token",
               Secret.fromString(API_TOKEN_ID)));
     }
   }
 }
 @DataBoundConstructor
 public StashNotifier(
     String stashServerBaseUrl,
     String stashUserName,
     String stashUserPassword,
     boolean ignoreUnverifiedSSLPeer,
     String commitSha1,
     boolean includeBuildNumberInKey) {
   this.stashServerBaseUrl =
       stashServerBaseUrl.endsWith("/")
           ? stashServerBaseUrl.substring(0, stashServerBaseUrl.length() - 1)
           : stashServerBaseUrl;
   this.stashUserName = stashUserName;
   this.stashUserPassword = Secret.fromString(stashUserPassword);
   this.ignoreUnverifiedSSLPeer = ignoreUnverifiedSSLPeer;
   this.commitSha1 = commitSha1;
   this.includeBuildNumberInKey = includeBuildNumberInKey;
 }
예제 #15
0
파일: Mailer.java 프로젝트: pfeuffer/hudson
    /**
     * Send an email to the admin address
     *
     * @throws IOException
     * @throws ServletException
     * @throws InterruptedException
     */
    public FormValidation doSendTestMail(
        @QueryParameter String smtpServer,
        @QueryParameter String adminAddress,
        @QueryParameter boolean useSMTPAuth,
        @QueryParameter String smtpAuthUserName,
        @QueryParameter String smtpAuthPassword,
        @QueryParameter boolean useSsl,
        @QueryParameter String smtpPort)
        throws IOException, ServletException, InterruptedException {
      try {
        if (!useSMTPAuth) smtpAuthUserName = smtpAuthPassword = null;

        MimeMessage msg =
            new MimeMessage(
                createSession(
                    smtpServer,
                    smtpPort,
                    useSsl,
                    smtpAuthUserName,
                    Secret.fromString(smtpAuthPassword)));
        msg.setSubject("Test email #" + ++testEmailCount);
        msg.setContent(
            "This is test email #"
                + testEmailCount
                + " sent from Hudson Continuous Integration server.",
            "text/plain");
        msg.setFrom(new InternetAddress(adminAddress));
        msg.setSentDate(new Date());
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(adminAddress));

        Transport.send(msg);

        return FormValidation.ok("Email was successfully sent");
      } catch (MessagingException e) {
        return FormValidation.errorWithMarkup(
            "<p>Failed to send out e-mail</p><pre>"
                + Util.escape(Functions.printThrowable(e))
                + "</pre>");
      }
    }
예제 #16
0
    @Override
    public void decorateHome(final JenkinsRule jenkinsRule, final File home) throws Exception {
      final String jobFolder = parent.getJobFolder();
      final String configXmlPath = jobFolder + "config.xml";
      final File configXmlFile = new File(home, configXmlPath);

      final String tfsServerUrl = helper.getServerUrl();
      XmlHelper.pokeValue(configXmlFile, "/project/scm/serverUrl", tfsServerUrl);

      final String projectPath = parent.getPathInTfvc();
      XmlHelper.pokeValue(configXmlFile, "/project/scm/projectPath", projectPath);

      final String workspaceName = "Hudson-${JOB_NAME}-${COMPUTERNAME}";
      XmlHelper.pokeValue(configXmlFile, "/project/scm/workspaceName", workspaceName);

      final String userName = helper.getUserName();
      XmlHelper.pokeValue(configXmlFile, "/project/scm/userName", userName);

      final String userPassword = helper.getUserPassword();
      final SecretOverride secretOverride = new SecretOverride();
      try {
        final Secret secret = Secret.fromString(userPassword);
        encryptedPassword = secret.getEncryptedValue();
      } finally {
        try {
          secretOverride.close();
        } catch (IOException e) {
          // ignore
        }
      }
      final String projectScmPassword = "******";
      final String currentPassword = XmlHelper.peekValue(configXmlFile, projectScmPassword);
      if (currentPassword != null) {
        XmlHelper.pokeValue(configXmlFile, projectScmPassword, encryptedPassword);
      }
    }
 @DataBoundConstructor
 public PasswordParameterValue(String name, String value, String description) {
   super(name, description);
   this.value = Secret.fromString(value);
 }
예제 #18
0
 /**
  * Sets gerritHttpPassword.
  *
  * @param gerritHttpPassword the password
  * @see #getGerritHttpPassword()
  */
 public void setGerritHttpPassword(String gerritHttpPassword) {
   this.gerritHttpPassword = Secret.fromString(gerritHttpPassword);
 }
예제 #19
0
 /**
  * GerritAuthKeyFilePassword.
  *
  * @param gerritAuthKeyFilePassword the password
  * @see #getGerritAuthKeyFilePassword()
  */
 public void setGerritAuthKeyFilePassword(String gerritAuthKeyFilePassword) {
   this.gerritAuthKeyFilePassword = Secret.fromString(gerritAuthKeyFilePassword);
 }
예제 #20
0
  @Override
  public void setValues(JSONObject formData) {
    gerritHostName = formData.optString("gerritHostName", DEFAULT_GERRIT_HOSTNAME);
    gerritSshPort = formData.optInt("gerritSshPort", DEFAULT_GERRIT_SSH_PORT);
    gerritProxy = formData.optString("gerritProxy", DEFAULT_GERRIT_PROXY);
    gerritUserName = formData.optString("gerritUserName", DEFAULT_GERRIT_USERNAME);
    gerritEMail = formData.optString("gerritEMail", "");
    notificationLevel =
        Notify.valueOf(
            formData.optString("notificationLevel", Config.DEFAULT_NOTIFICATION_LEVEL.toString()));
    String file = formData.optString("gerritAuthKeyFile", null);
    if (file != null) {
      gerritAuthKeyFile = new File(file);
    } else {
      gerritAuthKeyFile = DEFAULT_GERRIT_AUTH_KEY_FILE;
    }
    gerritAuthKeyFilePassword =
        Secret.fromString(
            formData.optString("gerritAuthKeyFilePassword", DEFAULT_GERRIT_AUTH_KEY_FILE_PASSWORD));

    if (formData.has("buildCurrentPatchesOnly")) {
      JSONObject currentPatchesOnly = formData.getJSONObject("buildCurrentPatchesOnly");
      buildCurrentPatchesOnly = BuildCancellationPolicy.createPolicyFromJSON(currentPatchesOnly);
    } else {
      buildCurrentPatchesOnly = new BuildCancellationPolicy();
    }

    numberOfWorkerThreads =
        formData.optInt("numberOfReceivingWorkerThreads", DEFAULT_NR_OF_RECEIVING_WORKER_THREADS);
    if (numberOfWorkerThreads <= 0) {
      numberOfWorkerThreads = DEFAULT_NR_OF_RECEIVING_WORKER_THREADS;
    }
    numberOfSendingWorkerThreads =
        formData.optInt("numberOfSendingWorkerThreads", DEFAULT_NR_OF_SENDING_WORKER_THREADS);
    if (numberOfSendingWorkerThreads <= 0) {
      numberOfSendingWorkerThreads = DEFAULT_NR_OF_SENDING_WORKER_THREADS;
    }

    if (formData.isEmpty()) {
      gerritBuildStartedVerifiedValue = DEFAULT_GERRIT_BUILD_STARTED_VERIFIED_VALUE;
      gerritBuildSuccessfulVerifiedValue = DEFAULT_GERRIT_BUILD_SUCCESSFUL_VERIFIED_VALUE;
      gerritBuildFailedVerifiedValue = DEFAULT_GERRIT_BUILD_FAILURE_VERIFIED_VALUE;
      gerritBuildUnstableVerifiedValue = DEFAULT_GERRIT_BUILD_UNSTABLE_VERIFIED_VALUE;
      gerritBuildNotBuiltVerifiedValue = DEFAULT_GERRIT_BUILD_NOT_BUILT_VERIFIED_VALUE;
      gerritBuildStartedCodeReviewValue = DEFAULT_GERRIT_BUILD_STARTED_CODE_REVIEW_VALUE;
      gerritBuildSuccessfulCodeReviewValue = DEFAULT_GERRIT_BUILD_SUCCESSFUL_CODE_REVIEW_VALUE;
      gerritBuildFailedCodeReviewValue = DEFAULT_GERRIT_BUILD_FAILURE_CODE_REVIEW_VALUE;
      gerritBuildUnstableCodeReviewValue = DEFAULT_GERRIT_BUILD_UNSTABLE_CODE_REVIEW_VALUE;
      gerritBuildNotBuiltCodeReviewValue = DEFAULT_GERRIT_BUILD_NOT_BUILT_CODE_REVIEW_VALUE;
    } else {
      gerritBuildStartedVerifiedValue =
          getValueFromFormData(formData, "gerritBuildStartedVerifiedValue");
      gerritBuildSuccessfulVerifiedValue =
          getValueFromFormData(formData, "gerritBuildSuccessfulVerifiedValue");
      gerritBuildFailedVerifiedValue =
          getValueFromFormData(formData, "gerritBuildFailedVerifiedValue");
      gerritBuildUnstableVerifiedValue =
          getValueFromFormData(formData, "gerritBuildUnstableVerifiedValue");
      gerritBuildNotBuiltVerifiedValue =
          getValueFromFormData(formData, "gerritBuildNotBuiltVerifiedValue");
      gerritBuildStartedCodeReviewValue =
          getValueFromFormData(formData, "gerritBuildStartedCodeReviewValue");
      gerritBuildSuccessfulCodeReviewValue =
          getValueFromFormData(formData, "gerritBuildSuccessfulCodeReviewValue");
      gerritBuildFailedCodeReviewValue =
          getValueFromFormData(formData, "gerritBuildFailedCodeReviewValue");
      gerritBuildUnstableCodeReviewValue =
          getValueFromFormData(formData, "gerritBuildUnstableCodeReviewValue");
      gerritBuildNotBuiltCodeReviewValue =
          getValueFromFormData(formData, "gerritBuildNotBuiltCodeReviewValue");
    }

    gerritVerifiedCmdBuildStarted =
        formData.optString(
            "gerritVerifiedCmdBuildStarted",
            "gerrit review <CHANGE>,<PATCHSET> --message 'Build Started <BUILDURL> <STARTED_STATS>' "
                + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
    gerritVerifiedCmdBuildFailed =
        formData.optString(
            "gerritVerifiedCmdBuildFailed",
            "gerrit review <CHANGE>,<PATCHSET> --message 'Build Failed <BUILDS_STATS>' "
                + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
    gerritVerifiedCmdBuildSuccessful =
        formData.optString(
            "gerritVerifiedCmdBuildSuccessful",
            "gerrit review <CHANGE>,<PATCHSET> --message 'Build Successful <BUILDS_STATS>' "
                + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
    gerritVerifiedCmdBuildUnstable =
        formData.optString(
            "gerritVerifiedCmdBuildUnstable",
            "gerrit review <CHANGE>,<PATCHSET> --message 'Build Unstable <BUILDS_STATS>' "
                + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
    gerritVerifiedCmdBuildNotBuilt =
        formData.optString(
            "gerritVerifiedCmdBuildNotBuilt",
            "gerrit review <CHANGE>,<PATCHSET> --message 'No Builds Executed <BUILDS_STATS>' "
                + "--verified <VERIFIED> --code-review <CODE_REVIEW>");
    gerritFrontEndUrl = formData.optString("gerritFrontEndUrl", DEFAULT_GERRIT_HOSTNAME);
    enableManualTrigger = formData.optBoolean("enableManualTrigger", DEFAULT_ENABLE_MANUAL_TRIGGER);
    enablePluginMessages =
        formData.optBoolean("enablePluginMessages", DEFAULT_ENABLE_PLUGIN_MESSAGES);
    buildScheduleDelay = formData.optInt("buildScheduleDelay", DEFAULT_BUILD_SCHEDULE_DELAY);
    if (buildScheduleDelay < 0) {
      buildScheduleDelay = 0;
    }
    dynamicConfigRefreshInterval =
        formData.optInt("dynamicConfigRefreshInterval", DEFAULT_DYNAMIC_CONFIG_REFRESH_INTERVAL);

    projectListFetchDelay =
        formData.optInt("projectListFetchDelay", DEFAULT_PROJECT_LIST_FETCH_DELAY);

    projectListRefreshInterval =
        formData.optInt("projectListRefreshInterval", DEFAULT_PROJECT_LIST_REFRESH_INTERVAL);
    enableProjectAutoCompletion =
        formData.optBoolean("enableProjectAutoCompletion", DEFAULT_ENABLE_PROJECT_AUTO_COMPLETION);

    categories = new LinkedList<VerdictCategory>();
    if (formData.has("verdictCategories")) {
      Object cat = formData.get("verdictCategories");
      if (cat instanceof JSONArray) {
        for (Object jsonObject : (JSONArray) cat) {
          categories.add(VerdictCategory.createVerdictCategoryFromJSON((JSONObject) jsonObject));
        }
      } else if (cat instanceof JSONObject) {
        categories.add(VerdictCategory.createVerdictCategoryFromJSON((JSONObject) cat));
      }
    }
    watchdogTimeoutMinutes =
        formData.optInt("watchdogTimeoutMinutes", DEFAULT_GERRIT_WATCHDOG_TIMEOUT_MINUTES);
    watchTimeExceptionData = addWatchTimeExceptionData(formData);

    if (formData.has("useRestApi")) {
      useRestApi = true;
      JSONObject restApi = formData.getJSONObject("useRestApi");
      gerritHttpUserName = restApi.optString("gerritHttpUserName", "");
      gerritHttpPassword = Secret.fromString(restApi.optString("gerritHttpPassword", ""));
      restCodeReview = restApi.optBoolean("restCodeReview", true);
      restVerified = restApi.optBoolean("restVerified", true);
    } else {
      useRestApi = false;
    }

    replicationConfig = ReplicationConfig.createReplicationConfigFromJSON(formData);
  }
예제 #21
0
파일: Mailer.java 프로젝트: pfeuffer/hudson
 public void setSmtpAuth(String userName, String password) {
   this.smtpAuthUsername = userName;
   this.smtpAuthPassword = Secret.fromString(password);
 }
예제 #22
0
 public Secret getAdminPassword() {
   return amiType.isWindows() ? ((WindowsData) amiType).getPassword() : Secret.fromString("");
 }
 public void setCredential(String username, String apiKey) throws IOException {
   this.username = username;
   this.apiKey = Secret.fromString(apiKey);
   save();
 }
예제 #24
0
 public String getAccessToken(String repourl) {
   DBObject token = getToken(repourl);
   return Secret.fromString(token.get("access_token").toString()).getPlainText();
 }
    public FormValidation doValidate(
        @QueryParameter(fixEmpty = true) String domain,
        @QueryParameter(fixEmpty = true) String site,
        @QueryParameter(fixEmpty = true) String bindName,
        @QueryParameter(fixEmpty = true) String bindPassword,
        @QueryParameter(fixEmpty = true) String server)
        throws IOException, ServletException, NamingException {
      ClassLoader ccl = Thread.currentThread().getContextClassLoader();
      Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
      try {
        Functions.checkPermission(Hudson.ADMINISTER);
        String n = Util.fixEmptyAndTrim(domain);
        if (n == null) { // no value given yet
          return FormValidation.error("No domain name set");
        }

        Secret password = Secret.fromString(bindPassword);
        if (bindName != null && password == null)
          return FormValidation.error("DN is specified but not password");

        String[] names = n.split(",");
        for (String name : names) {

          if (!name.endsWith(".")) name += '.';

          DirContext ictx;

          // first test the sanity of the domain name itself
          try {
            LOGGER.fine("Attempting to resolve " + name + " to NS record");
            ictx = createDNSLookupContext();
            Attributes attributes = ictx.getAttributes(name, new String[] {"NS"});
            Attribute ns = attributes.get("NS");
            if (ns == null) {
              LOGGER.fine("Attempting to resolve " + name + " to A record");
              attributes = ictx.getAttributes(name, new String[] {"A"});
              Attribute a = attributes.get("A");
              if (a == null) throw new NamingException(name + " doesn't look like a domain name");
            }
            LOGGER.log(Level.FINE, "{0} resolved to {1}", new Object[] {name, ns});
          } catch (NamingException e) {
            LOGGER.log(Level.WARNING, "Failed to resolve " + name + " to A record", e);
            return FormValidation.error(e, name + " doesn't look like a valid domain name");
          }

          // then look for the LDAP server
          List<SocketInfo> servers;
          try {
            servers = obtainLDAPServer(ictx, name, site, server);
          } catch (NamingException e) {
            String msg =
                site == null
                    ? "No LDAP server was found in " + name
                    : "No LDAP server was found in the " + site + " site of " + name;
            LOGGER.log(Level.WARNING, msg, e);
            return FormValidation.error(e, msg);
          }

          if (bindName != null) {
            // make sure the bind actually works
            try {
              DirContext context = bind(bindName, Secret.toString(password), servers);
              try {
                // actually do a search to make sure the credential is valid
                new LDAPSearchBuilder(context, toDC(domain)).searchOne("(objectClass=user)");
              } finally {
                context.close();
              }
            } catch (BadCredentialsException e) {
              return FormValidation.error(e, "Bad bind username or password");
            } catch (javax.naming.AuthenticationException e) {
              return FormValidation.error(e, "Bad bind username or password");
            } catch (Exception e) {
              return FormValidation.error(e, e.getMessage());
            }
          } else {
            // just some connection test
            // try to connect to LDAP port to make sure this machine has LDAP service
            IOException error = null;
            for (SocketInfo si : servers) {
              try {
                si.connect().close();
                break; // looks good
              } catch (IOException e) {
                LOGGER.log(Level.FINE, "Failed to connect to " + si, e);
                error = e;
                // try the next server in the list
              }
            }
            if (error != null) {
              LOGGER.log(Level.WARNING, "Failed to connect to " + servers, error);
              return FormValidation.error(error, "Failed to connect to " + servers);
            }
          }
        }

        // looks good
        return FormValidation.ok("Success");
      } finally {
        Thread.currentThread().setContextClassLoader(ccl);
      }
    }
 public void releaseRepository(String repository, String user, String password) {
   this.releaseRepository = repository;
   this.releaseUser = user;
   this.releasePassword = Secret.fromString(password);
 }
 @DataBoundConstructor
 public BlazemeterCredentialImpl(String apiKey, String description) {
   this.apiKey = Secret.fromString(apiKey);
   this.description = description;
 }