private ISVNAuthenticationProvider getSvnAuthenticationProvider(AbstractBuild<?, ?> build) { ISVNAuthenticationProvider sap; try { sap = getJenkinsScm().createAuthenticationProvider(build.getParent(), getLocation()); } catch (NoSuchMethodError e) { //fallback for versions under 2.x of org.jenkins-ci.plugins:subversion buildListener.getLogger().println( "[RELEASE] You are using an old subversion jenkins plugin, please consider upgrading."); sap = getJenkinsScm().getDescriptor().createAuthenticationProvider(build.getParent()); } if (sap == null) { throw new AbortException("Subversion authentication info is not set."); } return sap; }
/** * Submits the authentication info. */ // TODO: stapler should do multipart/form-data handling public void doPostCredential(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { Hudson.getInstance().checkPermission(Item.CONFIGURE); MultipartFormDataParser parser = new MultipartFormDataParser(req); // we'll record what credential we are trying here. StringWriter log = new StringWriter(); PrintWriter logWriter = new PrintWriter(log); UserProvidedCredential upc = UserProvidedCredential.fromForm(req,parser); try { postCredential(parser.get("url"), upc, logWriter); rsp.sendRedirect("credentialOK"); } catch (SVNException e) { logWriter.println("FAILED: "+e.getErrorMessage()); req.setAttribute("message",log.toString()); req.setAttribute("pre",true); req.setAttribute("exception",e); rsp.forward(Hudson.getInstance(),"error",req); } finally { upc.close(); } }
if (isValidateRemoteUpToVar()) { url = (url.indexOf('$') != -1) ? url.substring(0, url.indexOf('$')) : url; if (checkRepositoryPath(context, repoURL) != SVNNodeKind.NONE) { repository = getRepository(context, repoURL); long rev = repository.getLatestRevision(); String repoPath = getRelativePath(repoURL, repository); String p = repoPath; while (p.length() > 0) {
final ISVNAuthenticationProvider authProvider = getDescriptor().createAuthenticationProvider(project); final ModuleLocation[] moduleLocations = getLocations(lastCompletedBuild);
final ISVNAuthenticationProvider authProvider = getDescriptor().createAuthenticationProvider(project);
if (isValidateRemoteUpToVar()) { url = (url.indexOf('$') != -1) ? url.substring(0, url.indexOf('$')) : url; if (checkRepositoryPath(context, repoURL) != SVNNodeKind.NONE) { repository = getRepository(context, repoURL); long rev = repository.getLatestRevision(); String repoPath = getRelativePath(repoURL, repository); String p = repoPath; while (p.length() > 0) {
LOGGER.info("Persisted " + cred + " for " + realm); credentials.put(realm, cred); save();
SVNNodeKind node = null; try { node = checkRepositoryPath(context,repoURL, credentials); } catch (SVNCancelException ce) { if (isAuthenticationFailedError(ce)) { repository = getRepository(context,repoURL, credentials, Collections.<String, Credentials>emptyMap(), null); if (repository.hasCapability(SVNCapability.LOG_REVPROPS)) return FormValidation.ok();
r.jenkins.getDescriptorByType(SubversionSCM.DescriptorImpl.class).postCredential(null,repo.toDecodedString(),"guest","",null,new PrintWriter(System.out));
if (checkRepositoryPath(context, repoURL) != SVNNodeKind.NONE) repository = getRepository(context, repoURL); if (repository.hasCapability(SVNCapability.LOG_REVPROPS)) { return FormValidation.ok();
return descriptor().getRepository(context, repoURL, creds, additional, null); return descriptor().getRepository(context, repoURL, creds, additional, new ISVNSession() { public boolean keepConnection(SVNRepository repository) { return false;
if (checkRepositoryPath(context, repoURL) != SVNNodeKind.NONE) repository = getRepository(context, repoURL); if (repository.hasCapability(SVNCapability.LOG_REVPROPS)) { return FormValidation.ok();
repository = openSession(repoURL); String repoPath = SubversionSCM.DescriptorImpl.getRelativePath(repoURL, repository.getRepository()); List<String> prefix = Collections.emptyList(); fetch(listener,
SVNURL repoURL = SVNURL.parseURIEncoded(remoteBase); repository = openSession(repoURL); String repoPath = SubversionSCM.DescriptorImpl.getRelativePath(repoURL, repository.getRepository()); String base; long revision;
r.jenkins.getDescriptorByType(SubversionSCM.DescriptorImpl.class).postCredential(null,repo.toDecodedString(),"guest","",null,new PrintWriter(System.out)); attemptAccess(m);
SVNURL repoURL = SVNURL.parseURIEncoded(remote); StandardCredentials credentials = lookupCredentials(context, value, repoURL); SVNRepository repo = descriptor().getRepository(context, repoURL, credentials, Collections .<String, Credentials>emptyMap(), null); String repoRoot = repo.getRepositoryRoot(true).toDecodedString();
/*package*/ void migratePerJobCredentials() { if (credentials == null && !mayHaveLegacyPerJobCredentials ) { // nothing to do here return; } boolean allOk = true; for (AbstractProject<?, ?> job : Jenkins.getInstance().getAllItems(AbstractProject.class)) { File jobCredentials = new File(job.getRootDir(), "subversion.credentials"); if (jobCredentials.isFile()) { try { if (job.getScm() instanceof SubversionSCM) { new PerJobCredentialStore(job).migrateCredentials(this); job.save(); } // else: job is not using Subversion anymore if (!jobCredentials.delete()) { LOGGER.log(Level.WARNING, "Could not remove legacy per-job credentials store file: {0}", jobCredentials); allOk = false; } } catch (IOException e) { LOGGER.log(Level.WARNING, "Could not migrate per-job credentials for " + job.getFullName(), e); allOk = false; } } } mayHaveLegacyPerJobCredentials = !allOk; save(); }
/** * @since 1.34 */ public boolean repositoryLocationsNoLongerExist(Run<?,?> build, TaskListener listener, EnvVars env) { PrintStream out = listener.getLogger(); for (ModuleLocation l : getLocations(env, build)) try { if (getDescriptor().checkRepositoryPath(build.getParent(), l.getSVNURL(), lookupCredentials(build.getParent(), l.credentialsId, l.getSVNURL())) == SVNNodeKind.NONE) { out.println("Location '" + l.remote + "' does not exist"); ParametersAction params = build.getAction(ParametersAction.class); if (params != null) { // since this is used to disable projects, be conservative LOGGER.fine("Location could be expanded on build '" + build + "' parameters values:"); return false; } return true; } } catch (SVNException e) { // be conservative, since we are just trying to be helpful in detecting // non existent locations. If we can't detect that, we'll do nothing LOGGER.log(FINE, "Location check failed",e); } return false; }
public SVNNodeKind checkRepositoryPath(Item context, SVNURL repoURL, StandardCredentials credentials) throws SVNException { SVNRepository repository = null; try { repository = getRepository(context, repoURL, credentials, Collections.<String, Credentials>emptyMap(), null); repository.testConnection(); long rev = repository.getLatestRevision(); String repoPath = getRelativePath(repoURL, repository); return repository.checkPath(repoPath, rev); } catch (SVNException e) { if (LOGGER.isLoggable(Level.FINE)) { LogRecord lr = new LogRecord(Level.FINE, "Could not check repository path {0} using credentials {1} ({2})"); lr.setThrown(e); lr.setParameters(new Object[]{ repoURL, credentials == null ? null : CredentialsNameProvider.name(credentials), credentials }); LOGGER.log(lr); } throw e; } finally { if (repository != null) { repository.closeSession(); } } }
@Override public void load() { super.load(); if (credentials != null && !credentials.isEmpty()) { SecurityContext oldContext = ACL.impersonate(ACL.SYSTEM); try { BulkChange bc = new BulkChange(this); try { mayHaveLegacyPerJobCredentials = true; CredentialsStore store = CredentialsProvider.lookupStores(Jenkins.getInstance()).iterator().next(); for (Map.Entry<String, Credential> e : credentials.entrySet()) { migrateCredentials(store, e.getKey(), e.getValue()); } save(); bc.commit(); } catch (IOException e) { LOGGER.log(Level.WARNING, "Could not migrate stored credentials", e); } finally { bc.abort(); } } finally { SecurityContextHolder.setContext(oldContext); } } }