Tabnine Logo
CredentialsStore.addCredentials
Code IndexAdd Tabnine to your IDE (free)

How to use
addCredentials
method
in
com.cloudbees.plugins.credentials.CredentialsStore

Best Java code snippets using com.cloudbees.plugins.credentials.CredentialsStore.addCredentials (Showing top 20 results out of 315)

origin: jenkinsci/gitlab-plugin

  @Initializer(after = InitMilestone.PLUGINS_STARTED)
  public static void migrate() throws IOException {
    GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class);
    for (GitLabConnection connection : descriptor.getConnections()) {
      if (connection.apiTokenId == null && connection.apiToken != null) {
        for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) {
          if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) {
            List<Domain> domains = credentialsStore.getDomains();
            connection.apiTokenId = UUID.randomUUID().toString();
            credentialsStore.addCredentials(domains.get(0),
              new GitLabApiTokenImpl(CredentialsScope.SYSTEM, connection.apiTokenId, "GitLab API Token", Secret.fromString(connection.apiToken)));
          }
        }
      }
    }
    descriptor.save();
  }
}
origin: org.jenkins-ci.plugins/credentials

  /**
   * {@inheritDoc}
   */
  @Override
  protected int run() throws Exception {
    store.checkPermission(CredentialsProvider.CREATE);
    Domain domain = getDomainByName(store, this.domain);
    if (domain == null) {
      stderr.println("No such domain");
      return 2;
    }

    Credentials credentials = (Credentials) Items.XSTREAM.unmarshal(safeXmlStreamReader(stdin));
    if (store.addCredentials(domain, credentials)) {
      return 0;
    }
    stderr.println("No change");
    return 1;
  }
}
origin: jenkinsci/credentials-plugin

  /**
   * {@inheritDoc}
   */
  @Override
  protected int run() throws Exception {
    store.checkPermission(CredentialsProvider.CREATE);
    Domain domain = getDomainByName(store, this.domain);
    if (domain == null) {
      stderr.println("No such domain");
      return 2;
    }

    Credentials credentials = (Credentials) Items.XSTREAM.unmarshal(safeXmlStreamReader(stdin));
    if (store.addCredentials(domain, credentials)) {
      return 0;
    }
    stderr.println("No change");
    return 1;
  }
}
origin: jenkinsci/coverity-plugin

private String createCredentials(String username, String password) {
  String credentialId = name + "_" + username;
  try{
    StandardCredentials credential = retrieveCredential(credentialId);
    if (credential != null) {
      return StringUtils.EMPTY;
    }
    UsernamePasswordCredentialsImpl migrateCredential = new UsernamePasswordCredentialsImpl(
        CredentialsScope.GLOBAL, name + "_" + username, "Migrated Coverity Credential", username, password);
    CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
    store.addCredentials(Domain.global(), migrateCredential);
  } catch (IOException ioe) {
    logger.warning("Migrating username and password into credentials encountered IOException"
    + "\nPlease try to resolve this issue by adding credentials manually");
    return StringUtils.EMPTY;
  }
  return credentialId;
}
origin: jenkinsci/jclouds-plugin

/**
 * Stores a new credentials record (Used only during migration).
 * @param u The new credentials to store;
 * @return The Id of the new record or {@code null} on failure.
 * @throws IOException on error.
 */
public static String storeCredentials(final StandardUsernameCredentials u) throws IOException {
  if (null != u) {
    try (final ACLContext ctx = ACL.as(ACL.SYSTEM)) {
      final CredentialsStore s = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
      s.addCredentials(Domain.global(), u);
      return u.getId();
    }
  }
  return null;
}
origin: jenkinsci/pipeline-model-definition-plugin

@BeforeClass
public static void setup() throws Exception {
  CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next();
  store.addCredentials(Domain.global(), globalCred);
}
origin: uber/phabricator-jenkins-plugin

private static void addCredentials(ConduitCredentials credentials) throws IOException {
  CredentialsStore store = new SystemCredentialsProvider.UserFacingAction().getStore();
  store.addCredentials(Domain.global(), credentials);
}
origin: jenkinsci/pipeline-model-definition-plugin

@Issue("JENKINS-48380")
@Test
public void withCredentialsWrapper() throws Exception {
  final String credentialsId = "creds";
  final String username = "bob";
  final String passphrase = "s3cr3t";
  final String keyContent = "the-key";
  SSHUserPrivateKey c = new DummyPrivateKey(credentialsId, username, passphrase, keyContent);
  CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), c);
  expect("withCredentialsWrapper")
      .archives("userPass.txt", username + ":" + passphrase)
      .archives("key.txt", keyContent)
      .go();
}
origin: jenkinsci/pipeline-model-definition-plugin

@Issue("JENKINS-48380")
@Test
public void withCredentialsStageWrapper() throws Exception {
  final String credentialsId = "creds";
  final String username = "bob";
  final String passphrase = "s3cr3t";
  final String keyContent = "the-key";
  SSHUserPrivateKey c = new DummyPrivateKey(credentialsId, username, passphrase, keyContent);
  CredentialsProvider.lookupStores(j.jenkins).iterator().next().addCredentials(Domain.global(), c);
  expect("withCredentialsStageWrapper")
      .logContains("THEUSER is null")
      .archives("userPass.txt", username + ":" + passphrase)
      .archives("key.txt", keyContent)
      .go();
}
origin: jenkinsci/mercurial-plugin

@Test public void doFillCredentialsIdItemsWithoutJobWhenAdmin() throws Exception {
  r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
  ProjectMatrixAuthorizationStrategy as = new ProjectMatrixAuthorizationStrategy();
  as.add(Jenkins.ADMINISTER, "alice");
  r.jenkins.setAuthorizationStrategy(as);
  final UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "test", "bob", "s3cr3t");
  CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
  ACL.impersonate(User.get("alice").impersonate(), new Runnable() {
    @Override public void run() {
      ListBoxModel options = r.jenkins.getDescriptorByType(MercurialSCM.DescriptorImpl.class).doFillCredentialsIdItems(null, "http://nowhere.net/");
      assertEquals(CredentialsNameProvider.name(c), options.get(1).name);
    }
  });
}
origin: jenkinsci/pipeline-model-definition-plugin

@Test
public void withDefaults() throws Exception {
  Folder folder = j.createProject(Folder.class);
  getFolderStore(folder).addCredentials(Domain.global(), folderCred);
  getFolderStore(folder).addCredentials(Domain.global(), grandParentCred);
  folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
  expect("declarativeDockerConfigWithOverride")
      .inFolder(folder)
      .runFromRepo(false)
      .logContains("Docker Label is: other-label",
          "Registry URL is: https://other.registry",
          "Registry Creds ID is: " + grandParentCred.getId()).go();
}
origin: jenkinsci/mercurial-plugin

@Issue("SECURITY-158")
@Test public void doFillCredentialsIdItems() throws Exception {
  r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
  ProjectMatrixAuthorizationStrategy as = new ProjectMatrixAuthorizationStrategy();
  as.add(Jenkins.READ, "alice");
  as.add(Jenkins.READ, "bob");
  r.jenkins.setAuthorizationStrategy(as);
  FreeStyleProject p1 = r.createFreeStyleProject("p1");
  FreeStyleProject p2 = r.createFreeStyleProject("p2");
  p2.addProperty(new AuthorizationMatrixProperty(Collections.singletonMap(Item.CONFIGURE, Collections.singleton("bob"))));
  UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "test", "bob", "s3cr3t");
  CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
  assertCredentials("alice", null);
  assertCredentials("alice", p1);
  assertCredentials("alice", p2);
  assertCredentials("bob", null);
  assertCredentials("bob", p1);
  assertCredentials("bob", p2, c);
}
private void assertCredentials(String user, final Job<?,?> owner, Credentials... expected) {
origin: jenkinsci/cloudbees-folder-plugin

@Test
public void given_folderCredential_when_builtAsSystem_then_credentialFound() throws Exception {
  Folder f = createFolder();
  CredentialsStore folderStore = getFolderStore(f);
  folderStore.addCredentials(Domain.global(),
      new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "foo-manchu", "Dr. Fu Manchu", "foo",
          "manchu"));
  FreeStyleProject prj = f.createProject(FreeStyleProject.class, "job");
  prj.getBuildersList().add(new HasCredentialBuilder("foo-manchu"));
  r.buildAndAssertSuccess(prj);
}
origin: jenkinsci/pipeline-model-definition-plugin

@Test
public void grandParentOverride() throws Exception {
  Folder grandParent = j.createProject(Folder.class);
  getFolderStore(grandParent).addCredentials(Domain.global(), grandParentCred);
  grandParent.addProperty(new FolderConfig("parent_docker", "https://parent.registry", grandParentCred.getId()));
  Folder parent = grandParent.createProject(Folder.class, "testParent"); //Can be static since grandParent should be unique
  getFolderStore(parent).addCredentials(Domain.global(), folderCred);
  parent.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
  expect("declarativeDockerConfig")
      .inFolder(parent)
      .runFromRepo(false)
      .logContains("Docker Label is: folder_docker",
          "Registry URL is: https://folder.registry",
          "Registry Creds ID is: " + folderCred.getId())
      .logNotContains("Docker Label is: parent_docker",
          "Registry URL is: https://parent.registry",
          "Registry Creds ID is: " + grandParentCred.getId()).go();
}
origin: jenkinsci/pipeline-model-definition-plugin

@BeforeClass
public static void setUpAgent() throws Exception {
  s = j.createOnlineSlave();
  s.setLabelString("some-label docker");
  s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"),
      new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first")));
  s.setNumExecutors(2);
  s2 = j.createOnlineSlave();
  s2.setLabelString("other-docker");
  s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"),
      new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second")));
  //setup credentials for docker registry
  CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next();
  password = System.getProperty("docker.password");
  if(password != null) {
    UsernamePasswordCredentialsImpl globalCred =
        new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
            "dockerhub", "real", "jtaboada", password);
    store.addCredentials(Domain.global(), globalCred);
  }
}
origin: jenkinsci/pipeline-model-definition-plugin

@Test
public void directParent() throws Exception {
  Folder folder = j.createProject(Folder.class);
  getFolderStore(folder).addCredentials(Domain.global(), folderCred);
  folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
  expect("declarativeDockerConfig")
      .inFolder(folder)
      .runFromRepo(false)
      .logContains("Docker Label is: folder_docker",
          "Registry URL is: https://folder.registry",
          "Registry Creds ID is: " + folderCred.getId()).go();
}
origin: jenkinsci/pipeline-model-definition-plugin

@BeforeClass
public static void setUpAgentAndCreds() throws Exception {
  s = j.createOnlineSlave();
  s.setLabelString("some-label docker here");
  s.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"),
      new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "first")));
  s.setNumExecutors(2);
  s2 = j.createOnlineSlave();
  s2.setLabelString("other-docker");
  s2.getNodeProperties().add(new EnvironmentVariablesNodeProperty(new EnvironmentVariablesNodeProperty.Entry("ONAGENT", "true"),
      new EnvironmentVariablesNodeProperty.Entry("WHICH_AGENT", "second")));
  CredentialsStore store = CredentialsProvider.lookupStores(j.jenkins).iterator().next();
  String usernamePasswordCredentialsId = "FOOcredentials";
  UsernamePasswordCredentialsImpl usernamePassword = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, usernamePasswordCredentialsId, "sample", usernamePasswordUsername, usernamePasswordPassword);
  store.addCredentials(Domain.global(), usernamePassword);
}
origin: jenkinsci/pipeline-model-definition-plugin

@Test
public void grandParent() throws Exception {
  Folder grandParent = j.createProject(Folder.class);
  getFolderStore(grandParent).addCredentials(Domain.global(), grandParentCred);
  grandParent.addProperty(new FolderConfig("parent_docker", "https://parent.registry", grandParentCred.getId()));
  Folder parent = grandParent.createProject(Folder.class, "testParent"); //Can be static since grandParent should be unique
  expect("declarativeDockerConfig")
      .inFolder(parent)
      .runFromRepo(false)
      .logContains("Docker Label is: parent_docker",
          "Registry URL is: https://parent.registry",
          "Registry Creds ID is: " + grandParentCred.getId()).go();
}
origin: jenkinsci/cloudbees-folder-plugin

@Test
public void given_folderCredential_when_builtAsUserWithoutUseItem_then_credentialNotFound() throws Exception {
  Folder f = createFolder();
  CredentialsStore folderStore = getFolderStore(f);
  folderStore.addCredentials(Domain.global(),
      new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "foo-manchu", "Dr. Fu Manchu", "foo",
          "manchu"));
  FreeStyleProject prj = f.createProject(FreeStyleProject.class, "job");
  prj.getBuildersList().add(new HasCredentialBuilder("foo-manchu"));
  JenkinsRule.DummySecurityRealm realm = r.createDummySecurityRealm();
  r.jenkins.setSecurityRealm(realm);
  MockAuthorizationStrategy strategy = new MockAuthorizationStrategy();
  strategy.grant(Item.BUILD).everywhere().to("bob");
  strategy.grant(Computer.BUILD).everywhere().to("bob");
  r.jenkins.setAuthorizationStrategy(strategy);
  HashMap<String, Authentication> jobsToUsers = new HashMap<String, Authentication>();
  jobsToUsers.put(prj.getFullName(), User.get("bob").impersonate());
  MockQueueItemAuthenticator authenticator = new MockQueueItemAuthenticator(jobsToUsers);
  QueueItemAuthenticatorConfiguration.get().getAuthenticators().clear();
  QueueItemAuthenticatorConfiguration.get().getAuthenticators().add(authenticator);
  r.assertBuildStatus(Result.FAILURE, prj.scheduleBuild2(0).get());
}
origin: jenkinsci/pipeline-model-definition-plugin

@Test
public void directParentNotSystem() throws Exception {
  GlobalConfig.get().setDockerLabel("config_docker");
  GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId()));
  Folder folder = j.createProject(Folder.class);
  getFolderStore(folder).addCredentials(Domain.global(), folderCred);
  folder.addProperty(new FolderConfig("folder_docker", "https://folder.registry", folderCred.getId()));
  expect("declarativeDockerConfig")
      .inFolder(folder)
      .runFromRepo(false)
      .logContains("Docker Label is: folder_docker",
          "Registry URL is: https://folder.registry",
          "Registry Creds ID is: " + folderCred.getId())
      .logNotContains("Docker Label is: config_docker",
          "Registry URL is: https://docker.registry",
          "Registry Creds ID is: " + globalCred.getId()).go();
}
com.cloudbees.plugins.credentialsCredentialsStoreaddCredentials

Javadoc

Adds the specified Credentials within the specified Domain for this CredentialsStore.

Popular methods of CredentialsStore

  • getDomains
    Returns all the com.cloudbees.plugins.credentials.domains.Domains that this credential provider has.
  • addDomain
    Adds a new Domain with seed credentials.
  • getContext
    Returns the context within which this store operates. Credentials in this store will be available to
  • getProvider
    Returns the CredentialsProvider.
  • getCredentials
    Returns an unmodifiable list of credentials for the specified domain.
  • isDomainsModifiable
    Identifies whether this CredentialsStore supports making changes to the list of domains or whether i
  • updateCredentials
    Updates the specified Credentials from the specified Domain for this CredentialsStore with the suppl
  • _isApplicable
    CredentialsStore subtypes can override this method to veto some Descriptors from being available fro
  • checkPermission
    Checks if the current security principal has this permission. Note: This is just a convenience funct
  • getACL
  • getContextDisplayName
    Returns the display name of the #getContext() of this CredentialsStore. The default implementation c
  • getCredentialsDescriptors
    Returns the list of CredentialsDescriptor instances that are applicable within this CredentialsStore
  • getContextDisplayName,
  • getCredentialsDescriptors,
  • getRelativeLinkToAction,
  • getRelativeLinkToContext,
  • getScopes,
  • getStoreAction,
  • hasPermission,
  • isOverridden,
  • removeCredentials

Popular in Java

  • Finding current android device location
  • setScale (BigDecimal)
  • putExtra (Intent)
  • getApplicationContext (Context)
  • Path (java.nio.file)
  • BitSet (java.util)
    The BitSet class implements abit array [http://en.wikipedia.org/wiki/Bit_array]. Each element is eit
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • Callable (java.util.concurrent)
    A task that returns a result and may throw an exception. Implementors define a single method with no
  • CountDownLatch (java.util.concurrent)
    A synchronization aid that allows one or more threads to wait until a set of operations being perfor
  • Filter (javax.servlet)
    A filter is an object that performs filtering tasks on either the request to a resource (a servlet o
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now