2 * Copyright 2005-2010 the original author or authors.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.wamblee.photos.wicket;
18 import java.util.List;
19 import java.util.logging.Logger;
20 import javax.inject.Inject;
22 import org.apache.wicket.PageParameters;
23 import org.apache.wicket.markup.html.WebMarkupContainer;
24 import org.apache.wicket.markup.html.basic.Label;
25 import org.apache.wicket.markup.html.form.Form;
26 import org.apache.wicket.markup.html.form.TextField;
27 import org.apache.wicket.markup.html.link.Link;
28 import org.apache.wicket.markup.repeater.RepeatingView;
29 import org.apache.wicket.model.Model;
30 import org.wamblee.security.authentication.UserAdministration;
31 import org.wamblee.security.authentication.UserMgtException;
36 public class AdminPage extends BasePage {
38 private static final Logger LOGGER = Logger.getLogger(AdminPage.class.getName());
40 private static final long serialVersionUID = 1L;
43 private transient UserAdministration _userAdmin;
45 private TextField _groupName;
48 * Constructor that is invoked when page is invoked without a session.
50 * @param parameters Page parameters
52 public AdminPage(final PageParameters parameters) throws Exception {
55 RepeatingView groupDelete = new RepeatingView("groupDelete") {
57 protected void onPopulate() {
59 List<String> groups = _userAdmin.getGroups();
60 for (final String group : groups) {
61 WebMarkupContainer container = new WebMarkupContainer(newChildId());
63 container.add(new Label("groupName", group));
64 container.add(new Link("groupDelete") {
66 public void onClick() {
68 _userAdmin.removeGroup(group);
69 info("Group '" + group + "' removed");
71 catch (UserMgtException e) {
72 error("Could not remove group '" + group + "'");
77 public boolean isVisible() {
78 return _userAdmin.getUsers(group).isEmpty();
86 Form groupCreate = new Form("groupCreate") {
88 protected void onSubmit() {
89 String name = _groupName.getValue();
90 if (name == null || name.length() == 0) {
94 _userAdmin.createGroup(name);
95 _groupName.setModel(new Model(""));
96 info("Group '" + name + "' created");
98 catch (UserMgtException e) {
99 error("Group '" + name + "' could not be created");
104 _groupName = new TextField("groupName", new Model(""));
105 groupCreate.add(_groupName);
109 protected boolean isAdminPage() {