本文整理匯總了Java中com.cloudbees.plugins.credentials.CredentialsProvider類的典型用法代碼示例。如果您正苦於以下問題:Java CredentialsProvider類的具體用法?Java CredentialsProvider怎麽用?Java CredentialsProvider使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CredentialsProvider類屬於com.cloudbees.plugins.credentials包,在下文中一共展示了CredentialsProvider類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getCredentials
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Get the {@link StandardCredentials}.
*
* @return the credentials matching the {@link #credentialsId} or {@code null} is {@code #credentialsId} is blank
* @throws AbortException if no {@link StandardCredentials} matching {@link #credentialsId} is found
*/
private StandardCredentials getCredentials(Run<?, ?> build) throws AbortException {
if (StringUtils.isBlank(credentialsId)) {
return null;
}
StandardCredentials result = CredentialsProvider.findCredentialById(
credentialsId,
StandardCredentials.class,
build,
Collections.<DomainRequirement>emptyList());
if (result == null) {
throw new AbortException("No credentials found for id \"" + credentialsId + "\"");
}
return result;
}
示例2: testBasicWithCa
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
@Test
public void testBasicWithCa() throws Exception {
String encodedCertificate = new String(Base64.getEncoder().encode(CA_CERTIFICATE.getBytes()));
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("certificate-authority-data: " + encodedCertificate));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例3: testBasicWithoutCa
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
@Test
public void testBasicWithoutCa() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredential());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testBasicWithoutCa");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogContains("kubectl configuration cleaned up", b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("insecure-skip-tls-verify: true"));
assertTrue(configDumpContent.contains("server: " + SERVER_URL));
}
示例4: testUsernamePasswordCredentials
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
@Test
public void testUsernamePasswordCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), usernamePasswordCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testUsernamePasswordCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("username: " + USERNAME_WITH_SPACE));
assertTrue(configDumpContent.contains("password: " + PASSWORD_WITH_SPACE));
}
示例5: testSecretCredentials
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
@Test
public void testSecretCredentials() throws Exception {
CredentialsProvider.lookupStores(r.jenkins).iterator().next().addCredentials(Domain.global(), secretCredentialWithSpace());
WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "testSecretCredentials");
p.setDefinition(new CpsFlowDefinition(loadResource("kubectlWithoutCa.groovy"), true));
WorkflowRun b = p.scheduleBuild2(0).waitForStart();
assertNotNull(b);
r.assertBuildStatusSuccess(r.waitForCompletion(b));
r.assertLogNotContains(PASSWORD_WITH_SPACE, b);
FilePath configDump = r.jenkins.getWorkspaceFor(p).child("configDump");
assertTrue(configDump.exists());
String configDumpContent = configDump.readToString().trim();
assertTrue(configDumpContent.contains("token: " + PASSWORD_WITH_SPACE));
}
示例6: doFillPrincipalCredentialIdItems
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
public ListBoxModel doFillPrincipalCredentialIdItems(
@AncestorInPath Item item,
@QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (item == null) {
if (!Jenkins.getActiveInstance().hasPermission(Jenkins.ADMINISTER)) {
return result.includeCurrentValue(credentialsId);
}
} else {
if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.includeCurrentValue(credentialsId);
}
}
List<AzureCredentials> creds = CredentialsProvider.lookupCredentials(AzureCredentials.class, item, ACL.SYSTEM, Collections.<DomainRequirement>emptyList());
for (AzureCredentials cred
:
creds) {
result.add(cred.getId());
}
return result.includeEmptyValue()
.includeCurrentValue(credentialsId);
}
示例7: doFillMirrorgateCredentialsIdItems
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
public ListBoxModel doFillMirrorgateCredentialsIdItems(
@AncestorInPath Item item,
@QueryParameter("mirrorgateCredentialsId") String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (item == null) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return result.includeCurrentValue(credentialsId);
}
} else if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.includeCurrentValue(credentialsId);
}
return result
.includeEmptyValue()
.includeAs(ACL.SYSTEM, item, StandardUsernamePasswordCredentials.class);
}
示例8: doCheckMirrorgateCredentialsId
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
public FormValidation doCheckMirrorgateCredentialsId(
@AncestorInPath Item item,
@QueryParameter("mirrorgateCredentialsId") String credentialsId) {
if (item == null) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return FormValidation.ok();
}
} else if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return FormValidation.ok();
}
if (StringUtils.isBlank(credentialsId)) {
return FormValidation.ok();
}
if (credentialsId.startsWith("${") && credentialsId.endsWith("}")) {
return FormValidation.warning(
"Cannot validate expression based credentials");
}
return FormValidation.ok();
}
示例9: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Fills in the Login Credentials selection box with applicable connections.
*
* @param context
* filter for login credentials
* @param credentialsId
* existing login credentials; can be null
* @param project
* the Jenkins project
*
* @return login credentials selection
*/
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Jenkins context, @QueryParameter String credentialsId,
@AncestorInPath Item project)
{
List<StandardUsernamePasswordCredentials> creds = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM,
Collections.<DomainRequirement> emptyList());
ListBoxModel model = new ListBoxModel();
model.add(new Option(StringUtils.EMPTY, StringUtils.EMPTY, false));
for (StandardUsernamePasswordCredentials c : creds)
{
boolean isSelected = false;
if (credentialsId != null)
{
isSelected = credentialsId.matches(c.getId());
}
String description = Util.fixEmptyAndTrim(c.getDescription());
model.add(new Option(c.getUsername() + (description != null ? " (" + description + ')' : StringUtils.EMPTY), //$NON-NLS-1$
c.getId(), isSelected));
}
return model;
}
示例10: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Fills in the Login Credentials selection box with applicable Jenkins credentials.
*
* @param context
* filter for credentials
* @param credentialsId
* existing login credentials; can be null
* @param project
* the Jenkins project
*
* @return credential selections
*/
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Jenkins context, @QueryParameter String credentialsId, @AncestorInPath Item project)
{
List<StandardUsernamePasswordCredentials> creds = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM,
Collections.<DomainRequirement> emptyList());
StandardListBoxModel model = new StandardListBoxModel();
model.add(new Option(StringUtils.EMPTY, StringUtils.EMPTY, false));
for (StandardUsernamePasswordCredentials c : creds)
{
boolean isSelected = false;
if (credentialsId != null)
{
isSelected = credentialsId.matches(c.getId());
}
String description = Util.fixEmptyAndTrim(c.getDescription());
model.add(new Option(c.getUsername() + (description != null ? " (" + description + ')' : StringUtils.EMPTY), //$NON-NLS-1$
c.getId(), isSelected));
}
return model;
}
示例11: getLoginInformation
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Retrieves login information given a credential ID.
*
* @param project
* the Jenkins project
*
* @return a Jenkins credential with login information
*/
protected StandardUsernamePasswordCredentials getLoginInformation(Item project)
{
StandardUsernamePasswordCredentials credential = null;
List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());
IdMatcher matcher = new IdMatcher(getCredentialsId());
for (StandardUsernamePasswordCredentials c : credentials)
{
if (matcher.matches(c))
{
credential = c;
}
}
return credential;
}
示例12: getLoginInformation
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Retrieves login information given a credential ID
*
* @param project
* the Jenkins project
*
* @return a Jenkins credential with login information
*/
protected StandardUsernamePasswordCredentials getLoginInformation(Item project)
{
StandardUsernamePasswordCredentials credential = null;
List<StandardUsernamePasswordCredentials> credentials = CredentialsProvider.lookupCredentials(
StandardUsernamePasswordCredentials.class, project, ACL.SYSTEM, Collections.<DomainRequirement> emptyList());
IdMatcher matcher = new IdMatcher(getCredentialsId());
for (StandardUsernamePasswordCredentials c : credentials)
{
if (matcher.matches(c))
{
credential = c;
}
}
return credential;
}
示例13: testRecorderInvalidToken
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
/**
* Test that a JSON credential without a "jenkins_token" field and without a proper DC/OS service account value
* results in a 401 and only 1 web request.
*
* @throws Exception
*/
@Test
public void testRecorderInvalidToken() throws Exception {
final FreeStyleProject project = j.createFreeStyleProject();
final SystemCredentialsProvider.ProviderImpl system = ExtensionList.lookup(CredentialsProvider.class).get(SystemCredentialsProvider.ProviderImpl.class);
final CredentialsStore systemStore = system.getStore(j.getInstance());
final String credentialValue = "{\"field1\":\"some value\"}";
final Secret secret = Secret.fromString(credentialValue);
final StringCredentials credential = new StringCredentialsImpl(CredentialsScope.GLOBAL, "invalidtoken", "a token for JSON token test", secret);
TestUtils.enqueueFailureResponse(httpServer, 401);
systemStore.addCredentials(Domain.global(), credential);
addBuilders(TestUtils.loadFixture("idonly.json"), project);
// add post-builder
addPostBuilders(project, "invalidtoken");
final FreeStyleBuild build = j.assertBuildStatus(Result.FAILURE, project.scheduleBuild2(0).get());
j.assertLogContains("[Marathon] Authentication to Marathon instance failed:", build);
j.assertLogContains("[Marathon] Invalid DC/OS service account JSON", build);
assertEquals("Only 1 request should have been made.", 1, httpServer.getRequestCount());
}
示例14: checkForDuplicates
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
@CheckForNull
private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) {
for (CredentialsStore store : CredentialsProvider.lookupStores(object)) {
if (!store.hasPermission(CredentialsProvider.VIEW)) {
continue;
}
ModelObject storeContext = store.getContext();
for (Domain domain : store.getDomains()) {
if (CredentialsMatchers.firstOrNull(store.getCredentials(domain), CredentialsMatchers.withId(value))
!= null) {
if (storeContext == context) {
return FormValidation.error("This ID is already in use");
} else {
return FormValidation.warning("The ID ‘%s’ is already in use in %s", value,
storeContext instanceof Item
? ((Item) storeContext).getFullDisplayName()
: storeContext.getDisplayName());
}
}
}
}
return null;
}
示例15: doFillCredentialsIdItems
import com.cloudbees.plugins.credentials.CredentialsProvider; //導入依賴的package包/類
public ListBoxModel doFillCredentialsIdItems(@AncestorInPath Item item, @QueryParameter String credentialsId) {
StandardListBoxModel result = new StandardListBoxModel();
if (item == null) {
if (!Jenkins.getInstance().hasPermission(Jenkins.ADMINISTER)) {
return result.add(credentialsId);
}
} else {
if (!item.hasPermission(Item.EXTENDED_READ)
&& !item.hasPermission(CredentialsProvider.USE_ITEM)) {
return result.add(credentialsId);
}
}
return result
.withEmptySelection()
.withAll(CredentialsProvider.lookupCredentials(StandardUsernamePasswordCredentials.class, item, null, Collections.<DomainRequirement>emptyList()))
.withMatching(CredentialsMatchers.withId(credentialsId));
}