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
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
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
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
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
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
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
}\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
}\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
}\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
}\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
\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
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
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
\r
protected TimeZone timezone = null;\r
\r
- private User user = null;\r
+ private UserModel user = null;\r
\r
private String errorMessage = null;\r
\r
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
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
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
}\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
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
+++ /dev/null
-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
--- /dev/null
+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
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
// create constructor\r
super();\r
isCreate = true;\r
- setupPage(new User(""));\r
+ setupPage(new UserModel(""));\r
}\r
\r
public EditUserPage(PageParameters params) {\r
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
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
}\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