From: James Moger Date: Thu, 12 May 2011 02:07:53 +0000 (-0400) Subject: Renamed User to UserModel. X-Git-Tag: v0.5.0~54 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=511554c6bdd7daa080506fb62400bf6d295ab9e2;p=gitblit.git Renamed User to UserModel. --- diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index bdfa590e..d0daa536 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -22,7 +22,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.utils.JGitUtils; import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public class GitBlit implements ServletContextListener { @@ -67,14 +67,14 @@ public class GitBlit implements ServletContextListener { this.loginService = loginService; } - public User authenticate(String username, char[] password) { + public UserModel authenticate(String username, char[] password) { if (loginService == null) { return null; } return loginService.authenticate(username, password); } - public User authenticate(Cookie[] cookies) { + public UserModel authenticate(Cookie[] cookies) { if (loginService == null) { return null; } @@ -89,19 +89,19 @@ public class GitBlit implements ServletContextListener { return null; } - public void setCookie(WebResponse response, User user) { + public void setCookie(WebResponse response, UserModel user) { Cookie userCookie = new Cookie(Constants.NAME, user.getCookie()); userCookie.setMaxAge(Integer.MAX_VALUE); userCookie.setPath("/"); response.addCookie(userCookie); } - public User getUser(String username) { - User user = loginService.getUserModel(username); + public UserModel getUser(String username) { + UserModel user = loginService.getUserModel(username); return user; } - public void editUserModel(User user, boolean isCreate) throws GitBlitException { + public void editUserModel(UserModel user, boolean isCreate) throws GitBlitException { if (!loginService.updateUserModel(user)) { throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!"); } @@ -125,7 +125,7 @@ public class GitBlit implements ServletContextListener { return r; } - public List getRepositoryModels(User user) { + public List getRepositoryModels(UserModel user) { List list = getRepositoryList(); List repositories = new ArrayList(); for (String repo : list) { @@ -137,7 +137,7 @@ public class GitBlit implements ServletContextListener { return repositories; } - public RepositoryModel getRepositoryModel(User user, String repositoryName) { + public RepositoryModel getRepositoryModel(UserModel user, String repositoryName) { RepositoryModel model = getRepositoryModel(repositoryName); if (model.accessRestriction.atLeast(AccessRestrictionType.VIEW)) { if (user != null && user.canView(model)) { diff --git a/src/com/gitblit/ILoginService.java b/src/com/gitblit/ILoginService.java index fc2801d9..d0c5d13d 100644 --- a/src/com/gitblit/ILoginService.java +++ b/src/com/gitblit/ILoginService.java @@ -1,17 +1,17 @@ package com.gitblit; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public interface ILoginService { - User authenticate(String username, char[] password); + UserModel authenticate(String username, char[] password); - User authenticate(char[] cookie); + UserModel authenticate(char[] cookie); - User getUserModel(String username); + UserModel getUserModel(String username); - boolean updateUserModel(User model); + boolean updateUserModel(UserModel model); - boolean deleteUserModel(User model); + boolean deleteUserModel(UserModel model); } diff --git a/src/com/gitblit/JettyLoginService.java b/src/com/gitblit/JettyLoginService.java index ddd3722d..4b439647 100644 --- a/src/com/gitblit/JettyLoginService.java +++ b/src/com/gitblit/JettyLoginService.java @@ -18,7 +18,7 @@ import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.util.log.Log; import com.gitblit.utils.StringUtils; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public class JettyLoginService extends MappedLoginService implements ILoginService { @@ -31,12 +31,12 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi } @Override - public User authenticate(String username, char[] password) { + public UserModel authenticate(String username, char[] password) { UserIdentity identity = login(username, new String(password)); if (identity == null || identity.equals(UserIdentity.UNAUTHENTICATED_IDENTITY)) { return null; } - User user = new User(username); + UserModel user = new UserModel(username); user.setCookie(StringUtils.getSHA1((Constants.NAME + username + new String(password)))); user.canAdmin(identity.isUserInRole(Constants.ADMIN_ROLE, null)); @@ -53,14 +53,14 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi } @Override - public User authenticate(char[] cookie) { + public UserModel authenticate(char[] cookie) { // TODO cookie login return null; } @Override - public User getUserModel(String username) { - User model = new User(username); + public UserModel getUserModel(String username) { + UserModel model = new UserModel(username); UserIdentity identity = _users.get(username); Subject subject = identity.getSubject(); for (Principal principal : subject.getPrincipals()) { @@ -83,7 +83,7 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi } @Override - public boolean updateUserModel(User model) { + public boolean updateUserModel(UserModel model) { try { Properties properties = new Properties(); FileReader reader = new FileReader(realmFile); @@ -129,7 +129,7 @@ public class JettyLoginService extends MappedLoginService implements ILoginServi } @Override - public boolean deleteUserModel(User model) { + public boolean deleteUserModel(UserModel model) { try { // Read realm file Properties properties = new Properties(); diff --git a/src/com/gitblit/wicket/AuthorizationStrategy.java b/src/com/gitblit/wicket/AuthorizationStrategy.java index c4560adc..d5a59abb 100644 --- a/src/com/gitblit/wicket/AuthorizationStrategy.java +++ b/src/com/gitblit/wicket/AuthorizationStrategy.java @@ -7,7 +7,7 @@ import org.apache.wicket.authorization.strategies.page.AbstractPageAuthorization import com.gitblit.GitBlit; import com.gitblit.Keys; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; import com.gitblit.wicket.pages.RepositoriesPage; public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy implements IUnauthorizedComponentInstantiationListener { @@ -29,7 +29,7 @@ public class AuthorizationStrategy extends AbstractPageAuthorizationStrategy imp return false; } - User user = session.getUser(); + UserModel user = session.getUser(); if (pageClass.isAnnotationPresent(AdminPage.class)) { // admin page if (allowAdmin) { diff --git a/src/com/gitblit/wicket/GitBlitWebSession.java b/src/com/gitblit/wicket/GitBlitWebSession.java index c6cc36d0..4996546d 100644 --- a/src/com/gitblit/wicket/GitBlitWebSession.java +++ b/src/com/gitblit/wicket/GitBlitWebSession.java @@ -7,7 +7,7 @@ import org.apache.wicket.Session; import org.apache.wicket.protocol.http.WebSession; import org.apache.wicket.protocol.http.request.WebClientInfo; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public final class GitBlitWebSession extends WebSession { @@ -15,7 +15,7 @@ public final class GitBlitWebSession extends WebSession { protected TimeZone timezone = null; - private User user = null; + private UserModel user = null; private String errorMessage = null; @@ -39,11 +39,11 @@ public final class GitBlitWebSession extends WebSession { return user.canAdmin(); } - public User getUser() { + public UserModel getUser() { return user; } - public void setUser(User user) { + public void setUser(UserModel user) { this.user = user; } diff --git a/src/com/gitblit/wicket/LoginPage.java b/src/com/gitblit/wicket/LoginPage.java index 9e26a62a..db971d27 100644 --- a/src/com/gitblit/wicket/LoginPage.java +++ b/src/com/gitblit/wicket/LoginPage.java @@ -18,7 +18,7 @@ import org.apache.wicket.protocol.http.WebResponse; import com.gitblit.Constants; import com.gitblit.GitBlit; import com.gitblit.Keys; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public class LoginPage extends WebPage { @@ -61,7 +61,7 @@ public class LoginPage extends WebPage { String username = LoginPage.this.username.getObject(); char[] password = LoginPage.this.password.getObject().toCharArray(); - User user = GitBlit.self().authenticate(username, password); + UserModel user = GitBlit.self().authenticate(username, password); if (user == null) error("Invalid username or password!"); else @@ -70,7 +70,7 @@ public class LoginPage extends WebPage { } private void tryAutomaticLogin() { - User user = null; + UserModel user = null; // Grab cookie from Browser Session Cookie[] cookies = ((WebRequest) getRequestCycle().getRequest()).getCookies(); @@ -82,7 +82,7 @@ public class LoginPage extends WebPage { loginUser(user); } - private void loginUser(User user) { + private void loginUser(UserModel user) { if (user != null) { // Set the user into the session GitBlitWebSession.get().setUser(user); diff --git a/src/com/gitblit/wicket/models/User.java b/src/com/gitblit/wicket/models/User.java deleted file mode 100644 index 07848396..00000000 --- a/src/com/gitblit/wicket/models/User.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.gitblit.wicket.models; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import com.gitblit.Constants.AccessRestrictionType; - -public class User implements Serializable { - - private static final long serialVersionUID = 1L; - - private String username; - private String password; - private String cookie; - private boolean canAdmin = false; - private List repositories = new ArrayList(); - - public User(String username) { - this.username = username; - } - - public String getUsername() { - return username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - public void canAdmin(boolean value) { - canAdmin = value; - } - - public boolean canAdmin() { - return canAdmin; - } - - public boolean canClone(RepositoryModel repository) { - return canAccess(repository, AccessRestrictionType.CLONE); - } - - public boolean canPush(RepositoryModel repository) { - return canAccess(repository, AccessRestrictionType.PUSH); - } - - public boolean canView(RepositoryModel repository) { - return canAccess(repository, AccessRestrictionType.VIEW); - } - - private boolean canAccess(RepositoryModel repository, AccessRestrictionType minimum) { - if (repository.accessRestriction.atLeast(minimum)) { - // repository is restricted, must check roles - return canAdmin || repositories.contains(repository.name); - } else { - // repository is not restricted - return true; - } - } - - public void setCookie(String cookie) { - this.cookie = cookie; - } - - public String getCookie() { - return cookie; - } - - public void setRepositories(List repositories) { - this.repositories.clear(); - this.repositories.addAll(repositories); - } - - public void addRepository(String name) { - repositories.add(name.toLowerCase()); - } - - public List getRepositories() { - return repositories; - } - - public String toString() { - return username; - } -} diff --git a/src/com/gitblit/wicket/models/UserModel.java b/src/com/gitblit/wicket/models/UserModel.java new file mode 100644 index 00000000..c65d3564 --- /dev/null +++ b/src/com/gitblit/wicket/models/UserModel.java @@ -0,0 +1,89 @@ +package com.gitblit.wicket.models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import com.gitblit.Constants.AccessRestrictionType; + +public class UserModel implements Serializable { + + private static final long serialVersionUID = 1L; + + private String username; + private String password; + private String cookie; + private boolean canAdmin = false; + private List repositories = new ArrayList(); + + public UserModel(String username) { + this.username = username; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public void canAdmin(boolean value) { + canAdmin = value; + } + + public boolean canAdmin() { + return canAdmin; + } + + public boolean canClone(RepositoryModel repository) { + return canAccess(repository, AccessRestrictionType.CLONE); + } + + public boolean canPush(RepositoryModel repository) { + return canAccess(repository, AccessRestrictionType.PUSH); + } + + public boolean canView(RepositoryModel repository) { + return canAccess(repository, AccessRestrictionType.VIEW); + } + + private boolean canAccess(RepositoryModel repository, AccessRestrictionType minimum) { + if (repository.accessRestriction.atLeast(minimum)) { + // repository is restricted, must check roles + return canAdmin || repositories.contains(repository.name); + } else { + // repository is not restricted + return true; + } + } + + public void setCookie(String cookie) { + this.cookie = cookie; + } + + public String getCookie() { + return cookie; + } + + public void setRepositories(List repositories) { + this.repositories.clear(); + this.repositories.addAll(repositories); + } + + public void addRepository(String name) { + repositories.add(name.toLowerCase()); + } + + public List getRepositories() { + return repositories; + } + + public String toString() { + return username; + } +} diff --git a/src/com/gitblit/wicket/pages/EditUserPage.java b/src/com/gitblit/wicket/pages/EditUserPage.java index 84bf7bc9..250d1fde 100644 --- a/src/com/gitblit/wicket/pages/EditUserPage.java +++ b/src/com/gitblit/wicket/pages/EditUserPage.java @@ -22,7 +22,7 @@ import com.gitblit.GitBlitException; import com.gitblit.wicket.AdminPage; import com.gitblit.wicket.BasePage; import com.gitblit.wicket.WicketUtils; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; @AdminPage public class EditUserPage extends BasePage { @@ -33,7 +33,7 @@ public class EditUserPage extends BasePage { // create constructor super(); isCreate = true; - setupPage(new User("")); + setupPage(new UserModel("")); } public EditUserPage(PageParameters params) { @@ -41,23 +41,23 @@ public class EditUserPage extends BasePage { super(params); isCreate = false; String name = WicketUtils.getUsername(params); - User model = GitBlit.self().getUser(name); + UserModel model = GitBlit.self().getUser(name); setupPage(model); } - protected void setupPage(final User userModel) { + protected void setupPage(final UserModel userModel) { if (isCreate) { super.setupPage("", getString("gb.newUser")); } else { super.setupPage("", getString("gb.edit")); } final Model confirmPassword = new Model(); - CompoundPropertyModel model = new CompoundPropertyModel(userModel); + CompoundPropertyModel model = new CompoundPropertyModel(userModel); List repos = GitBlit.self().getRepositoryList(); repos.add(0, "*"); // all repositories wildcard final Palette repositories = new Palette("repositories", new ListModel(userModel.getRepositories()), new CollectionModel(repos), new ChoiceRenderer("", ""), 10, false); - Form form = new Form("editForm", model) { + Form form = new Form("editForm", model) { private static final long serialVersionUID = 1L; diff --git a/src/com/gitblit/wicket/pages/RepositoriesPage.java b/src/com/gitblit/wicket/pages/RepositoriesPage.java index 9f3aa2a3..45058296 100644 --- a/src/com/gitblit/wicket/pages/RepositoriesPage.java +++ b/src/com/gitblit/wicket/pages/RepositoriesPage.java @@ -33,7 +33,7 @@ import com.gitblit.wicket.GitBlitWebSession; import com.gitblit.wicket.LinkPanel; import com.gitblit.wicket.WicketUtils; import com.gitblit.wicket.models.RepositoryModel; -import com.gitblit.wicket.models.User; +import com.gitblit.wicket.models.UserModel; public class RepositoriesPage extends BasePage { @@ -99,7 +99,7 @@ public class RepositoriesPage extends BasePage { } add(repositoriesMessage); - User user = GitBlitWebSession.get().getUser(); + UserModel user = GitBlitWebSession.get().getUser(); List rows = GitBlit.self().getRepositoryModels(user); DataProvider dp = new DataProvider(rows); DataView dataView = new DataView("repository", dp) {