| | |
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.RegistrantAccessPermission;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.TeamModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
| | | import com.gitblit.wicket.RequiresAdminRole;
|
| | | import com.gitblit.wicket.StringChoiceRenderer;
|
| | | import com.gitblit.wicket.WicketUtils;
|
| | | import com.gitblit.wicket.panels.RegistrantPermissionsPanel;
|
| | |
|
| | | @RequiresAdminRole
|
| | | public class EditUserPage extends RootSubPage {
|
| | |
|
| | | private final boolean isCreate;
|
| | |
|
| | | |
| | | public EditUserPage() {
|
| | | // create constructor
|
| | | super();
|
| | |
| | | }
|
| | | isCreate = true;
|
| | | setupPage(new UserModel(""));
|
| | | setStatelessHint(false);
|
| | | }
|
| | |
|
| | | public EditUserPage(PageParameters params) {
|
| | |
| | | String name = WicketUtils.getUsername(params);
|
| | | UserModel model = GitBlit.self().getUserModel(name);
|
| | | setupPage(model);
|
| | | setStatelessHint(false);
|
| | | }
|
| | |
|
| | | protected void setupPage(final UserModel userModel) {
|
| | |
| | | repos.add(repo);
|
| | | }
|
| | | }
|
| | | StringUtils.sortRepositorynames(repos);
|
| | | |
| | | List<String> userTeams = new ArrayList<String>();
|
| | | for (TeamModel team : userModel.teams) {
|
| | | userTeams.add(team.name);
|
| | |
| | | Collections.sort(userTeams);
|
| | |
|
| | | final String oldName = userModel.username;
|
| | | final Palette<String> repositories = new Palette<String>("repositories",
|
| | | new ListModel<String>(new ArrayList<String>(userModel.repositories)),
|
| | | new CollectionModel<String>(repos), new StringChoiceRenderer(), 10, false);
|
| | | final List<RegistrantAccessPermission> permissions = userModel.getRepositoryPermissions();
|
| | |
|
| | | final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(
|
| | | new ArrayList<String>(userTeams)), new CollectionModel<String>(GitBlit.self()
|
| | | .getAllTeamnames()), new StringChoiceRenderer(), 10, false);
|
| | | Form<UserModel> form = new Form<UserModel>("editForm", model) {
|
| | |
|
| | | private static final long serialVersionUID = 1L;
|
| | |
|
| | | |
| | | /*
|
| | | * (non-Javadoc)
|
| | | *
|
| | |
| | | }
|
| | | boolean rename = !StringUtils.isEmpty(oldName)
|
| | | && !oldName.equalsIgnoreCase(username);
|
| | | if (!userModel.password.equals(confirmPassword.getObject())) {
|
| | | error(getString("gb.passwordsDoNotMatch"));
|
| | | return;
|
| | | }
|
| | | String password = userModel.password;
|
| | | if (!password.toUpperCase().startsWith(StringUtils.MD5_TYPE)
|
| | | && !password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
|
| | | // This is a plain text password.
|
| | | // Check length.
|
| | | int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5);
|
| | | if (minLength < 4) {
|
| | | minLength = 4;
|
| | | }
|
| | | if (password.trim().length() < minLength) {
|
| | | error(MessageFormat.format(getString("gb.passwordTooShort"),
|
| | | minLength));
|
| | | if (GitBlit.self().supportsCredentialChanges()) {
|
| | | if (!userModel.password.equals(confirmPassword.getObject())) {
|
| | | error(getString("gb.passwordsDoNotMatch"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // Optionally store the password MD5 digest.
|
| | | String type = GitBlit.getString(Keys.realm.passwordStorage, "md5");
|
| | | if (type.equalsIgnoreCase("md5")) {
|
| | | // store MD5 digest of password
|
| | | userModel.password = StringUtils.MD5_TYPE
|
| | | + StringUtils.getMD5(userModel.password);
|
| | | } else if (type.equalsIgnoreCase("combined-md5")) {
|
| | | // store MD5 digest of username+password
|
| | | userModel.password = StringUtils.COMBINED_MD5_TYPE
|
| | | + StringUtils.getMD5(username + userModel.password);
|
| | | String password = userModel.password;
|
| | | if (!password.toUpperCase().startsWith(StringUtils.MD5_TYPE)
|
| | | && !password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
|
| | | // This is a plain text password.
|
| | | // Check length.
|
| | | int minLength = GitBlit.getInteger(Keys.realm.minPasswordLength, 5);
|
| | | if (minLength < 4) {
|
| | | minLength = 4;
|
| | | }
|
| | | if (password.trim().length() < minLength) {
|
| | | error(MessageFormat.format(getString("gb.passwordTooShort"),
|
| | | minLength));
|
| | | return;
|
| | | }
|
| | | |
| | | // Optionally store the password MD5 digest.
|
| | | String type = GitBlit.getString(Keys.realm.passwordStorage, "md5");
|
| | | if (type.equalsIgnoreCase("md5")) {
|
| | | // store MD5 digest of password
|
| | | userModel.password = StringUtils.MD5_TYPE
|
| | | + StringUtils.getMD5(userModel.password);
|
| | | } else if (type.equalsIgnoreCase("combined-md5")) {
|
| | | // store MD5 digest of username+password
|
| | | userModel.password = StringUtils.COMBINED_MD5_TYPE
|
| | | + StringUtils.getMD5(username + userModel.password);
|
| | | }
|
| | | } else if (rename
|
| | | && password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
|
| | | error(getString("gb.combinedMd5Rename"));
|
| | | return;
|
| | | }
|
| | | } else if (rename
|
| | | && password.toUpperCase().startsWith(StringUtils.COMBINED_MD5_TYPE)) {
|
| | | error(getString("gb.combinedMd5Rename"));
|
| | | return;
|
| | | }
|
| | |
|
| | | Iterator<String> selectedRepositories = repositories.getSelectedChoices();
|
| | | List<String> repos = new ArrayList<String>();
|
| | | while (selectedRepositories.hasNext()) {
|
| | | repos.add(selectedRepositories.next().toLowerCase());
|
| | | // update user permissions
|
| | | for (RegistrantAccessPermission repositoryPermission : permissions) {
|
| | | userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);
|
| | | }
|
| | | userModel.repositories.clear();
|
| | | userModel.repositories.addAll(repos);
|
| | |
|
| | | Iterator<String> selectedTeams = teams.getSelectedChoices();
|
| | | userModel.teams.clear();
|
| | |
| | |
|
| | | // not all user services support manipulating username and password
|
| | | boolean editCredentials = GitBlit.self().supportsCredentialChanges();
|
| | | |
| | | // not all user services support manipulating display name
|
| | | boolean editDisplayName = GitBlit.self().supportsDisplayNameChanges();
|
| | |
|
| | | // not all user services support manipulating email address
|
| | | boolean editEmailAddress = GitBlit.self().supportsEmailAddressChanges();
|
| | |
|
| | | // not all user services support manipulating team memberships
|
| | | boolean editTeams = GitBlit.self().supportsTeamMembershipChanges();
|
| | |
| | | confirmPassword);
|
| | | confirmPasswordField.setResetPassword(false);
|
| | | form.add(confirmPasswordField.setEnabled(editCredentials));
|
| | | form.add(new TextField<String>("displayName").setEnabled(editDisplayName));
|
| | | form.add(new TextField<String>("emailAddress").setEnabled(editEmailAddress));
|
| | | form.add(new CheckBox("canAdmin"));
|
| | | form.add(new CheckBox("canFork"));
|
| | | form.add(new CheckBox("canCreate"));
|
| | | form.add(new CheckBox("excludeFromFederation"));
|
| | | form.add(repositories);
|
| | | form.add(new RegistrantPermissionsPanel("repositories", repos, permissions, getAccessPermissions()));
|
| | | form.add(teams.setEnabled(editTeams));
|
| | |
|
| | | form.add(new Button("save"));
|