protected String ugServiceName;
protected AbstractUserPage(String ugServiceName, final GeoServerUser user) {
this.ugServiceName=ugServiceName;
GeoServerUserGroupService ugService = getUserGroupService(ugServiceName);
boolean emptyPasswd = getSecurityManager().loadPasswordEncoder(ugService.getPasswordEncoderName())
instanceof GeoServerEmptyPasswordEncoder;
boolean hasUserGroupStore = ugService.canCreateStore();
boolean hasRoleStore = hasRoleStore(getSecurityManager().getActiveRoleService().getName());
// build the form
Form form = new Form<Serializable>("form", new CompoundPropertyModel(user));
add(form);
form.add(new TextField("username").setEnabled(hasUserGroupStore));
form.add(new CheckBox("enabled").setEnabled(hasUserGroupStore));
PasswordTextField pw1 = new PasswordTextField("password") {
@Override
public boolean isRequired() {
return isFinalSubmit(this);
}
};
form.add(pw1);
pw1.setResetPassword(false);
pw1.setEnabled(hasUserGroupStore && !emptyPasswd);
PasswordTextField pw2 = new PasswordTextField("confirmPassword",
new Model(user.getPassword())) {
@Override
public boolean isRequired() {
return isFinalSubmit(this);
}
};
form.add(pw2);
pw2.setResetPassword(false);
pw2.setEnabled(hasUserGroupStore && !emptyPasswd);
form.add(new PropertyEditorFormComponent("properties").setEnabled(hasUserGroupStore));
form.add(userGroupPalette = new UserGroupPaletteFormComponent("groups", ugServiceName, user));
userGroupPalette.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateCalculatedRoles(target);
}
});
userGroupPalette.setEnabled(hasUserGroupStore);
List<GeoServerRole> roles;
try {
roles = new ArrayList(
getSecurityManager().getActiveRoleService().getRolesForUser(user.getUsername()));
} catch (IOException e) {
throw new WicketRuntimeException(e);
}
form.add(rolePalette = new RolePaletteFormComponent("roles", new ListModel(roles)));
rolePalette.add(new AjaxFormComponentUpdatingBehavior("onchange") {
@Override
protected void onUpdate(AjaxRequestTarget target) {
updateCalculatedRoles(target);
updateGroupAdminList(target);
}
});
rolePalette.setOutputMarkupId(true);
rolePalette.setEnabled(hasRoleStore);
boolean isGroupAdmin = roles.contains(GeoServerRole.GROUP_ADMIN_ROLE);
List<GeoServerUserGroup> adminGroups = new ArrayList();
if (isGroupAdmin) {
for (String groupName : GroupAdminProperty.get(user.getProperties())) {
try {
adminGroups.add(ugService.getGroupByGroupname(groupName));
} catch (IOException e) {
throw new WicketRuntimeException(e);
}
}
}