]> source.dussan.org Git - gitblit.git/commitdiff
Renamed User to UserModel.
authorJames Moger <james.moger@gitblit.com>
Thu, 12 May 2011 02:07:53 +0000 (22:07 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 12 May 2011 02:07:53 +0000 (22:07 -0400)
src/com/gitblit/GitBlit.java
src/com/gitblit/ILoginService.java
src/com/gitblit/JettyLoginService.java
src/com/gitblit/wicket/AuthorizationStrategy.java
src/com/gitblit/wicket/GitBlitWebSession.java
src/com/gitblit/wicket/LoginPage.java
src/com/gitblit/wicket/models/User.java [deleted file]
src/com/gitblit/wicket/models/UserModel.java [new file with mode: 0644]
src/com/gitblit/wicket/pages/EditUserPage.java
src/com/gitblit/wicket/pages/RepositoriesPage.java

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