@Override protected SystemCredentialsProvider instance(Mapping mapping, ConfigurationContext context) { return SystemCredentialsProvider.getInstance(); }
@Nonnull @Override public Set<Attribute<SystemCredentialsProvider, ?>> describe() { return Collections.singleton( new MultivaluedAttribute<SystemCredentialsProvider, DomainCredentials>("domainCredentials", DomainCredentials.class) .setter( (target, value) -> target.setDomainCredentialsMap(DomainCredentials.asMap(value))) ); }
public static void add(@Nonnull OpenstackCredential openstackCredential) { SystemCredentialsProvider.getInstance().getCredentials().add(openstackCredential); }
/** * {@inheritDoc} */ @NonNull @Override @Exported public List<Domain> getDomains() { return Collections.unmodifiableList(new ArrayList<Domain>( SystemCredentialsProvider.getInstance().getDomainCredentialsMap().keySet() )); }
private static String checkLocalKubernetesToken() { File file = new File(KUBE_TOKEN_PATH); if (file.exists() && file.canRead() ) { try { String token = IOUtils.toString(file.toURI() ); TokenCredentialsImpl kubeServiceToken = new TokenCredentialsImpl(CredentialsScope.SYSTEM, KUBE_SERVICE_TOKEN_ID, "Local Kubernetes service token", Secret.fromString(token) ); SystemCredentialsProvider.getInstance().getCredentials().add(kubeServiceToken); SystemCredentialsProvider.getInstance().save(); return KUBE_SERVICE_TOKEN_ID; } catch (IOException excep) { LOGGER.warning("Unable to read Kubernetes service token file: " + excep); } } return StringUtils.EMPTY; }
Proc p = runSvnServe(getClass().getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Collections.<Credentials>emptyList() )); SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob") SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-bob", null, "bob","bob"),
public static void save() throws IOException { SystemCredentialsProvider.getInstance().save(); } }
final SystemCredentialsProvider credentialsProvider = SystemCredentialsProvider.getInstance(); final Map<Domain, List<Credentials>> credentialsMap = credentialsProvider.getDomainCredentialsMap(); credentialsProvider.setDomainCredentialsMap(credentialsMap); credentialsProvider.save();
public static String setCredentials(final String hostName, String username, String password) { List<DomainSpecification> domainSpecifications = new ArrayList<>(); domainSpecifications.add(new HostnameSpecification(hostName, null)); Domain domain = new Domain("Generated for " + hostName, "", domainSpecifications); SystemCredentialsProvider.getInstance().getDomainCredentialsMap().put(domain, new ArrayList<Credentials>()); String credentialsId; StandardUsernamePasswordCredentials newCredential = new UsernamePasswordCredentialsImpl( CredentialsScope.GLOBAL, credentialsId = UUID.randomUUID().toString(), "Generated for " + username, username, password ); SystemCredentialsProvider.getInstance().getDomainCredentialsMap().get(domain).add(newCredential); try { SystemCredentialsProvider.getInstance().save(); } catch (IOException ex) { LOGGER.log(Level.WARNING, "SystemCredentialsProvider instance save failed: ", ex); } return credentialsId; }
/** * Implementation for {@link StoreImpl} to delegate to while keeping the lock synchronization simple. */ private synchronized boolean removeDomain(@NonNull Domain domain) throws IOException { checkPermission(CredentialsProvider.MANAGE_DOMAINS); Map<Domain, List<Credentials>> domainCredentialsMap = getDomainCredentialsMap(); if (domainCredentialsMap.containsKey(domain)) { domainCredentialsMap.remove(domain); checkedSave(CredentialsProvider.MANAGE_DOMAINS); return true; } return false; }
/** * Short-cut method that redundantly checks the specified permission (to catch any typos) and then escalates * authentication in order to save the {@link CredentialsStore}. * * @param p the permissions of the operation being performed. * @throws IOException if something goes wrong. */ private void checkedSave(Permission p) throws IOException { checkPermission(p); Authentication old = SecurityContextHolder.getContext().getAuthentication(); SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM); try { save(); } finally { SecurityContextHolder.getContext().setAuthentication(old); } }
/** * Get all the credentials. * * @return all the credentials. * @since 1.5 */ @SuppressWarnings("unused") // used by stapler public List<DomainCredentials> getDomainCredentials() { return DomainCredentials.asList(getDomainCredentialsMap()); }
public ListBoxModel doFillCredentialsIdItems() { final ListBoxModel selections = new ListBoxModel(); SystemCredentialsProvider s = SystemCredentialsProvider.getInstance(); Set<String> displayCredentials = new HashSet(); for (Credentials c: s.getCredentials()) { if (c instanceof CodeBuildCredentials) { displayCredentials.add(((CodeBuildCredentials) c).getId()); } } Jenkins instance = Jenkins.getInstance(); if(instance != null) { List<Folder> folders = instance.getAllItems(Folder.class); for(Folder folder: folders) { List<Credentials> creds = CredentialsProvider.lookupCredentials(Credentials.class, (Item) folder); for(Credentials cred: creds) { if (cred instanceof CodeBuildCredentials) { displayCredentials.add(((CodeBuildCredentials) cred).getId()); } } } } for(String credString: displayCredentials) { selections.add(credString); } return selections; }
/** * {@inheritDoc} */ @NonNull @Override @Exported public List<Domain> getDomains() { return Collections.unmodifiableList(new ArrayList<Domain>( SystemCredentialsProvider.getInstance().getDomainCredentialsMap().keySet() )); }
password ); SystemCredentialsProvider.getInstance().getCredentials().add(newCredentials); try { SystemCredentialsProvider.getInstance().save(); LOGGER.log(Level.INFO, "Provided username and password were successfully migrated and stored as {0}", newCredentials.getId()); } catch (IOException e) {
/** * There was a bug that credentials stored in the remote call context was serialized wrongly. */ @Issue("JENKINS-8061") @Test public void remoteBuild() throws Exception { Proc p = runSvnServe(SubversionSCMTest.class.getResource("HUDSON-1379.zip")); try { SystemCredentialsProvider.getInstance().setDomainCredentialsMap(Collections.singletonMap(Domain.global(), Arrays.<Credentials>asList( new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, "1-alice", null, "alice", "alice") ) )); FreeStyleProject b = r.createFreeStyleProject(); b.setScm(new SubversionSCM("svn://localhost/bob", "1-alice", ".")); b.setAssignedNode(r.createSlave()); FreeStyleBuild run = r.buildAndAssertSuccess(b); /* TODO runSvnServe not guaranteed to use port 3690; otherwise this works: assertLogContains(Messages.CredentialsSVNAuthenticationProviderImpl_sole_credentials("alice/******", "<svn://localhost:3690> 8a677b3a-1c61-4b23-9212-1bf3c3d713a7"), run); */ } finally { p.kill(); } } }
/** * {@inheritDoc} */ @Override public void save() throws IOException { if (BulkChange.contains(this)) { return; } SystemCredentialsProvider.getInstance().save(); } }
/** * Implementation for {@link StoreImpl} to delegate to while keeping the lock synchronization simple. */ private synchronized boolean removeDomain(@NonNull Domain domain) throws IOException { checkPermission(CredentialsProvider.MANAGE_DOMAINS); Map<Domain, List<Credentials>> domainCredentialsMap = getDomainCredentialsMap(); if (domainCredentialsMap.containsKey(domain)) { domainCredentialsMap.remove(domain); checkedSave(CredentialsProvider.MANAGE_DOMAINS); return true; } return false; }
/** * Short-cut method that redundantly checks the specified permission (to catch any typos) and then escalates * authentication in order to save the {@link CredentialsStore}. * * @param p the permissions of the operation being performed. * @throws IOException if something goes wrong. */ private void checkedSave(Permission p) throws IOException { checkPermission(p); Authentication old = SecurityContextHolder.getContext().getAuthentication(); SecurityContextHolder.getContext().setAuthentication(ACL.SYSTEM); try { save(); } finally { SecurityContextHolder.getContext().setAuthentication(old); } }
/** * Get all the credentials. * * @return all the credentials. * @since 1.5 */ @SuppressWarnings("unused") // used by stapler public List<DomainCredentials> getDomainCredentials() { return DomainCredentials.asList(getDomainCredentialsMap()); }