Refine search
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; }
@NonNull @Override protected BasicSSHUserPassword doResolve(@NonNull UsernamePasswordCredentialsImpl original) { return new BasicSSHUserPassword(original.getScope(), original.getId(), original.getUsername(), original.getPassword().getEncryptedValue(), original.getDescription()); } }
@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); }
Proc p = runSvnServe(getClass().getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Collections.<Credentials>emptyList() )); FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/bob", "1-bob", ".")); FreeStyleProject c = r.createFreeStyleProject(); c.setScm(new SubversionSCM("svn://localhost/charlie", "2-charlie", ".")); r.assertBuildStatus(Result.FAILURE, b.scheduleBuild2(0).get()); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob") r.assertBuildStatus(Result.FAILURE, c.scheduleBuild2(0).get()); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob"), new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "2-charlie", null, "charlie","charlie")
@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(); }
@Test public void configRoundTrip() throws Exception { FreeStyleProject p = r.createFreeStyleProject(); MercurialSCM scm = new MercurialSCM("http://repo/"); assertEquals("default", scm.getRevision()); scm.setRevisionType(MercurialSCM.RevisionType.TAG); scm.setRevision("LATEST"); UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "test", "bob", "s3cr3t"); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c); scm.setCredentialsId(c.getId()); scm.setModules("src"); scm.setSubdir("checkout"); XmlFile xml = p.getConfigFile(); System.out.println(xml.asString()); r.configRoundtrip(p); System.out.println(xml.asString()); scm = (MercurialSCM) p.getScm(); assertEquals(MercurialSCM.RevisionType.TAG, scm.getRevisionType()); assertEquals("LATEST", scm.getRevision()); assertEquals(c.getId(), scm.getCredentialsId()); assertEquals("s3cr3t", ((UsernamePasswordCredentialsImpl) scm.getCredentials(p, new EnvVars())).getPassword().getPlainText()); assertEquals("src", scm.getModules()); assertEquals("checkout", scm.getSubdir());
@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); }
public StandardCredentials getGitCredentials() { if (overrideCredentials) { return new UsernamePasswordCredentialsImpl(null, null, "release staging Git credentials", username, password); } return null; }
@BeforeClass public static void setup() throws Exception { 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); StringCredentialsImpl mixedEnvCred1 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvCred1Secret)); store.addCredentials(Domain.global(), mixedEnvCred1); UsernamePasswordCredentialsImpl mixedEnvCred2 = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvCred2U, mixedEnvCred2P); store.addCredentials(Domain.global(), mixedEnvCred2); StringCredentialsImpl mixedEnvCred3 = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred3Id, "test", Secret.fromString(mixedEnvCred3Secret)); store.addCredentials(Domain.global(), mixedEnvCred3); FileCredentialsImpl fileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, fileCredId, "test", fileCredName, SecretBytes.fromBytes(fileCredContent.getBytes())); store.addCredentials(Domain.global(), fileCred); FileCredentialsImpl otherFileCred = new FileCredentialsImpl(CredentialsScope.GLOBAL, otherFileCredId, "test", otherFileCredName, SecretBytes.fromBytes(otherFileCredContent.getBytes())); store.addCredentials(Domain.global(), otherFileCred); folder = j.jenkins.createProject(Folder.class, "testFolder"); folder.addProperty(new FolderCredentialsProvider.FolderCredentialsProperty(new DomainCredentials[0])); j.configRoundtrip(folder); CredentialsStore folderStore = folder.getProperties().get(FolderCredentialsProvider.FolderCredentialsProperty.class).getStore(); StringCredentialsImpl sc = new StringCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred1Id, "test", Secret.fromString(mixedEnvInFolderCred1Secret)); folderStore.addCredentials(Domain.global(), sc); UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, mixedEnvCred2Id, "sample", mixedEnvInFoldercred2U, mixedEnvInFolderCred2P); folderStore.addCredentials(Domain.global(), c); SSHUserPrivateKey k = new BasicSSHUserPrivateKey(CredentialsScope.GLOBAL, "sshCred1", "bobby", new BasicSSHUserPrivateKey.DirectEntryPrivateKeySource("abc123"), null, "sample"); store.addCredentials(Domain.global(), k); }
String username = "bob"; String password = "s3cr3t"; UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test", "sample", username, password); CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c); )); WorkflowRun run = job.scheduleBuild2(0).getStartCondition().get(); r.waitForCompletion(run); FlowExecution exec = run.getExecution(); String log = r.getLog(run); ForkScanner scanner = new ForkScanner(); List<FlowNode> filtered = scanner.filteredNodes(exec, new DescriptorMatchPredicate(BindingStep.DescriptorImpl.class));
public static String setCredentials(final String hostName, String username, String password) { List<DomainSpecification> domainSpecifications = new ArrayList<>(); domainSpecifications.add(new HostnameSpecification(hostName, null)); Domain domain = new Domain("Generated for " + hostName, "", domainSpecifications); SystemCredentialsProvider.getInstance().getDomainCredentialsMap().put(domain, new ArrayList<Credentials>()); String credentialsId; StandardUsernamePasswordCredentials newCredential = new UsernamePasswordCredentialsImpl( CredentialsScope.GLOBAL, credentialsId = UUID.randomUUID().toString(), "Generated for " + username, username, password ); SystemCredentialsProvider.getInstance().getDomainCredentialsMap().get(domain).add(newCredential); try { SystemCredentialsProvider.getInstance().save(); } catch (IOException ex) { LOGGER.log(Level.WARNING, "SystemCredentialsProvider instance save failed: ", ex); } return credentialsId; }
@Test @LocalData() public void upgradeFrom_1_1() throws Exception { List<Credentials> credentials = SystemCredentialsProvider.getInstance().getCredentials(); assertEquals(3, credentials.size()); UsernamePasswordCredentialsImpl cred0 = (UsernamePasswordCredentialsImpl) credentials.get(0); assertEquals("token", cred0.getId()); assertEquals("myusername", cred0.getUsername()); FileSystemServiceAccountCredential cred1 = (FileSystemServiceAccountCredential) credentials.get(1); StringCredentialsImpl cred2 = (StringCredentialsImpl) credentials.get(2); assertEquals("mytoken", Secret.toString(cred2.getSecret())); assertThat(cloud.getLabels(), hasEntry("jenkins", "slave")); }
@Test public void plainSystemConfig() throws Exception { GlobalConfig.get().setDockerLabel("config_docker"); GlobalConfig.get().setRegistry(new DockerRegistryEndpoint("https://docker.registry", globalCred.getId())); expect("declarativeDockerConfig") .logContains("Docker Label is: config_docker", "Registry URL is: https://docker.registry", "Registry Creds ID is: " + globalCred.getId()).go(); }
@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); } }); }
/** * There was a bug that credentials stored in the remote call context was serialized wrongly. */ @Issue("JENKINS-8061") @Test public void remoteBuild() throws Exception { Proc p = runSvnServe(SubversionSCMTest.class.getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-alice", null, "alice", "alice") ) )); FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/bob", "1-alice", ".")); b.setAssignedNode(r.createSlave()); FreeStyleBuild run = r.buildAndAssertSuccess(b); /* TODO runSvnServe not guaranteed to use port 3690; otherwise this works: assertLogContains(Messages.CredentialsSVNAuthenticationProviderImpl_sole_credentials("alice/******", "<svn://localhost:3690> 8a677b3a-1c61-4b23-9212-1bf3c3d713a7"), run); */ } finally { p.kill(); } } }
@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(); }
@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); } }
public static String createCredentials(String serverAPIUrl, String username, String password) throws Exception { String description = serverAPIUrl + " GitHub auto generated Username password credentials"; UsernamePasswordCredentialsImpl credentials = new UsernamePasswordCredentialsImpl( CredentialsScope.GLOBAL, UUID.randomUUID().toString(), description, username, password); return createCredentials(serverAPIUrl, credentials); }
"migrated from previous ssh-plugin version"); } else if (!Strings.isNullOrEmpty(legacy.password)) { credentialsToCreate = new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, createdCredentialId, "migrated from previous ssh-plugin version", legacy.username, legacy.password); } else { final Domain sshDomain = new Domain("ssh-plugin-" + site.hostname, "migrated ssh-plugin credentials-" + site.hostname, Lists.newArrayList(hostnameSpec));
@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) {