From: <jbo...@li...> - 2005-11-01 12:09:36
|
Author: aron.gombas Date: 2005-11-01 07:09:30 -0500 (Tue, 01 Nov 2005) New Revision: 1480 Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/server/svn/SvnServiceImpl.java trunk/labs/kosmos/src/java/hu/midori/kosmos/server/util/ScrapingUtils.java Log: SVN support for secure repos added Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/server/svn/SvnServiceImpl.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/server/svn/SvnServiceImpl.java 2005-11-01 12:00:24 UTC (rev 1479) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/server/svn/SvnServiceImpl.java 2005-11-01 12:09:30 UTC (rev 1480) @@ -13,6 +13,7 @@ import hu.midori.kosmos.server.AbstractKosmosService; import hu.midori.kosmos.server.CachedDataHandler; import hu.midori.kosmos.server.util.ChartUtils; +import hu.midori.kosmos.server.util.ScrapingUtils; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -28,6 +29,7 @@ import java.util.Set; import java.util.TreeMap; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.jfree.data.time.TimeSeries; @@ -43,6 +45,7 @@ import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl; import org.tmatesoft.svn.core.io.SVNRepository; import org.tmatesoft.svn.core.io.SVNRepositoryFactory; +import org.tmatesoft.svn.core.wc.SVNWCUtil; /** * Implementation of the <i>Subversion</i> service. @@ -98,18 +101,33 @@ SVNRepositoryFactoryImpl.setup(); try { - // get repository info + // connect to repository SVNURL svnUrl = SVNURL.parseURIEncoded(url); SVNRepository repo = SVNRepositoryFactory.create(svnUrl); - // TODO repository.setCredentialsProvider(new SVNSimpleCredentialsProvider("anonymous", "anonymous"));//TODO should be param + + // authenticate if repository is secured + String userInfo = svnUrl.getUserInfo(); + if(!StringUtils.isBlank(userInfo)) { + String strings[] = StringUtils.split(userInfo, ':'); + if(strings.length != 2) + throw new IllegalArgumentException(String.format("Invalid user info \"%s\"", userInfo)); + String userName = strings[0]; + String password = strings[1]; + if(StringUtils.isBlank(userName) || StringUtils.isBlank(password)) + throw new IllegalArgumentException(String.format("Invalid username (\"%s\") or password (\"%s\")", userName, password)); + log.debug(String.format("Signing in as \"%s\" \"%s\"...", userName, password)); + + repo.setAuthenticationManager(SVNWCUtil.createDefaultAuthenticationManager(userName, password)); + } + // get repository info SvnRepositoryLogStats logStats = analyzeLog(repo); SvnRepositoryContentStats contentStats = analyzeContent(repo); generateCharts(repo, logStats); // save previousLatestRevision = repo.getLatestRevision(); - SvnRepository repository = new SvnRepository(repo.getLocation().toString(), repo.getLatestRevision(), + SvnRepository repository = new SvnRepository(ScrapingUtils.removeUserInfoFromUrl(repo.getLocation().toString()), repo.getLatestRevision(), logStats.createdDate, logStats.commits, logStats.commitsTotal, logStats.commitsToday, logStats.commitsLast7Days, logStats.commitsLast31Days, logStats.committersTotal.size(), logStats.committersToday.size(), logStats.committersLast7Days.size(), logStats.committersLast31Days.size(), @@ -323,7 +341,7 @@ /** Generates and saves the chart images on the server, and sets the URLs to the stats. */ protected void generateCharts(SVNRepository repository, SvnRepositoryLogStats stats) throws IOException { - String location = repository.getLocation().toString(); + String location = ScrapingUtils.removeUserInfoFromUrl(repository.getLocation().toString()); // generate charts ByteArrayOutputStream out = new ByteArrayOutputStream(); Modified: trunk/labs/kosmos/src/java/hu/midori/kosmos/server/util/ScrapingUtils.java =================================================================== --- trunk/labs/kosmos/src/java/hu/midori/kosmos/server/util/ScrapingUtils.java 2005-11-01 12:00:24 UTC (rev 1479) +++ trunk/labs/kosmos/src/java/hu/midori/kosmos/server/util/ScrapingUtils.java 2005-11-01 12:09:30 UTC (rev 1480) @@ -6,6 +6,7 @@ */ package hu.midori.kosmos.server.util; +import java.net.MalformedURLException; import java.net.URL; import java.util.List; @@ -17,6 +18,7 @@ import net.sf.saxon.query.XQueryExpression; import net.sf.saxon.trans.XPathException; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.w3c.dom.Document; @@ -84,6 +86,17 @@ } /** + * Removes the userinfo part from the given URL. + * @return the truncated URL. + */ + public static String removeUserInfoFromUrl(String url) throws MalformedURLException { + URL originalUrl = new URL(url); + + // remove the userinfo part and the separator '@' + return StringUtils.remove(StringUtils.remove(originalUrl.toString(), originalUrl.getUserInfo()), '@'); + } + + /** * Eliminates the empty items from a scraped value string to make * the tokenizer happy. E.g. <code>||xxx|</code> will be transformed to <code> | |xxx| </code>. */ |