本文整理汇总了Java中com.cloudbees.plugins.credentials.Credentials类的典型用法代码示例。如果您正苦于以下问题:Java Credentials类的具体用法?Java Credentials怎么用?Java Credentials使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Credentials类属于com.cloudbees.plugins.credentials包,在下文中一共展示了Credentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doUpdate
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的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: toString
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
@Nonnull
protected static Collection<String> toString(@Nonnull Iterable<Credentials> credentials) {
List<String> result = new ArrayList<>();
for (Credentials creds : credentials) {
if (creds instanceof PasswordCredentials) {
PasswordCredentials passwordCredentials = (PasswordCredentials) creds;
result.add(passwordCredentials.getPassword().getPlainText());
} else if (creds instanceof SSHUserPrivateKey) {
SSHUserPrivateKey sshUserPrivateKey = (SSHUserPrivateKey) creds;
Secret passphrase = sshUserPrivateKey.getPassphrase();
if (passphrase != null) {
result.add(passphrase.getPlainText());
}
// omit the private key, there
} else {
LOGGER.log(Level.FINE, "Skip masking of unsupported credentials type {0}: {1}", new Object[]{creds.getClass(), creds.getDescriptor().getDisplayName()});
}
}
return result;
}
示例3: apply
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
@Override
public String apply(@javax.annotation.Nullable Credentials credentials) {
if (credentials == null)
return "null";
String result = ClassUtils.getShortName(credentials.getClass()) + "[";
if (credentials instanceof IdCredentials) {
IdCredentials idCredentials = (IdCredentials) credentials;
result += "id: " + idCredentials.getId() + ",";
}
if (credentials instanceof UsernameCredentials) {
UsernameCredentials usernameCredentials = (UsernameCredentials) credentials;
result += "username: " + usernameCredentials.getUsername() + "";
}
result += "]";
return result;
}
示例4: getAuthConfig
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
@CheckForNull
public AuthConfig getAuthConfig() {
if (StringUtils.isEmpty(credentialsId)) {
return null;
}
if (StringUtils.isNotBlank(credentialsId)) {
// hostname requirements?
Credentials credentials = lookupSystemCredentials(credentialsId);
if (credentials instanceof DockerRegistryAuthCredentials) {
final DockerRegistryAuthCredentials authCredentials = (DockerRegistryAuthCredentials) credentials;
return authCredentials.getAuthConfig();
}
}
return null;
}
示例5: resolveCreds
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Fill additional object with resolved creds.
* For example before transfering object to remote.
*/
public void resolveCreds() {
final AuthConfigurations authConfigs = new AuthConfigurations();
for (Map.Entry<String, String> entry : creds.entrySet()) {
final String registry = entry.getKey();
final String credId = entry.getValue();
final Credentials credentials = ClientBuilderForConnector.lookupSystemCredentials(credId);
if (credentials instanceof UsernamePasswordCredentials) {
final UsernamePasswordCredentials upCreds = (UsernamePasswordCredentials) credentials;
final AuthConfig authConfig = new AuthConfig()
.withRegistryAddress(registry)
.withPassword(upCreds.getPassword())
.withUsername(upCreds.getUserName());
authConfigs.addConfig(authConfig);
} else if (credentials instanceof DockerRegistryAuthCredentials) {
final DockerRegistryAuthCredentials authCredentials = (DockerRegistryAuthCredentials) credentials;
authConfigs.addConfig(
authCredentials.getAuthConfig().withRegistryAddress(registry)
);
}
}
this.authConfigurations = authConfigs;
}
示例6: getJenkinsCredentials
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Get the credentials identified by the given id from the Jenkins
* credential store.
*
* @param <T>
* @param credentialsId The id for the credentials
* @param credentialsClass The class of credentials to return
* @return Jenkins credentials
*/
public static <T extends Credentials> T getJenkinsCredentials(
final String credentialsId, final Class<T> credentialsClass) {
if (StringUtils.isEmpty(credentialsId)) {
return null;
}
return CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(credentialsClass,
Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()),
CredentialsMatchers.withId(credentialsId)
);
}
示例7: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
public ListBoxModel doFillCredentialsIdItems() {
final ListBoxModel selections = new ListBoxModel();
SystemCredentialsProvider s = SystemCredentialsProvider.getInstance();
for (Credentials c: s.getCredentials()) {
if (c instanceof CodeBuildCredentials) {
selections.add(((CodeBuildCredentials) c).getId());
}
}
return selections;
}
示例8: updateTokenCredentials
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
@Override
public boolean updateTokenCredentials(final Credentials tokenCredentials) throws AuthenticationException {
if (tokenCredentials instanceof StringCredentials) {
final StringCredentials oldCredentials = (StringCredentials) tokenCredentials;
if (credentials != null) {
try {
final String token = getToken();
if (token == null) {
// TODO: better message somewhere in getToken flow of what happened?
final String errorMessage = "Failed to retrieve authentication token from DC/OS.";
LOGGER.warning(errorMessage);
throw new AuthenticationException(errorMessage);
}
final StringCredentials updatedCredentials = newTokenCredentials(oldCredentials, token);
return doTokenUpdate(oldCredentials.getId(), updatedCredentials);
} catch (IOException e) {
LOGGER.warning(e.getMessage());
throw new AuthenticationException(e.getMessage());
}
}
} else {
LOGGER.warning("Invalid credential type, expected String Credentials, received: " + tokenCredentials.getClass().getName());
}
return false;
}
示例9: getTokenAuthProvider
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
public static TokenAuthProvider getTokenAuthProvider(final Providers provider, final Credentials credentials) {
switch (provider) {
case DCOS:
return new DcosAuthImpl((StringCredentials) credentials);
default:
return null;
}
}
示例10: doTokenUpdate
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Helper method to update tokenCredentials with contents of creds.
* <p>
* This searches all domains for the id associated with tokenCredentials and updates the first credential it finds.
*
* @param tokenId Existing credentials that should be updated.
* @param creds New credentials
* @throws IOException If problems reading or writing to Jenkins Credential Store
*/
boolean doTokenUpdate(final String tokenId, final Credentials creds) throws IOException {
final SystemCredentialsProvider.ProviderImpl systemProvider = ExtensionList.lookup(CredentialsProvider.class)
.get(SystemCredentialsProvider.ProviderImpl.class);
if (systemProvider == null) return false;
final CredentialsStore credentialsStore = systemProvider.getStore(Jenkins.getInstance());
if (credentialsStore == null) return false;
/*
Walk through all domains and credentials for each domain to find a credential with the matching id.
*/
for (final Domain d : credentialsStore.getDomains()) {
for (Credentials c : credentialsStore.getCredentials(d)) {
if (!(c instanceof StringCredentials)) continue;
final StringCredentials stringCredentials = (StringCredentials) c;
if (stringCredentials.getId().equals(tokenId)) {
final boolean wasUpdated = credentialsStore.updateCredentials(d, c, creds);
if (!wasUpdated) {
LOGGER.warning("Updating Token credential failed during update call.");
}
return wasUpdated;
}
}
}
// if the credential was not found, then put a warning in the console log.
LOGGER.warning("Token credential was not found in the Credentials Store.");
return false;
}
示例11: getJenkinsCredentials
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Get the credentials identified by the given id from the Jenkins credential store.
*
* @param <T> credential type
* @param credentialsId The id for the credentials
* @param credentialsClass The class of credentials to return
* @return Jenkins credentials
*/
public static <T extends Credentials> T getJenkinsCredentials(final String credentialsId, final Class<T> credentialsClass) {
if (StringUtils.isEmpty(credentialsId))
return null;
return CredentialsMatchers.firstOrNull(
CredentialsProvider.lookupCredentials(credentialsClass,
Jenkins.getInstance(), ACL.SYSTEM, Collections.<DomainRequirement>emptyList()),
CredentialsMatchers.withId(credentialsId)
);
}
示例12: getCredentials
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
private Credentials getCredentials(final String credentialsId) {
return firstOrNull(
lookupCredentials(
Credentials.class,
Jenkins.getInstance(),
ACL.SYSTEM,
Collections.<DomainRequirement> emptyList()),
withId(credentialsId));
}
示例13: if
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Score the goodness of match.
* @param tokenClass the token class.
* @param credentials the credentials instance.
* @return the match score (higher the better) or {@code null} if not a match.
* @since 1.1
*/
/*package*/ final Integer score(Class<?> tokenClass, Credentials credentials) {
if (!produces(tokenClass) || !consumes(credentials)) {
return null;
}
short producerScore;
if (this.tokenClass.equals(tokenClass)) {
producerScore = Short.MAX_VALUE;
} else {
if (this.tokenClass.isInterface()) {
// TODO compute a goodness of fit
producerScore = 0;
} else {
producerScore = (short)ClassUtils.getAllSuperclasses(tokenClass).indexOf(this.tokenClass);
}
}
short consumerScore;
if (this.credentialsClass.equals(credentials.getClass())) {
consumerScore = Short.MAX_VALUE;
} else {
if (this.credentialsClass.isInterface()) {
// TODO compute a goodness of fit
consumerScore = 0;
} else {
consumerScore = (short)ClassUtils.getAllSuperclasses(credentials.getClass()).indexOf(this.credentialsClass);
}
}
return ((int)producerScore) << 16 | (int)consumerScore;
}
示例14: lookupSystemCredentials
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的package包/类
/**
* Util method to find credential by id in jenkins
*
* @param credentialsId credentials to find in jenkins
* @return {@link CertificateCredentials} or {@link StandardUsernamePasswordCredentials} expected
*/
public static Credentials lookupSystemCredentials(String credentialsId) {
return firstOrNull(
lookupCredentials(
Credentials.class,
Jenkins.getInstance(),
ACL.SYSTEM,
emptyList()
),
withId(credentialsId)
);
}
示例15: upgradeFrom_1_1
import com.cloudbees.plugins.credentials.Credentials; //导入依赖的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()));
}