@Initializer(after = InitMilestone.PLUGINS_STARTED) public static void migrate() throws IOException { GitLabConnectionConfig descriptor = (GitLabConnectionConfig) Jenkins.getInstance().getDescriptor(GitLabConnectionConfig.class); for (GitLabConnection connection : descriptor.getConnections()) { if (connection.apiTokenId == null && connection.apiToken != null) { for (CredentialsStore credentialsStore : CredentialsProvider.lookupStores(Jenkins.getInstance())) { if (credentialsStore instanceof SystemCredentialsProvider.StoreImpl) { List<Domain> domains = credentialsStore.getDomains(); connection.apiTokenId = UUID.randomUUID().toString(); credentialsStore.addCredentials(domains.get(0), new GitLabApiTokenImpl(CredentialsScope.SYSTEM, connection.apiTokenId, "GitLab API Token", Secret.fromString(connection.apiToken))); } } } } descriptor.save(); } }
protected static Domain getDomainByName(CredentialsStore store, String domain) { if (StringUtils.equals("_", domain) || StringUtils.isBlank(domain) || "(global)".equals(domain)) { return Domain.global(); } else { for (Domain d : store.getDomains()) { if (domain.equals(d.getName())) { return d; } } } return null; }
protected static Domain getDomainByName(CredentialsStore store, String domain) { if (StringUtils.equals("_", domain) || StringUtils.isBlank(domain) || "(global)".equals(domain)) { return Domain.global(); } else { for (Domain d : store.getDomains()) { if (domain.equals(d.getName())) { return d; } } } return null; }
@Override protected int run() throws Exception { store.checkPermission(CredentialsProvider.UPDATE); List<DomainCredentials> existing = new ArrayList<>(); List<Domain> domains = store.getDomains(); for (Domain domain : domains) { existing.add(new DomainCredentials(domain, store.getCredentials(domain))); } CredentialsStoreAction.SECRETS_REDACTED.toXML(existing, new OutputStreamWriter(stdout, "UTF-8")); return 0; }
/** * Retrieves the domain with the matching name. * * @param name the name (or {@code null} to match {@link Domain#global()} as that is the domain with a null name) * @return the domain or {@code null} if there is no domain with the supplied name. * @since 2.1.1 */ @CheckForNull public Domain getDomainByName(@CheckForNull String name) { for (Domain d : getDomains()) { if (StringUtils.equals(name, d.getName())) { return d; } } return null; }
/** * Retrieves the domain with the matching name. * * @param name the name (or {@code null} to match {@link Domain#global()} as that is the domain with a null name) * @return the domain or {@code null} if there is no domain with the supplied name. * @since 2.1.1 */ @CheckForNull public Domain getDomainByName(@CheckForNull String name) { for (Domain d : getDomains()) { if (StringUtils.equals(name, d.getName())) { return d; } } return null; }
private String url(CredentialsStore store) { for (Domain d: store.getDomains()) { for (Credentials c: store.getCredentials(d)) { if (c instanceof IdCredentials && value.equals(((IdCredentials) c).getId())) { String link = store.getRelativeLinkToAction(); return link == null ? null : link + d.getUrl() + "credential/"+ Util.rawEncode(value); } } } return null; }
private String url(CredentialsStore store) { for (Domain d: store.getDomains()) { for (Credentials c: store.getCredentials(d)) { if (c instanceof IdCredentials && value.equals(((IdCredentials) c).getId())) { String link = store.getRelativeLinkToAction(); return link == null ? null : link + d.getUrl() + "credential/"+ Util.rawEncode(value); } } } return null; }
for (Domain d : action.getStore().getDomains()) { if (wrapper != null && wrapper.domain == d) { continue;
for (Domain d : action.getStore().getDomains()) { if (wrapper != null && wrapper.domain == d) { continue;
/** * Returns the map of {@link DomainWrapper} instances. * * @return the map of {@link DomainWrapper} instances. */ @Exported @NonNull public Map<String, DomainWrapper> getDomains() { Map<String, DomainWrapper> result = new TreeMap<String, DomainWrapper>(); for (Domain d : getStore().getDomains()) { String name; if (d.isGlobal()) { name = "_"; } else { name = d.getName(); } result.put(name, new DomainWrapper(this, d)); } return result; }
/** * Returns the map of {@link DomainWrapper} instances. * * @return the map of {@link DomainWrapper} instances. */ @Exported @NonNull public Map<String, DomainWrapper> getDomains() { Map<String, DomainWrapper> result = new TreeMap<String, DomainWrapper>(); for (Domain d : getStore().getDomains()) { String name; if (d.isGlobal()) { name = "_"; } else { name = d.getName(); } result.put(name, new DomainWrapper(this, d)); } return result; }
for (CredentialsStore p : CredentialsProvider.lookupStores(context)) { if (p.hasPermission(CredentialsProvider.VIEW)) { for (Domain domain : p.getDomains()) { for (Credentials c : p.getCredentials(domain)) { CredentialsScope scope = c.getScope();
for (CredentialsStore p : CredentialsProvider.lookupStores(context)) { if (p.hasPermission(CredentialsProvider.VIEW)) { for (Domain domain : p.getDomains()) { for (Credentials c : p.getCredentials(domain)) { CredentialsScope scope = c.getScope();
@CheckForNull private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) { CredentialsMatcher withId = CredentialsMatchers.withId(value); for (CredentialsStore store : CredentialsProvider.lookupStores(object)) { if (!store.hasPermission(CredentialsProvider.VIEW)) { continue; } ModelObject storeContext = store.getContext(); for (Domain domain : store.getDomains()) { for (Credentials match : CredentialsMatchers.filter(store.getCredentials(domain), withId)) { if (storeContext == context) { return FormValidation.error("This ID is already in use"); } else { CredentialsScope scope = match.getScope(); if (scope != null && !scope.isVisible(context)) { // scope is not exported to child contexts continue; } return FormValidation.warning("The ID ā%sā is already in use in %s", value, storeContext instanceof Item ? ((Item) storeContext).getFullDisplayName() : storeContext.getDisplayName()); } } } } return null; }
/** * Stapler web binding for adding credentials to the domain. * * @param req the request. * @param rsp the response. * @throws IOException if something goes wrong. * @throws ServletException if something goes wrong. */ @RequirePOST public void doAddCredentials(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (!store.isDomainsModifiable()) { hudson.util.HttpResponses.status(400).generateResponse(req, rsp, null); FormApply.applyResponse("window.alert('Domain is read-only')").generateResponse(req, rsp, null); } store.checkPermission(CredentialsStoreAction.CREATE); JSONObject data = req.getSubmittedForm(); String domainName = data.getString("domain"); CredentialsStoreAction.DomainWrapper wrapper = getWrappers().get(domainName); if (!store.getDomains().contains(wrapper.getDomain())) { hudson.util.HttpResponses.status(400).generateResponse(req, rsp, null); FormApply.applyResponse("window.alert('Store does not have selected domain')") .generateResponse(req, rsp, null); } store.checkPermission(CredentialsStoreAction.CREATE); Credentials credentials = req.bindJSON(Credentials.class, data.getJSONObject("credentials")); store.addCredentials(wrapper.getDomain(), credentials); FormApply.applyResponse("window.credentials.refreshAll();").generateResponse(req, rsp, null); }
@CheckForNull private static FormValidation checkForDuplicates(String value, ModelObject context, ModelObject object) { CredentialsMatcher withId = CredentialsMatchers.withId(value); for (CredentialsStore store : CredentialsProvider.lookupStores(object)) { if (!store.hasPermission(CredentialsProvider.VIEW)) { continue; } ModelObject storeContext = store.getContext(); for (Domain domain : store.getDomains()) { for (Credentials match : CredentialsMatchers.filter(store.getCredentials(domain), withId)) { if (storeContext == context) { return FormValidation.error("This ID is already in use"); } else { CredentialsScope scope = match.getScope(); if (scope != null && !scope.isVisible(context)) { // scope is not exported to child contexts continue; } return FormValidation.warning("The ID ā%sā is already in use in %s", value, storeContext instanceof Item ? ((Item) storeContext).getFullDisplayName() : storeContext.getDisplayName()); } } } } return null; }
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Domain d : getStore().getDomains()) { MenuItem item = new MenuItem(d.getUrl(), getMenuItemIconUrlByClassSpec("icon-credentials-domain icon-md"), d.isGlobal() ? Messages.CredentialsStoreAction_GlobalDomainDisplayName() : d.getName() ); item.subMenu = new DomainWrapper(this, d).getContextMenu(ContextMenuIconUtils.buildUrl(prefix, d.getUrl())); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
/** * Creates the children context menu with the supplied prefix to all URLs. * * @param prefix the prefix to prepend to relative urls. * @return the {@link ContextMenu} or {@code null} * @since 2.0 */ @CheckForNull public ContextMenu getChildrenContextMenu(String prefix) { ContextMenu menu = new ContextMenu(); for (Domain d : getStore().getDomains()) { MenuItem item = new MenuItem(d.getUrl(), getMenuItemIconUrlByClassSpec("icon-credentials-domain icon-md"), d.isGlobal() ? Messages.CredentialsStoreAction_GlobalDomainDisplayName() : d.getName() ); item.subMenu = new DomainWrapper(this, d).getContextMenu(ContextMenuIconUtils.buildUrl(prefix, d.getUrl())); menu.add(item); } return menu.items.isEmpty() ? null : menu; }
/** * Stapler web binding for adding credentials to the domain. * * @param req the request. * @param rsp the response. * @throws IOException if something goes wrong. * @throws ServletException if something goes wrong. */ @RequirePOST public void doAddCredentials(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { if (!store.isDomainsModifiable()) { hudson.util.HttpResponses.status(400).generateResponse(req, rsp, null); FormApply.applyResponse("window.alert('Domain is read-only')").generateResponse(req, rsp, null); } store.checkPermission(CredentialsStoreAction.CREATE); JSONObject data = req.getSubmittedForm(); String domainName = data.getString("domain"); CredentialsStoreAction.DomainWrapper wrapper = getWrappers().get(domainName); if (!store.getDomains().contains(wrapper.getDomain())) { hudson.util.HttpResponses.status(400).generateResponse(req, rsp, null); FormApply.applyResponse("window.alert('Store does not have selected domain')") .generateResponse(req, rsp, null); } store.checkPermission(CredentialsStoreAction.CREATE); Credentials credentials = req.bindJSON(Credentials.class, data.getJSONObject("credentials")); store.addCredentials(wrapper.getDomain(), credentials); FormApply.applyResponse("window.credentials.refreshAll();").generateResponse(req, rsp, null); }