当前位置: 首页>>代码示例>>Java>>正文


Java Credentials类代码示例

本文整理汇总了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());
    }
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:25,代码来源:MarathonBuilderImpl.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:pipeline-maven-plugin,代码行数:21,代码来源:MaskPasswordsConsoleLogFilter.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:pipeline-maven-plugin,代码行数:19,代码来源:WithMavenStepExecution.java

示例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;
}
 
开发者ID:KostyaSha,项目名称:yet-another-docker-plugin,代码行数:17,代码来源:DockerAuthConfig.java

示例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;
}
 
开发者ID:KostyaSha,项目名称:yet-another-docker-plugin,代码行数:28,代码来源:DockerBuildImage.java

示例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)
    );
}
 
开发者ID:BBVA,项目名称:mirrorgate-jenkins-builds-collector,代码行数:23,代码来源:CredentialsUtils.java

示例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;
}
 
开发者ID:awslabs,项目名称:aws-codebuild-jenkins-plugin,代码行数:12,代码来源:CodeBuilder.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:28,代码来源:DcosAuthImpl.java

示例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;
    }
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:9,代码来源:TokenAuthProvider.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:40,代码来源:TokenAuthProvider.java

示例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)
    );
}
 
开发者ID:jenkinsci,项目名称:marathon-plugin,代码行数:18,代码来源:MarathonBuilderUtils.java

示例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));
}
 
开发者ID:taylorp36,项目名称:jenkins-spark-notifier-plugin,代码行数:10,代码来源:SparkNotifyBuilder.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:authentication-tokens-plugin,代码行数:36,代码来源:AuthenticationTokenSource.java

示例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)
    );
}
 
开发者ID:KostyaSha,项目名称:yet-another-docker-plugin,代码行数:18,代码来源:ClientBuilderForConnector.java

示例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()));
}
 
开发者ID:carlossg,项目名称:jenkins-kubernetes-plugin,代码行数:13,代码来源:KubernetesTest.java


注:本文中的com.cloudbees.plugins.credentials.Credentials类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。