本文整理汇总了Java中com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials类的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordCredentials类的具体用法?Java UsernamePasswordCredentials怎么用?Java UsernamePasswordCredentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UsernamePasswordCredentials类属于com.cloudbees.plugins.credentials.common包,在下文中一共展示了UsernamePasswordCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doUpdate
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
/**
* Construct a Marathon client based on the provided credentialsId and execute an update for the configuration's
* Marathon application.
*
* @param credentialsId A string ID for a credential within Jenkin's Credential store
* @throws MarathonException thrown if the Marathon service has an error
*/
private void doUpdate(final String credentialsId) throws MarathonException {
final Credentials credentials = MarathonBuilderUtils.getJenkinsCredentials(credentialsId, Credentials.class);
Marathon client;
if (credentials instanceof UsernamePasswordCredentials) {
client = getMarathonClient((UsernamePasswordCredentials) credentials);
} else if (credentials instanceof StringCredentials) {
client = getMarathonClient((StringCredentials) credentials);
} else {
client = getMarathonClient();
}
if (client != null) {
client.updateApp(getApp().getId(), getApp(), config.getForceUpdate());
}
}
示例2: doCheckCredentialsId
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public FormValidation doCheckCredentialsId(@QueryParameter final String credentialsId,
@AncestorInPath final Job<?,?> owner) {
String globalCredentialsId = this.getGlobalCredentialsId();
if (credentialsId == null || credentialsId.isEmpty()) {
if (globalCredentialsId == null || globalCredentialsId.isEmpty()) {
return FormValidation.error("Please enter Bitbucket OAuth credentials");
} else {
return this.doCheckGlobalCredentialsId(this.getGlobalCredentialsId());
}
}
UsernamePasswordCredentials credentials = BitbucketBuildStatusHelper.getCredentials(credentialsId, owner);
return this.checkCredentials(credentials);
}
开发者ID:jenkinsci,项目名称:bitbucket-build-status-notifier-plugin,代码行数:17,代码来源:BitbucketBuildStatusNotifier.java
示例3: checkCredentials
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
private FormValidation checkCredentials(UsernamePasswordCredentials credentials) {
try {
OAuthConfig config = new OAuthConfig(credentials.getUsername(), credentials.getPassword().getPlainText());
BitbucketApiService apiService = (BitbucketApiService) new BitbucketApi().createService(config);
Verifier verifier = null;
Token token = apiService.getAccessToken(OAuthConstants.EMPTY_TOKEN, verifier);
if (token.isEmpty()) {
return FormValidation.error("Invalid Bitbucket OAuth credentials");
}
} catch (Exception e) {
return FormValidation.error(e.getClass() + e.getMessage());
}
return FormValidation.ok();
}
开发者ID:jenkinsci,项目名称:bitbucket-build-status-notifier-plugin,代码行数:18,代码来源:BitbucketBuildStatusNotifier.java
示例4: appendCredentials
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
protected ArgumentListBuilder appendCredentials(ArgumentListBuilder args)
throws IOException, InterruptedException
{
if (credentials instanceof SSHUserPrivateKey) {
SSHUserPrivateKey privateKeyCredentials = (SSHUserPrivateKey)credentials;
key = Utils.createSshKeyFile(key, ws, privateKeyCredentials, copyCredentialsInWorkspace);
args.add("--private-key").add(key);
args.add("-u").add(privateKeyCredentials.getUsername());
if (privateKeyCredentials.getPassphrase() != null) {
script = Utils.createSshAskPassFile(script, ws, privateKeyCredentials, copyCredentialsInWorkspace);
environment.put("SSH_ASKPASS", script.getRemote());
// inspired from https://github.com/jenkinsci/git-client-plugin/pull/168
// but does not work with MacOSX
if (! environment.containsKey("DISPLAY")) {
environment.put("DISPLAY", ":123.456");
}
}
} else if (credentials instanceof UsernamePasswordCredentials) {
args.add("-u").add(credentials.getUsername());
args.add("-k");
}
return args;
}
示例5: getCredentials
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
/**
* Looks up the credentialsID attached to this object in the Global Credentials plugin datastore
* @return the matched credentials
*/
private UsernamePasswordCredentials getCredentials() {
String credetialId = this.getCreds();
StandardUsernameCredentials matchedCredentials = null;
Item item = null;
List<StandardUsernameCredentials> listOfCredentials = CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());
for (StandardUsernameCredentials cred : listOfCredentials) {
if (credetialId.equals(cred.getId())) {
matchedCredentials = cred;
break;
}
}
// now we have matchedCredentials.getPassword() and matchedCredentials.getUsername();
return (UsernamePasswordCredentials) matchedCredentials;
}
示例6: doFillCredsItems
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public static ListBoxModel doFillCredsItems() {
StandardUsernameListBoxModel model = new StandardUsernameListBoxModel();
Item item = Stapler.getCurrentRequest().findAncestorObject(Item.class);
List<StandardUsernameCredentials> listOfAllCredentails = CredentialsProvider.lookupCredentials(
StandardUsernameCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());
List<StandardUsernameCredentials> listOfSandardUsernameCredentials = new ArrayList<StandardUsernameCredentials>();
// since we only care about 'UsernamePasswordCredentials' objects, lets seek those out and ignore the rest.
for (StandardUsernameCredentials c : listOfAllCredentails) {
if (c instanceof UsernamePasswordCredentials) {
listOfSandardUsernameCredentials.add(c);
}
}
model.withAll(listOfSandardUsernameCredentials);
return model;
}
示例7: userConfig
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
private CodeSceneUser userConfig() {
if (credentialsId == null) {
// fallback to the deprecated username and password due the backward compatibility.
return new CodeSceneUser(username, password);
}
final UsernamePasswordCredentials credentials = lookupCredentials(credentialsId);
if (credentials == null) {
throw new IllegalStateException("No CodeScene credentials found for id=" + credentialsId);
}
return new CodeSceneUser(credentials.getUsername(), credentials.getPassword().getPlainText());
}
示例8: given__userPassCredential__when__convert__then__tokenAuth
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
@Test
public void given__userPassCredential__when__convert__then__tokenAuth() throws Exception {
// we use a mock to ensure that java.lang.reflect.Proxy implementations of the credential interface work
UsernamePasswordCredentials credential = Mockito.mock(UsernamePasswordCredentials.class);
Mockito.when(credential.getUsername()).thenReturn("bob");
Mockito.when(credential.getPassword()).thenReturn(Secret.fromString("secret"));
GiteaAuth auth = AuthenticationTokens.convert(GiteaAuth.class, credential);
assertThat(auth, instanceOf(GiteaAuthUser.class));
assertThat(((GiteaAuthUser)auth).getUsername(), is("bob"));
assertThat(((GiteaAuthUser)auth).getPassword(), is("secret"));
}
示例9: getUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public static UsernamePasswordCredentials getUsernamePasswordCredentials() {
String credentialsId = Jenkins.getInstance().getDescriptorByType(
MirrorGatePublisher.DescriptorImpl.class)
.getMirrorgateCredentialsId();
return CredentialsUtils.getJenkinsCredentials(
credentialsId, UsernamePasswordCredentials.class);
}
示例10: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item) {
return new StandardListBoxModel().withEmptySelection().withMatching(
CredentialsMatchers.anyOf(
CredentialsMatchers.instanceOf(StringCredentials.class),
CredentialsMatchers.instanceOf(UsernamePasswordCredentials.class)
),
CredentialsProvider.lookupCredentials(StandardCredentials.class, item, null, Collections.<DomainRequirement>emptyList())
);
}
示例11: doCheckGlobalCredentialsId
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public FormValidation doCheckGlobalCredentialsId(@QueryParameter final String globalCredentialsId) {
if (globalCredentialsId.isEmpty()) {
return FormValidation.ok();
}
Job owner = null;
UsernamePasswordCredentials credentials = BitbucketBuildStatusHelper.getCredentials(globalCredentialsId, owner);
return this.checkCredentials(credentials);
}
开发者ID:jenkinsci,项目名称:bitbucket-build-status-notifier-plugin,代码行数:11,代码来源:BitbucketBuildStatusNotifier.java
示例12: notifyBuildStatus
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public static void notifyBuildStatus(UsernamePasswordCredentials credentials, boolean overrideLatestBuild,
final Run<?, ?> build, final TaskListener listener,
BitbucketBuildStatus buildStatus) throws Exception {
List<BitbucketBuildStatusResource> buildStatusResources = createBuildStatusResources(build);
Run<?, ?> prevBuild = build.getPreviousBuild();
List<BitbucketBuildStatusResource> prevBuildStatusResources = new ArrayList<BitbucketBuildStatusResource>();
if (prevBuild != null && prevBuild.getResult() != null && prevBuild.getResult() == Result.ABORTED) {
prevBuildStatusResources = createBuildStatusResources(prevBuild);
}
for (BitbucketBuildStatusResource buildStatusResource : buildStatusResources) {
// if previous build was manually aborted by the user and revision is the same than the current one
// then update the bitbucket build status resource with current status and current build number
for (BitbucketBuildStatusResource prevBuildStatusResource : prevBuildStatusResources) {
if (prevBuildStatusResource.getCommitId().equals(buildStatusResource.getCommitId())) {
BitbucketBuildStatus prevBuildStatus = createBitbucketBuildStatusFromBuild(prevBuild, overrideLatestBuild);
buildStatus.setKey(prevBuildStatus.getKey());
break;
}
}
sendBuildStatusNotification(credentials, build, buildStatusResource, buildStatus, listener);
}
}
开发者ID:jenkinsci,项目名称:bitbucket-build-status-notifier-plugin,代码行数:29,代码来源:BitbucketBuildStatusHelper.java
示例13: sendBuildStatusNotification
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
public static void sendBuildStatusNotification(final UsernamePasswordCredentials credentials,
final Run<?, ?> build,
final BitbucketBuildStatusResource buildStatusResource,
final BitbucketBuildStatus buildStatus,
final TaskListener listener) throws Exception {
if (credentials == null) {
throw new Exception("Credentials could not be found!");
}
OAuthConfig config = new OAuthConfig(credentials.getUsername(), credentials.getPassword().getPlainText());
BitbucketApiService apiService = (BitbucketApiService) new BitbucketApi().createService(config);
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(BitbucketBuildStatus.class, new BitbucketBuildStatusSerializer());
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
OAuthRequest request = new OAuthRequest(Verb.POST, buildStatusResource.generateUrl(Verb.POST));
request.addHeader("Content-type", "application/json");
request.addPayload(gson.toJson(buildStatus));
Token token = apiService.getAccessToken(OAuthConstants.EMPTY_TOKEN, null);
apiService.signRequest(token, request);
Response response = request.send();
logger.info("This request was sent: " + request.getBodyContents());
logger.info("This response was received: " + response.getBody());
listener.getLogger().println("Sending build status " + buildStatus.getState() +
" for commit " + buildStatusResource.getCommitId() + " to BitBucket is done!");
}
开发者ID:jenkinsci,项目名称:bitbucket-build-status-notifier-plugin,代码行数:32,代码来源:BitbucketBuildStatusHelper.java
示例14: smokes
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的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"))));
}
示例15: convert
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入依赖的package包/类
@NonNull
@Override
public DigestToken convert(@NonNull UsernamePasswordCredentials credential)
throws AuthenticationTokenException {
// this is so totally insecure as a token, but it works as an example
return new DigestToken(Util.getDigestOf(
String.format("%s:%s", credential.getUsername(), credential.getPassword().getPlainText())));
}