/** * @deprecated Use MesosCloud#getCredentials().getUsername() instead. * @return */ @Deprecated public String getPrincipal() { StandardUsernamePasswordCredentials credentials = getCredentials(); return credentials == null ? "jenkins" : credentials.getUsername(); }
private File createUsernameFile(StandardUsernamePasswordCredentials userPass) throws IOException { File usernameFile = createTempFile("username", ".txt"); try (PrintWriter w = new PrintWriter(usernameFile, "UTF-8")) { w.println(userPass.getUsername()); } return usernameFile; }
public String getUsername() { return this.getCredentials().getUsername(); }
static String createAuthorization(final StandardUsernamePasswordCredentials credentials) { final String username = credentials.getUsername(); final Secret secretPassword = credentials.getPassword(); final String password = secretPassword.getPlainText(); final String credPair = username + ":" + password; final byte[] credBytes = credPair.getBytes(MediaType.UTF_8); final String base64enc = DatatypeConverter.printBase64Binary(credBytes); final String result = "Basic " + base64enc; return result; }
@DataBoundConstructor public ReleaseManagementCI(String collectionUrl, String projectName, String releaseDefinitionName, String credentialsId) { if (collectionUrl.endsWith("/")) { this.collectionUrl = collectionUrl; } else { this.collectionUrl = collectionUrl + "/"; } this.projectName = projectName; this.releaseDefinitionName = releaseDefinitionName; StandardUsernamePasswordCredentials credential = TeamCollectionConfiguration.findCredentialsById(credentialsId); this.username = credential == null ? "" : credential.getUsername(); this.password = credential == null ? Secret.fromString("") : credential.getPassword(); this.credentialsId = credentialsId; }
@Override public StandardCredentials toCredentials(ModelObject context, String description) throws IOException { for (StandardUsernamePasswordCredentials c : CredentialsProvider.lookupCredentials( StandardUsernamePasswordCredentials.class, findItemGroup(context), ACL.SYSTEM, Collections.<DomainRequirement>emptyList())) { if (userName.equals(c.getUsername()) && getPassword().equals(c.getPassword().getPlainText())) { return c; } } return null; }
@Override public CloseableHttpClient authenticate(HttpClientBuilder clientBuilder, HttpContext context, HttpRequestBase requestBase, PrintStream logger) throws IOException, InterruptedException { return auth(clientBuilder, context, requestBase, credential.getUsername(), credential.getPassword().getPlainText()); }
public static Server create(final Launcher launcher, final TaskListener taskListener, final String url, final StandardUsernamePasswordCredentials credentials, final WebProxySettings webProxySettings, final ExtraSettings extraSettings) throws IOException { final String username; final String userPassword; if (credentials == null) { username = null; userPassword = null; } else { username = credentials.getUsername(); final Secret password = credentials.getPassword(); userPassword = password.getPlainText(); } return new Server(launcher, taskListener, url, username, userPassword, webProxySettings, extraSettings); }
protected Object readResolve() { if (StringUtils.isNotBlank(collectionUrl) && password != null && StringUtils.isNotBlank(password.getPlainText())) { try { final URI uri = new URI(collectionUrl); String hostName = uri.getHost(); List<StandardUsernamePasswordCredentials> credentials = TeamCollectionConfiguration.findCredentials(hostName); for (StandardUsernamePasswordCredentials credential : credentials) { if ((StringUtils.isBlank(username) || credential.getUsername().equals(username)) && credential.getPassword().getPlainText().equals(password.getPlainText())) { this.credentialsId = credential.getId(); return this; } } this.credentialsId = TeamCollectionConfiguration.setCredentials(hostName, username, password.getPlainText()); } catch (Exception ex) { logger.log(Level.WARNING, String.format("Get or generate credentials for collection url: %s and username: %s failed.", collectionUrl, username), ex); } } return this; }
return listBoxModel; String username = credential.getUsername(); Secret password = credential.getPassword();
String username = credential.getUsername(); Secret password = credential.getPassword();
if (credentials instanceof StandardUsernamePasswordCredentials) { StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials; builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText()); } else { return FormValidation.error("No username/password credentials provided");
private static GitHubBuilder getBuilder(Item context, String serverAPIUrl, String credentialsId) { GitHubBuilder builder = new GitHubBuilder() .withEndpoint(serverAPIUrl) .withConnector(new HttpConnectorWithJenkinsProxy()); String contextName = context == null ? "(Jenkins.instance)" : context.getFullDisplayName(); if (StringUtils.isEmpty(credentialsId)) { LOGGER.log(Level.WARNING, "credentialsId not set for context {0}, using anonymous connection", contextName); return builder; } StandardCredentials credentials = Ghprb.lookupCredentials(context, credentialsId, serverAPIUrl); if (credentials == null) { LOGGER.log(Level.SEVERE, "Failed to look up credentials for context {0} using id: {1}", new Object[] {contextName, credentialsId}); } else if (credentials instanceof StandardUsernamePasswordCredentials) { LOGGER.log(Level.FINEST, "Using username/password for context {0}", contextName); StandardUsernamePasswordCredentials upCredentials = (StandardUsernamePasswordCredentials) credentials; builder.withPassword(upCredentials.getUsername(), upCredentials.getPassword().getPlainText()); } else if (credentials instanceof StringCredentials) { LOGGER.log(Level.FINEST, "Using OAuth token for context {0}", contextName); StringCredentials tokenCredentials = (StringCredentials) credentials; builder.withOAuthToken(tokenCredentials.getSecret().getPlainText()); } else { LOGGER.log(Level.SEVERE, "Unknown credential type for context {0} using id: {1}: {2}", new Object[] {contextName, credentialsId, credentials.getClass().getName()}); return null; } return builder; }
creds.getUsername(), creds.getPassword().getPlainText(), agent.getPublicDNSName(),
/** * get IAM or UAA token based on the credentials id, only used by freestyle job's test connection or get the policy list * @param iamAPI * @param targetAPI * @param credentials * @return IAM token when user is using apikey, otherwise return UAA token * @throws Exception */ public static String getTokenForFreeStyleJob(StandardCredentials credentials, String iamAPI, String targetAPI, PrintStream printStream) throws Exception { try { if (credentials instanceof StandardUsernamePasswordCredentials) { // if it is the Jenkins username/password type StandardUsernamePasswordCredentials c = (StandardUsernamePasswordCredentials) credentials; if (c.getUsername().equals("apikey")) { // user is using apikey, get IAM token return getIAMToken(c.getPassword().getPlainText(), iamAPI, printStream); } else { // user is using username/pw, get UAA token return getBluemixToken(c.getUsername(), c.getPassword().getPlainText(), targetAPI, printStream); } } else { // if it is the standard type StringCredentialsImpl value = (StringCredentialsImpl) credentials; return getIAMToken(value.getSecret().getPlainText(), iamAPI, printStream); } } catch (Exception e) { throw new Exception(getMessage(LOGIN_IN_FAIL) + "\n" + e.getMessage()); } }
((CredentialItem.Username) i).setValue(_cred.getUsername()); continue;
credentials.getUsername(), credentials.getPassword().getPlainText(), releaseRepository.getTargetRepoPrivateUri(),
/** * Populates the credential of a JClouds ContextBuilder from a credentials record. * @param cb The {@link org.jclouds.ContextBuilder} which should get the credential. * @param id The Id of the credentials object. * @return The modified {@link org.jclouds.ContextBuilder} */ public static ContextBuilder setCredentials(final ContextBuilder cb, final String id) { StandardUsernameCredentials u = getCredentialsById(id); if (null != u) { if (u instanceof OpenstackKeystoneV3) { OpenstackKeystoneV3 ok3 = (OpenstackKeystoneV3)u; String domainname = ok3.getDomain().isEmpty() ? "default" : ok3.getDomain(); return cb.credentials(domainname + ":" + ok3.getUsername(), getPassword(ok3.getPassword())); } else if (u instanceof StandardUsernamePasswordCredentials) { StandardUsernamePasswordCredentials up = (StandardUsernamePasswordCredentials)u; return cb.credentials(up.getUsername(), getPassword(up.getPassword())); } else if (u instanceof SSHUserPrivateKey) { SSHUserPrivateKey up = (SSHUserPrivateKey)u; return cb.credentials(up.getUsername(), getPrivateKey(up)); } throw new RuntimeException("invalid credentials type"); } throw new RuntimeException("Could not retrieve credentials"); }
AmazonWebServicesCredentials.class, run, Collections.emptyList()); if (usernamePasswordCredentials != null) { localEnv.override(AWSClientFactory.AWS_ACCESS_KEY_ID, usernamePasswordCredentials.getUsername()); localEnv.override(AWSClientFactory.AWS_SECRET_ACCESS_KEY, usernamePasswordCredentials.getPassword().getPlainText()); } else if (amazonWebServicesCredentials != null) {
public <T extends ApiClient.HttpClientFactory> void init(ApiClient client, T httpFactory) { this.trigger = this.builder.getTrigger(); if (client == null) { String username = trigger.getUsername(); String password = trigger.getPassword(); StandardUsernamePasswordCredentials credentials = getCredentials(trigger.getCredentialsId()); if (credentials != null) { username = credentials.getUsername(); password = credentials.getPassword().getPlainText(); } if (this.trigger.isCloud()) { this.client = createCloudClient(httpFactory, username, password); } else { this.client = createServerClient(httpFactory, username, password); } } else this.client = client; }