James Moger
2011-11-03 ec5a889c907af30afeba527def2d9f836eecbec4
Feeds and Manager must respect a server's web.mountParameters setting
11 files modified
125 ■■■■ changed files
docs/00_index.mkd 1 ●●●● patch | view | raw | blame | history
docs/02_rpc.mkd 1 ●●●● patch | view | raw | blame | history
docs/04_releases.mkd 1 ●●●● patch | view | raw | blame | history
src/com/gitblit/Constants.java 14 ●●●●● patch | view | raw | blame | history
src/com/gitblit/RpcFilter.java 6 ●●●● patch | view | raw | blame | history
src/com/gitblit/RpcServlet.java 23 ●●●● patch | view | raw | blame | history
src/com/gitblit/SyndicationServlet.java 28 ●●●● patch | view | raw | blame | history
src/com/gitblit/client/GitblitClient.java 31 ●●●●● patch | view | raw | blame | history
src/com/gitblit/client/RepositoriesPanel.java 6 ●●●●● patch | view | raw | blame | history
src/com/gitblit/utils/SyndicationUtils.java 10 ●●●● patch | view | raw | blame | history
tests/com/gitblit/tests/SyndicationUtilsTest.java 4 ●●●● patch | view | raw | blame | history
docs/00_index.mkd
@@ -54,6 +54,7 @@
- fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23)
- fixed: Set the RSS content type of syndication feeds for Firefox 4 (issue 22)
- fixed: RSS feeds are now properly encoded to UTF-8
- fixed: RSS feeds now properly generated parameterized links if *web.mountParameters=false*
- fixed: Null pointer exception if did not set federation strategy (issue 20)
- fixed: Gitblit GO allows SSL renegotiation if running on Java 1.6.0_22 or later
- updated: MarkdownPapers 1.2.4
docs/02_rpc.mkd
@@ -19,6 +19,7 @@
<tr><td colspan='5'><em>web.enableRpcServlet=true</em></td></tr>
<tr><td>LIST_REPOSITORIES</td><td>-</td><td>-</td><td>-</td><td>Map&lt;String, RepositoryModel&gt;</td></tr>
<tr><td>LIST_BRANCHES</td><td>-</td><td>-</td><td>-</td><td>Map&lt;String, List&lt;String&gt;&gt;</td></tr>
<tr><td>LIST_SETTINGS</td><td>-</td><td><em>-</em></td><td>-</td><td>ServerSettings (basic keys)</td></tr>
<tr><td colspan='5'><em>web.enableRpcManagement=true</em></td></tr>
<tr><td>CREATE_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>
<tr><td>EDIT_REPOSITORY</td><td>repository name</td><td><em>admin</em></td><td>RepositoryModel</td><td>-</td></tr>
docs/04_releases.mkd
@@ -27,6 +27,7 @@
- fixed: Gitblit now runs on Servlet 3.0 webservers (e.g. Tomcat 7, Jetty 8) (issue 23)
- fixed: Set the RSS content type of syndication feeds for Firefox 4 (issue 22)
- fixed: RSS feeds are now properly encoded to UTF-8
- fixed: RSS feeds now properly generated parameterized links if *web.mountParameters=false*
- fixed: Null pointer exception if did not set federation strategy (issue 20)
- fixed: Gitblit GO allows SSL renegotiation if running on Java 1.6.0_22 or later
- updated: MarkdownPapers 1.2.4
src/com/gitblit/Constants.java
@@ -201,11 +201,13 @@
     * a client.
     */
    public static enum RpcRequest {
        LIST_REPOSITORIES, LIST_BRANCHES, CREATE_REPOSITORY, EDIT_REPOSITORY, DELETE_REPOSITORY,
        LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS,
        SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS,
        LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, EDIT_SETTINGS,
        LIST_STATUS;
        // Order is important here.  anything above LIST_SETTINGS requires
        // administrator privileges and web.allowRpcManagement.
        LIST_REPOSITORIES, LIST_BRANCHES, LIST_SETTINGS, CREATE_REPOSITORY, EDIT_REPOSITORY,
        DELETE_REPOSITORY, LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER,
        LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS,
        LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,
        EDIT_SETTINGS, LIST_STATUS;
        public static RpcRequest fromName(String name) {
            for (RpcRequest type : values()) {
@@ -214,7 +216,7 @@
                }
            }
            return null;
        }
        }
        public boolean exceeds(RpcRequest type) {
            return this.ordinal() > type.ordinal();
src/com/gitblit/RpcFilter.java
@@ -64,7 +64,7 @@
            return;
        }
        boolean adminRequest = requestType.exceeds(RpcRequest.LIST_BRANCHES);
        boolean adminRequest = requestType.exceeds(RpcRequest.LIST_SETTINGS);
        // conditionally reject all rpc requests
        if (!GitBlit.getBoolean(Keys.web.enableRpcServlet, true)) {
@@ -86,8 +86,8 @@
        // conditionally reject rpc management/administration requests
        if (adminRequest && !GitBlit.getBoolean(Keys.web.enableRpcManagement, false)) {
            logger.warn(Keys.web.enableRpcManagement
                    + " must be set TRUE for management/administrative rpc requests.");
            logger.warn(MessageFormat.format("{0} must be set TRUE for {1} rpc requests.",
                    Keys.web.enableRpcManagement, requestType.toString()));
            httpResponse.sendError(HttpServletResponse.SC_FORBIDDEN);
            return;
        }
src/com/gitblit/RpcServlet.java
@@ -68,9 +68,13 @@
        logger.info(MessageFormat.format("Rpc {0} request from {1}", reqType,
                request.getRemoteAddr()));
        boolean allowAdmin = GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);
        UserModel user = (UserModel) request.getUserPrincipal();
        boolean allowManagement = user != null && user.canAdmin
                && GitBlit.getBoolean(Keys.web.enableRpcManagement, false);
        boolean allowAdmin = user != null && user.canAdmin
                && GitBlit.getBoolean(Keys.web.enableRpcAdministration, false);
        Object result = null;
        if (RpcRequest.LIST_REPOSITORIES.equals(reqType)) {
@@ -224,9 +228,18 @@
                // return all settings
                result = settings;
            } else {
                // return management settings only
                String[] keys = { Keys.realm.minPasswordLength, Keys.realm.passwordStorage,
                        Keys.federation.sets };
                // anonymous users get a few settings to allow browser launching
                List<String> keys = new ArrayList<String>();
                keys.add(Keys.web.siteName);
                keys.add(Keys.web.mountParameters);
                if (allowManagement) {
                    // keys necessary for repository and/or user management
                    keys.add(Keys.realm.minPasswordLength);
                    keys.add(Keys.realm.passwordStorage);
                    keys.add(Keys.federation.sets);
                }
                // build the settings
                ServerSettings managementSettings = new ServerSettings();
                for (String key : keys) {
                    managementSettings.add(settings.get(key));
src/com/gitblit/SyndicationServlet.java
@@ -32,8 +32,6 @@
import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.SyndicationUtils;
import com.sun.syndication.feed.synd.SyndContent;
import com.sun.syndication.feed.synd.SyndContentImpl;
/**
 * SyndicationServlet generates RSS 2.0 feeds and feed links.
@@ -145,13 +143,22 @@
        List<RevCommit> commits = JGitUtils.getRevLog(repository, objectId, 0, length);
        List<SyndicatedEntryModel> entries = new ArrayList<SyndicatedEntryModel>();
        boolean mountParameters = GitBlit.getBoolean(Keys.web.mountParameters, true);
        String urlPattern;
        if (mountParameters) {
            // mounted parameters
            urlPattern = "{0}/commit/{1}/{2}";
        } else {
            // parameterized parameters
            urlPattern = "{0}/commit/?r={1}&h={2}";
        }
        String gitblitUrl = HttpUtils.getGitblitURL(request);
        // convert RevCommit to SyndicatedEntryModel
        for (RevCommit commit : commits) {
            SyndicatedEntryModel entry = new SyndicatedEntryModel();
            entry.title = commit.getShortMessage();
            entry.author = commit.getAuthorIdent().getName();
            entry.link = MessageFormat.format("{0}/commit/{1}/{2}", gitblitUrl,
            entry.link = MessageFormat.format(urlPattern, gitblitUrl,
                    StringUtils.encodeURL(model.name), commit.getName());
            entry.published = commit.getCommitterIdent().getWhen();
            entry.contentType = "text/plain";
@@ -160,9 +167,20 @@
            entry.branch = objectId;
            entries.add(entry);
        }
        String feedLink;
        if (mountParameters) {
            // mounted url
            feedLink = MessageFormat.format("{0}/summary/{1}", gitblitUrl,
                    StringUtils.encodeURL(model.name));
        } else {
            // parameterized url
            feedLink = MessageFormat.format("{0}/summary/?r={1}", gitblitUrl,
                    StringUtils.encodeURL(model.name));
        }
        try {
            SyndicationUtils.toRSS(gitblitUrl, getTitle(model.name, objectId), model.description,
                    model.name, entries, response.getOutputStream());
            SyndicationUtils.toRSS(gitblitUrl, feedLink, getTitle(model.name, objectId),
                    model.description, model.name, entries, response.getOutputStream());
        } catch (Exception e) {
            logger.error("An error occurred during feed generation", e);
        }
src/com/gitblit/client/GitblitClient.java
@@ -38,6 +38,7 @@
import com.gitblit.models.SyndicatedEntryModel;
import com.gitblit.models.UserModel;
import com.gitblit.utils.RpcUtils;
import com.gitblit.utils.StringUtils;
import com.gitblit.utils.SyndicationUtils;
/**
@@ -96,6 +97,7 @@
    }
    public void login() throws IOException {
        refreshSettings();
        refreshAvailableFeeds();
        refreshRepositories();
@@ -110,7 +112,6 @@
            // credentials may not have administrator access
            // or server may have disabled rpc management
            refreshUsers();
            refreshSettings();
            allowManagement = true;
        } catch (UnauthorizedException e) {
        } catch (ForbiddenException e) {
@@ -132,7 +133,6 @@
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    public boolean allowManagement() {
@@ -147,6 +147,33 @@
        return account != null && account.equalsIgnoreCase(model.owner);
    }
    public String getURL(String action, String repository, String objectId) {
        boolean mounted = settings.get(Keys.web.mountParameters).getBoolean(true);
        StringBuilder sb = new StringBuilder();
        sb.append(url);
        sb.append('/');
        sb.append(action);
        sb.append('/');
        if (mounted) {
            // mounted url/action/repository/objectId
            sb.append(StringUtils.encodeURL(repository));
            if (!StringUtils.isEmpty(objectId)) {
                sb.append('/');
                sb.append(objectId);
            }
            return sb.toString();
        } else {
            // parameterized url/action/&r=repository&h=objectId
            sb.append("?r=");
            sb.append(repository);
            if (!StringUtils.isEmpty(objectId)) {
                sb.append("&h=");
                sb.append(objectId);
            }
            return sb.toString();
        }
    }
    public ServerSettings getSettings() {
        return settings;
    }
src/com/gitblit/client/RepositoriesPanel.java
@@ -26,7 +26,6 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
@@ -91,9 +90,8 @@
        browseRepository.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                RepositoryModel model = getSelectedRepositories().get(0);
                String u = MessageFormat.format("{0}/summary/{1}", gitblit.url,
                        StringUtils.encodeURL(model.name));
                Utils.browse(u);
                String url = gitblit.getURL("summary", model.name, null);
                Utils.browse(url);
            }
        });
src/com/gitblit/utils/SyndicationUtils.java
@@ -51,6 +51,7 @@
     * Outputs an RSS feed of the list of entries to the outputstream.
     * 
     * @param hostUrl
     * @param feedLink
     * @param title
     * @param description
     * @param repository
@@ -59,16 +60,15 @@
     * @throws IOException
     * @throws FeedException
     */
    public static void toRSS(String hostUrl, String title, String description, String repository,
            List<SyndicatedEntryModel> entryModels, OutputStream os) throws IOException,
            FeedException {
    public static void toRSS(String hostUrl, String feedLink, String title, String description,
            String repository, List<SyndicatedEntryModel> entryModels, OutputStream os)
            throws IOException, FeedException {
        SyndFeed feed = new SyndFeedImpl();
        feed.setFeedType("rss_2.0");
        feed.setEncoding("UTF-8");
        feed.setTitle(title);
        feed.setLink(MessageFormat.format("{0}/summary/{1}", hostUrl,
                StringUtils.encodeURL(repository)));
        feed.setLink(feedLink);
        feed.setDescription(description);
        SyndImageImpl image = new SyndImageImpl();
        image.setTitle(Constants.NAME);
tests/com/gitblit/tests/SyndicationUtilsTest.java
@@ -42,8 +42,8 @@
            entries.add(entry);
        }
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        SyndicationUtils.toRSS("http://localhost", "Title", "Description", "Repository", entries,
                os);
        SyndicationUtils.toRSS("http://localhost", "", "Title", "Description", "Repository",
                entries, os);
        String feed = os.toString();
        os.close();
        assertTrue(feed.indexOf("<title>Title</title>") > -1);