本文整理汇总了Java中com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials.getUsername方法的典型用法代码示例。如果您正苦于以下问题:Java UsernamePasswordCredentials.getUsername方法的具体用法?Java UsernamePasswordCredentials.getUsername怎么用?Java UsernamePasswordCredentials.getUsername使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials
的用法示例。
在下文中一共展示了UsernamePasswordCredentials.getUsername方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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
示例2: 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());
}
示例3: 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
示例4: convert
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入方法依赖的package包/类
@NonNull
@Override
public DockerRegistryToken convert(UsernamePasswordCredentials c) throws AuthenticationTokenException {
return new DockerRegistryToken(c.getUsername(),
Base64.encodeBase64String((c.getUsername() + ":" + c.getPassword().getPlainText())
.getBytes(Charsets.UTF_8)));
}
开发者ID:jenkinsci,项目名称:docker-commons-plugin,代码行数:8,代码来源:UsernamePasswordDockerRegistryTokenSource.java
示例5: convert
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@NonNull
@Override
public GiteaAuthUser convert(@NonNull UsernamePasswordCredentials credential) throws AuthenticationTokenException {
return new GiteaAuthUser(credential.getUsername(), credential.getPassword().getPlainText());
}
示例6: setCredentials
import com.cloudbees.plugins.credentials.common.UsernamePasswordCredentials; //导入方法依赖的package包/类
/**
* Set the user section of the kube configuration file.
*
* @throws IOException on file operations
* @throws InterruptedException on file operations
*/
private void setCredentials(String configFile) throws IOException, InterruptedException {
Set<String> tempFiles = newHashSet();
final StandardCredentials credentials = getCredentials(build);
String credentialsArgs;
int sensitiveFieldsCount = 1;
if (credentials == null) {
throw new AbortException("No credentials defined to setup Kubernetes CLI");
} else if (credentials instanceof TokenProducer) {
credentialsArgs = "--token=\"" + ((TokenProducer) credentials).getToken(serverUrl, null, true) + "\"";
} else if (credentials instanceof StringCredentials) {
credentialsArgs = "--token=\"" + ((StringCredentials) credentials).getSecret() + "\"";
} else if (credentials instanceof UsernamePasswordCredentials) {
UsernamePasswordCredentials upc = (UsernamePasswordCredentials) credentials;
credentialsArgs = "--username=\"" + upc.getUsername() + "\" --password=\"" + Secret.toString(upc.getPassword()) + "\"";
} else if (credentials instanceof StandardCertificateCredentials) {
sensitiveFieldsCount = 0;
FilePath clientCrtFile = workspace.createTempFile("client", "crt");
FilePath clientKeyFile = workspace.createTempFile("client", "key");
CertificateHelper.extractFromCertificate((StandardCertificateCredentials) credentials, clientCrtFile, clientKeyFile);
tempFiles.add(clientCrtFile.getRemote());
tempFiles.add(clientKeyFile.getRemote());
credentialsArgs = "--embed-certs=true --client-certificate=" + clientCrtFile.getRemote() + " --client-key="
+ clientKeyFile.getRemote();
} else {
throw new AbortException("Unsupported Credentials type " + credentials.getClass().getName());
}
String[] cmds = QuotedStringTokenizer.tokenize(String.format("%s config set-credentials %s %s",
KUBECTL_BINARY,
USERNAME,
credentialsArgs));
int status = launcher.launch()
.envs(String.format("KUBECONFIG=%s", configFile))
.cmds(cmds)
.masks(getMasks(cmds.length, sensitiveFieldsCount))
.stdout(launcher.getListener())
.join();
if (status != 0) throw new IOException("Failed to add kubectl credentials (exit code " + status + ")");
for (String tempFile : tempFiles) {
workspace.child(tempFile).delete();
}
}