本文整理汇总了Java中com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl类的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordCredentialsImpl类的具体用法?Java UsernamePasswordCredentialsImpl怎么用?Java UsernamePasswordCredentialsImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsernamePasswordCredentialsImpl类属于com.cloudbees.plugins.credentials.impl包,在下文中一共展示了UsernamePasswordCredentialsImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupGlobalConfiguration
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
/**
* Setup the global configuration.
*
* @throws IOException
*/
public static void setupGlobalConfiguration() throws IOException
{
JSONObject hostConnection = new JSONObject();
hostConnection.put(TestConstants.DESCRIPTION, "TestConnection");
hostConnection.put(TestConstants.HOST_PORT, TestConstants.EXPECTED_HOST + ':' + TestConstants.EXPECTED_PORT);
hostConnection.put(TestConstants.CODE_PAGE, TestConstants.EXPECTED_CODE_PAGE);
hostConnection.put(TestConstants.TIMEOUT, TestConstants.EXPECTED_TIMEOUT);
hostConnection.put(TestConstants.CONNECTION_ID, TestConstants.EXPECTED_CONNECTION_ID);
hostConnection.put(TestConstants.CES_URL, TestConstants.EXPECTED_CES_URL);
JSONArray hostConnections = new JSONArray();
hostConnections.add(hostConnection);
JSONObject json = new JSONObject();
json.put("hostConn", hostConnections);
json.put(TestConstants.TOPAZ_CLI_LOCATION_LINUX, "/opt/Compuware/TopazCLI");
json.put(TestConstants.TOPAZ_CLI_LOCATION_WINDOWS, "C:\\Program Files\\Compuware\\Topaz Workbench CLI");
CpwrGlobalConfiguration globalConfig = CpwrGlobalConfiguration.get();
globalConfig.configure(Stapler.getCurrentRequest(), json);
SystemCredentialsProvider.getInstance().getCredentials().add(new UsernamePasswordCredentialsImpl(CredentialsScope.USER,
TestConstants.EXPECTED_CREDENTIALS_ID, null, TestConstants.EXPECTED_USER_ID, TestConstants.EXPECTED_PASSWORD));
SystemCredentialsProvider.getInstance().save();
}
示例2: configRoundTrip
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test public void configRoundTrip() {
story.addStep(new Statement() {
@Override public void evaluate() throws Throwable {
IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "registryCreds", null, "me", "pass");
CredentialsProvider.lookupStores(story.j.jenkins).iterator().next().addCredentials(Domain.global(), registryCredentials);
StepConfigTester sct = new StepConfigTester(story.j);
Map<String,Object> registryConfig = new TreeMap<String,Object>();
registryConfig.put("url", "https://docker.my.com/");
registryConfig.put("credentialsId", registryCredentials.getId());
Map<String,Object> config = Collections.<String,Object>singletonMap("registry", registryConfig);
RegistryEndpointStep step = DescribableHelper.instantiate(RegistryEndpointStep.class, config);
step = sct.configRoundTrip(step);
DockerRegistryEndpoint registry = step.getRegistry();
assertNotNull(registry);
assertEquals("https://docker.my.com/", registry.getUrl());
assertEquals(registryCredentials.getId(), registry.getCredentialsId());
assertEquals(config, DescribableHelper.uninstantiate(step));
}
});
}
示例3: testPerformWrongCredentials
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void testPerformWrongCredentials() throws Exception {
FreeStyleProject project = j.createFreeStyleProject();
project.setScm(new ExtractResourceSCM(getClass().getResource("hello-java.zip")));
CredentialsStore store = CredentialsProvider.lookupStores(j.getInstance()).iterator().next();
store.addCredentials(Domain.global(),
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "wrongCredentialsId", "",
"wrongName", "wrongPass"));
CloudFoundryPushPublisher cf = new CloudFoundryPushPublisher(TEST_TARGET, TEST_ORG, TEST_SPACE,
"wrongCredentialsId", false, false, 0, null, ManifestChoice.defaultManifestFileConfig());
project.getPublishersList().add(cf);
FreeStyleBuild build = project.scheduleBuild2(0).get();
System.out.println(build.getDisplayName() + " completed");
String s = FileUtils.readFileToString(build.getLogFile());
System.out.println(s);
assertTrue("Build succeeded where it should have failed", build.getResult().isWorseOrEqualTo(Result.FAILURE));
assertTrue("Build did not write error message", s.contains("ERROR: Wrong username or password"));
}
示例4: basics
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test public void basics() throws Exception {
String username = "bob";
String password = "s3cr3t";
UsernamePasswordCredentialsImpl c = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, null, "sample", username, password);
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), c);
FreeStyleProject p = r.createFreeStyleProject();
p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<Binding<?>>singletonList(new UsernamePasswordBinding("AUTH", c.getId()))));
p.getBuildersList().add(Functions.isWindows() ? new BatchFile("echo %AUTH% > auth.txt") : new Shell("echo $AUTH > auth.txt"));
r.configRoundtrip(p);
SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
assertNotNull(wrapper);
List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
assertEquals(1, bindings.size());
MultiBinding<?> binding = bindings.get(0);
assertEquals(c.getId(), binding.getCredentialsId());
assertEquals(UsernamePasswordBinding.class, binding.getClass());
assertEquals("AUTH", ((UsernamePasswordBinding) binding).getVariable());
FreeStyleBuild b = r.buildAndAssertSuccess(p);
r.assertLogNotContains(password, b);
assertEquals(username + ':' + password, b.getWorkspace().child("auth.txt").readToString().trim());
assertEquals("[AUTH]", b.getSensitiveBuildVariables().toString());
}
示例5: newUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
private static Credentials newUsernamePasswordCredentials(
String secretName, String usernameData, String passwordData) {
return new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL,
secretName, secretName, new String(Base64.decode(usernameData),
StandardCharsets.UTF_8), new String(
Base64.decode(passwordData), StandardCharsets.UTF_8));
}
示例6: smokes
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void smokes() {
UsernamePasswordCredentials p =
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "test", null, "bob", "secret");
assertThat(AuthenticationTokens.matcher(DigestToken.class).matches(p), is(true));
assertThat(AuthenticationTokens.matcher(DigestToken.class).matches(new CertificateCredentialsImpl(CredentialsScope.GLOBAL, "test2", null, null, new CertificateCredentialsImpl.UploadedKeyStoreSource(null))), is(false));
assertThat(AuthenticationTokens.convert(DigestToken.class, p),
is(new DigestToken(Util.getDigestOf("bob:secret"))));
}
示例7: configRoundTrip
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test public void configRoundTrip() throws Exception {
CredentialsStore store = CredentialsProvider.lookupStores(r.jenkins).iterator().next();
IdCredentials serverCredentials = new DockerServerCredentials(CredentialsScope.GLOBAL, "serverCreds", null, "clientKey", "clientCertificate", "serverCaCertificate");
store.addCredentials(Domain.global(), serverCredentials);
IdCredentials registryCredentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "registryCreds", null, "me", "pass");
store.addCredentials(Domain.global(), registryCredentials);
SampleDockerBuilder b1 = new SampleDockerBuilder(new DockerServerEndpoint("", ""), new DockerRegistryEndpoint("http://dhe.mycorp.com/", registryCredentials.getId()));
r.assertEqualDataBoundBeans(b1, r.configRoundtrip(b1));
b1 = new SampleDockerBuilder(new DockerServerEndpoint("tcp://192.168.1.104:8333", serverCredentials.getId()), new DockerRegistryEndpoint("", ""));
r.assertEqualDataBoundBeans(b1, r.configRoundtrip(b1));
r.jenkins.getDescriptorByType(DockerTool.DescriptorImpl.class).setInstallations(new DockerTool("Docker 1.5", "/usr/local/docker15", Collections.<ToolProperty<?>>emptyList()));
b1.setToolName("Docker 1.5");
r.assertEqualDataBoundBeans(b1, r.configRoundtrip(b1));
}
示例8: createCredentials
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
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);
}
示例9: upgradeFrom_1_1
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@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()));
}
示例10: repositoryCtorWithTriggerTest
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void repositoryCtorWithTriggerTest() throws Exception {
BitbucketBuildTrigger trigger = new BitbucketBuildTrigger(
"", "@hourly",
"JenkinsCID",
"foo",
"bar",
"", "",
"", true,
"", "", "",
true,
true,
false, BitbucketRepository.DEFAULT_COMMENT_TRIGGER
);
BitbucketPullRequestsBuilder builder = EasyMock.createMock(BitbucketPullRequestsBuilder.class);
EasyMock.expect(builder.getTrigger()).andReturn(trigger).anyTimes();
EasyMock.replay(builder);
CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next();
assertNotNull(store);
store.addCredentials(Domain.global(), new UsernamePasswordCredentialsImpl(
CredentialsScope.GLOBAL, "JenkinsCID", "description", "username", "password"
));
ApiClient.HttpClientFactory httpFactory = EasyMock.createNiceMock(ApiClient.HttpClientFactory.class);
EasyMock.expect(httpFactory.getInstanceHttpClient()).andReturn(
new HttpClientInterceptor(new AssertCredentials(new UsernamePasswordCredentials("username", "password")))
).anyTimes();
EasyMock.replay(httpFactory);
BitbucketRepository repo = new BitbucketRepository("", builder);
repo.init(httpFactory);
try { repo.postPullRequestApproval("prId"); } catch(Error e) { assertTrue(e instanceof AssertionError); }
}
开发者ID:nishio-dens,项目名称:bitbucket-pullrequest-builder-plugin,代码行数:37,代码来源:BitbucketBuildRepositoryTest.java
示例11: testCredentialsSupportForAbstractProjectTypes
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void testCredentialsSupportForAbstractProjectTypes() throws Exception {
assumeTrue(pw != null && repo != null && uName != null);
cloneTestRepositoryAndPrepareABranch();
SystemCredentialsProvider scp = (SystemCredentialsProvider)jenkinsRule.getInstance().getExtensionList("com.cloudbees.plugins.credentials.SystemCredentialsProvider").get(0);
UsernamePasswordCredentialsImpl unpwCred = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "pipCredentials","description", uName, pw);
scp.getCredentials().add(unpwCred);
scp.save();
List<UserRemoteConfig> urcList = new ArrayList<>();
UserRemoteConfig urc = new UserRemoteConfig(repo,null,null,"pipCredentials");
urcList.add(urc);
FreeStyleProject freeStyle = TestUtilsFactory.configurePretestedIntegrationPlugin(jenkinsRule, TestUtilsFactory.STRATEGY_TYPE.SQUASH, urcList,"origin", false);
jenkinsRule.buildAndAssertSuccess(freeStyle);
}
示例12: testCredentialsSupportForWorkflowProjectTypes
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void testCredentialsSupportForWorkflowProjectTypes() throws Exception {
assumeTrue(pw != null && repo != null && uName != null);
cloneTestRepositoryAndPrepareABranch();
SystemCredentialsProvider scp = (SystemCredentialsProvider)jenkinsRule.getInstance().getExtensionList("com.cloudbees.plugins.credentials.SystemCredentialsProvider").get(0);
UsernamePasswordCredentialsImpl unpwCred = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "pipCredentials","description", uName, pw);
scp.getCredentials().add(unpwCred);
scp.save();
WorkflowJob wfJob = jenkinsRule.createProject(WorkflowJob.class, "PipTestPipeline");
wfJob.setDefinition(new CpsFlowDefinition(pipelineScript.replace("%repoForTest", repo), true));
jenkinsRule.buildAndAssertSuccess(wfJob);
}
示例13: cleanCloudSpace
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Before
public void cleanCloudSpace() throws IOException {
client.deleteAllApplications();
client.deleteAllServices();
CredentialsStore store = CredentialsProvider.lookupStores(j.getInstance()).iterator().next();
store.addCredentials(Domain.global(),
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "testCredentialsId", "",
TEST_USERNAME, TEST_PASSWORD));
}
示例14: globalConfigRoundtrip
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void globalConfigRoundtrip() throws Exception {
// Create fake credentials, so they are selectable on configuration for during configuration roundtrip
final CredentialsStore store = CredentialsProvider.lookupStores(jenkins.getInstance()).iterator().next();
DockerServerCredentials dc = new DockerServerCredentials(SYSTEM, "credentialsId", "test", null, null, null);
store.addCredentials(Domain.global(), dc);
UsernamePasswordCredentials rc = new UsernamePasswordCredentialsImpl(SYSTEM, "pullCredentialsId", null, null, null);
store.addCredentials(Domain.global(), rc);
final DockerTemplate template = new DockerTemplate(
new DockerTemplateBase("image", "pullCredentialsId", "dnsStirng", "network",
"dockerCommand", "volumesString", "volumesFroString", "environmentString",
"hostname", 128, 256, 42, "bindPorts", true, true, true, "macAddress", "extraHostsString"),
new DockerComputerAttachConnector("jenkins"),
"labelString", "remoteFs", "10");
template.setPullStrategy(DockerImagePullStrategy.PULL_NEVER);
template.setMode(Node.Mode.NORMAL);
template.setRemoveVolumes(true);
template.setRetentionStrategy(new DockerOnceRetentionStrategy(33));
DockerCloud cloud = new DockerCloud("docker", new DockerAPI(new DockerServerEndpoint("uri", "credentialsId")),
Collections.singletonList(template));
jenkins.getInstance().clouds.replaceBy(Collections.singleton(cloud));
jenkins.configRoundtrip();
Assert.assertEquals(cloud, jenkins.getInstance().clouds.get(0));
}
示例15: shouldRetrieveOverridingCredentialFromProject
import com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl; //导入依赖的package包/类
@Test
public void shouldRetrieveOverridingCredentialFromProject() throws Exception {
Folder f = r.jenkins.createProject(Folder.class, "folder1");
UsernamePasswordCredentialsImpl credentials =
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, ID, DESCRIPTION, USERNAME,
PASSWORD);
getFolderStore(f).addCredentials(Domain.global(), credentials);
// Matches what's sent from ui
Credential overridingCredentialProvided = new Credential(null, "", null, credentials.getId(), null, true);
DeployitNotifier.DeployitDescriptor descriptor = new DeployitNotifier.DeployitDescriptor();
DeployitNotifier notifierSpy = spy(new DeployitNotifier("AdminGlobal1", "app1", null, null, null, null, false, null, overridingCredentialProvided));
doReturn(descriptor).when(notifierSpy).getDescriptor();
doReturn(overridingCredentialProvided).when(notifierSpy).getOverridingCredential();
FreeStyleProject freeStyleProjectSpy = spy(new FreeStyleProject(f, "folder1/proj1"));
freeStyleProjectSpy.addPublisher(notifierSpy);
DescribableList<Publisher, Descriptor<Publisher>> publisherListMock = mock(DescribableList.class);
doReturn(notifierSpy).when(publisherListMock).get(any(DeployitNotifier.DeployitDescriptor.class));
doReturn(publisherListMock).when(freeStyleProjectSpy).getPublishersList();
Credential overridingCredential = RepositoryUtils.retrieveOverridingCredentialFromProject(freeStyleProjectSpy);
assertEquals(USERNAME, overridingCredential.getUsername());
assertEquals(PASSWORD, overridingCredential.getPassword().getPlainText());
}