| | |
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | | import java.util.regex.Pattern;
|
| | |
|
| | | import javax.servlet.http.Cookie;
|
| | |
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.markup.html.form.PasswordTextField;
|
| | | import org.apache.wicket.markup.html.form.StatelessForm;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | | import org.apache.wicket.markup.html.link.BookmarkablePageLink;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | | import org.apache.wicket.protocol.http.WebRequest;
|
| | | import org.apache.wicket.protocol.http.WebResponse;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | | import com.gitblit.utils.StringUtils;
|
| | | import com.gitblit.wicket.GitBlitWebSession;
|
| | | import com.gitblit.wicket.PageRegistration;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.NavigationPanel;
|
| | |
|
| | | /**
|
| | | * Root page is a topbar, navigable page like Repositories, Users, or
|
| | | * Federation.
|
| | | * |
| | | * @author James Moger
|
| | | * |
| | | */
|
| | | public abstract class RootPage extends BasePage {
|
| | |
|
| | | final boolean showAdmin;
|
| | | boolean showAdmin;
|
| | |
|
| | | IModel<String> username = new Model<String>("");
|
| | | IModel<String> password = new Model<String>("");
|
| | |
|
| | | public RootPage() {
|
| | | super();
|
| | | setupPage("", "");
|
| | | }
|
| | |
|
| | | // try to automatically login from cookie
|
| | | if (!GitBlitWebSession.get().isLoggedIn()
|
| | | && GitBlit.getBoolean(Keys.web.allowCookieAuthentication, false)) {
|
| | | loginByCookie();
|
| | | }
|
| | | public RootPage(PageParameters params) {
|
| | | super(params);
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void setupPage(String repositoryName, String pageName) {
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | | boolean allowAdmin = GitBlit.getBoolean(Keys.web.allowAdministration, false);
|
| | | showAdmin = allowAdmin && GitBlitWebSession.get().canAdmin();
|
| | |
| | | && GitBlit.getBoolean(Keys.web.showFederationRegistrations, false);
|
| | |
|
| | | // navigation links
|
| | | add(new BookmarkablePageLink<Void>("repositories", RepositoriesPage.class));
|
| | | add(new BookmarkablePageLink<Void>("users", UsersPage.class).setVisible(showAdmin));
|
| | | add(new BookmarkablePageLink<Void>("federation", FederationPage.class).setVisible(showAdmin
|
| | | || showRegistrations));
|
| | | List<PageRegistration> pages = new ArrayList<PageRegistration>();
|
| | | pages.add(new PageRegistration("gb.repositories", RepositoriesPage.class));
|
| | | pages.add(new PageRegistration("gb.activity", ActivityPage.class));
|
| | | if (showAdmin) {
|
| | | pages.add(new PageRegistration("gb.users", UsersPage.class));
|
| | | }
|
| | | if (showAdmin || showRegistrations) {
|
| | | pages.add(new PageRegistration("gb.federation", FederationPage.class));
|
| | | }
|
| | | NavigationPanel navPanel = new NavigationPanel("navPanel", getClass(), pages);
|
| | | add(navPanel);
|
| | |
|
| | | // login form
|
| | | StatelessForm<Void> loginForm = new StatelessForm<Void>("loginForm") {
|
| | |
| | | }
|
| | | }
|
| | | };
|
| | | loginForm.add(new TextField<String>("username", username));
|
| | | loginForm.add(new PasswordTextField("password", password));
|
| | | TextField<String> unameField = new TextField<String>("username", username);
|
| | | WicketUtils.setInputPlaceholder(unameField, getString("gb.username"));
|
| | | loginForm.add(unameField);
|
| | | PasswordTextField pwField = new PasswordTextField("password", password);
|
| | | WicketUtils.setInputPlaceholder(pwField, getString("gb.password"));
|
| | | loginForm.add(pwField);
|
| | | add(loginForm);
|
| | | if (GitBlit.getBoolean(Keys.web.authenticateViewPages, true)
|
| | | || GitBlit.getBoolean(Keys.web.authenticateAdminPages, true)) {
|
| | |
| | | pendingProposals));
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void loginByCookie() {
|
| | | UserModel user = null;
|
| | |
|
| | | // Grab cookie from Browser Session
|
| | | Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies();
|
| | | if (cookies != null && cookies.length > 0) {
|
| | | user = GitBlit.self().authenticate(cookies);
|
| | | }
|
| | |
|
| | | // Login the user
|
| | | loginUser(user);
|
| | | super.setupPage(repositoryName, pageName);
|
| | | }
|
| | |
|
| | | private void loginUser(UserModel user) {
|
| | |
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | protected List<RepositoryModel> getRepositories(PageParameters params) {
|
| | | final UserModel user = GitBlitWebSession.get().getUser();
|
| | | if (params == null) {
|
| | | return GitBlit.self().getRepositoryModels(user);
|
| | | }
|
| | |
|
| | | String repositoryName = WicketUtils.getRepositoryName(params);
|
| | | String set = WicketUtils.getSet(params);
|
| | | String regex = WicketUtils.getRegEx(params);
|
| | | String team = WicketUtils.getTeam(params);
|
| | |
|
| | | List<RepositoryModel> models = null;
|
| | |
|
| | | if (!StringUtils.isEmpty(repositoryName)) {
|
| | | // try named repository
|
| | | models = new ArrayList<RepositoryModel>();
|
| | | RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
|
| | | if (user.canAccessRepository(model)) {
|
| | | models.add(model);
|
| | | }
|
| | | }
|
| | |
|
| | | // get all user accessible repositories
|
| | | if (models == null) {
|
| | | models = GitBlit.self().getRepositoryModels(user);
|
| | | }
|
| | |
|
| | | if (!StringUtils.isEmpty(regex)) {
|
| | | // filter the repositories by the regex
|
| | | List<RepositoryModel> accessible = GitBlit.self().getRepositoryModels(user);
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | Pattern pattern = Pattern.compile(regex);
|
| | | for (RepositoryModel aModel : accessible) {
|
| | | if (pattern.matcher(aModel.name).find()) {
|
| | | matchingModels.add(aModel);
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | } else if (!StringUtils.isEmpty(set)) {
|
| | | // filter the repositories by the specified sets
|
| | | List<String> sets = StringUtils.getStringsFromValue(set, ",");
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | for (RepositoryModel model : models) {
|
| | | for (String curr : sets) {
|
| | | if (model.federationSets.contains(curr)) {
|
| | | matchingModels.add(model);
|
| | | }
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | } else if (!StringUtils.isEmpty(team)) {
|
| | | // filter the repositories by the specified teams
|
| | | List<String> teams = StringUtils.getStringsFromValue(team, ",");
|
| | | |
| | | // need TeamModels first
|
| | | List<TeamModel> teamModels = new ArrayList<TeamModel>();
|
| | | for (String name : teams) {
|
| | | TeamModel model = GitBlit.self().getTeamModel(name);
|
| | | if (model != null) {
|
| | | teamModels.add(model);
|
| | | }
|
| | | }
|
| | | |
| | | // brute-force our way through finding the matching models
|
| | | List<RepositoryModel> matchingModels = new ArrayList<RepositoryModel>();
|
| | | for (RepositoryModel repositoryModel : models) {
|
| | | for (TeamModel teamModel : teamModels) {
|
| | | if (teamModel.hasRepository(repositoryModel.name)) {
|
| | | matchingModels.add(repositoryModel);
|
| | | }
|
| | | }
|
| | | }
|
| | | models = matchingModels;
|
| | | }
|
| | | return models;
|
| | | }
|
| | | }
|