<h1>Groups</h1>
+ <h2>Delete groups</h2>
<table>
<tr>
<th>Group</th>
<td><a href="#" wicket:id="groupDelete">delete</a></td>
</tr>
</table>
+
+ <h2>Create group</h2>
+
<form method="post" wicket:id="groupCreate">
<table>
<tr>
</table>
</form>
+ <h1>Users</h1>
+
+ <h2>Delete users, change passwords, delete users from groups</h2>
+
+ <table>
+ <tr>
+ <th>User</th>
+ <th>Groups</th>
+ <th>Actions</th>
+ </tr>
+ <tr wicket:id="user">
+ <td><span wicket:id="name">username</span></td>
+ <td><span wicket:id="groups"><span wicket:id="group">groupname</span> (<a href="#"
+ wicket:id="remove">del</a>) </span>
+ </td>
+ <td>
+ <a href="#" wicket:id="delete">delete</a>
+
+ <form wicket:id="changePasswordForm" method="post">
+ <table>
+ <tr>
+ <td><input type="password" wicket:id="password"/></td>
+ <td><input type="submit" value="Submit"/></td>
+ </tr>
+ </table>
+ </form>
+ </td>
+ </tr>
+ </table>
+
+ <h2>Create user</h2>
+
+ <form wicket:id="createUserForm">
+ <table>
+ <tr>
+ <th>Username</th>
+ <td><input type="text" wicket:id="user" value=""/></td>
+ </tr>
+ <tr>
+ <th>Password</th>
+ <td><input type="password" wicket:id="password"/></td>
+ </tr>
+ <!--
+ <tr>
+ <th>Group</th>
+ <td>
+ <select wicket:id="group">
+ <option>group1</option>
+ <option>group2</option>
+ </select>
+ </td>
+ </tr>
+ -->
+ <tr>
+ <th></th>
+ <th><input type="submit" value="Create user"/></th>
+ </tr>
+ </table>
+ </form>
+
+
+ <h2>Add user to group</h2>
+
</div>
</wicket:extend>
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.PasswordTextField;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.repeater.RepeatingView;
+import org.apache.wicket.model.IModel;
+import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.Model;
import org.wamblee.security.authentication.UserAdministration;
import org.wamblee.security.authentication.UserMgtException;
add(groupCreate);
_groupName = new TextField("groupName", new Model(""));
groupCreate.add(_groupName);
+
+ RepeatingView user = new RepeatingView("user") {
+ @Override
+ protected void onPopulate() {
+ removeAll();
+ List<String> users = _userAdmin.getUsers();
+ for (final String user : users) {
+ WebMarkupContainer nameContainer = new WebMarkupContainer(newChildId());
+ nameContainer.add(new Label("name", user));
+ add(nameContainer);
+ RepeatingView groups = new RepeatingView("groups") {
+ @Override
+ protected void onPopulate() {
+ removeAll();
+ List<String> groups = _userAdmin.getGroups(user);
+ for (final String group : groups) {
+ WebMarkupContainer groupContainer = new WebMarkupContainer(newChildId());
+ groupContainer.add(new Label("group", group));
+ groupContainer.add(new Link("remove") {
+ @Override
+ public void onClick() {
+ try {
+ _userAdmin.removeUserFromGroup(user, group);
+ }
+ catch (UserMgtException e) {
+ error("Error removing group: " + e.getMessage());
+ }
+ }
+ });
+ add(groupContainer);
+ }
+ }
+ };
+ nameContainer.add(groups);
+ nameContainer.add(new Link("delete") {
+ @Override
+ public void onClick() {
+ try {
+ _userAdmin.removeUser(user);
+ info("Deleted user '" + user + "'");
+ }
+ catch (UserMgtException e) {
+ error("Could not delete user '" + user + "'");
+ }
+ }
+ });
+
+ final PasswordTextField password = new PasswordTextField("password", new Model(""));
+ Form changePassword = new Form("changePasswordForm") {
+ @Override
+ protected void onSubmit() {
+ String value = password.getValue();
+ if (value == null || value.length() == 0) {
+ return;
+ }
+ _userAdmin.setPassword(user, value);
+ info("password for user '" + user + "' changed");
+ }
+ };
+ changePassword.add(password);
+ nameContainer.add(changePassword);
+ }
+ }
+ };
+ add(user);
+
+ {
+ final TextField newUser = new TextField("user", new Model(""));
+ final PasswordTextField passwordNewUser = new PasswordTextField("password", new Model(""));
+ IModel<List<String>> groups = new LoadableDetachableModel<List<String>>() {
+ @Override
+ protected List<String> load() {
+ return _userAdmin.getGroups();
+ }
+ };
+ /*
+ final DropDownChoice groupChoice =
+ new DropDownChoice("group", new Model(""), groups, new IChoiceRenderer() {
+
+ @Override
+ public Object getDisplayValue(Object object) {
+ return object.toString();
+ }
+
+ @Override
+ public String getIdValue(Object object, int index) {
+ if (index < 0) {
+ return "";
+ }
+ return object.toString();
+ }
+ });
+ */
+ Form createUserForm = new Form("createUserForm") {
+ @Override
+ protected void onSubmit() {
+ //System.out.println("Create user " + newUser.getValue() + " " + passwordNewUser.getValue() + " " +
+ // "'" + groupChoice.getValue() + "'");
+ String user = newUser.getValue();
+ String pw = passwordNewUser.getValue();
+
+ //String group = groupChoice.getValue();
+ // if (!_userAdmin.getGroups().contains(group)) {
+ // info("No group selected");
+ // return;
+ // }
+ if (user.length() == 0) {
+ info("No username specified");
+ return;
+ }
+ try {
+ _userAdmin.createUser(user, pw);
+ // _userAdmin.addUserToGroup(user, group);
+ info("User '" + user + "' created");
+ newUser.setModel(new Model(""));
+ }
+ catch (UserMgtException e) {
+ error("Problem creating user '" + user + "': " + e.getMessage());
+ }
+ }
+ };
+ add(createUserForm);
+ createUserForm.add(newUser);
+ createUserForm.add(passwordNewUser);
+ // createUserForm.add(groupChoice);
+ }
}
@Override