| | |
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.List;
|
| | |
|
| | | 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.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));
|
| | | 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) {
|