import org.argeo.security.ui.admin.SecurityAdminPlugin;
import org.argeo.security.ui.admin.internal.UiAdminUtils;
import org.argeo.security.ui.admin.internal.UserAdminConstants;
-import org.argeo.security.ui.admin.views.UsersView;
+import org.argeo.security.ui.admin.internal.UserAdminWrapper;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.window.Window;
import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;
import org.osgi.service.useradmin.Role;
import org.osgi.service.useradmin.User;
-import org.osgi.service.useradmin.UserAdmin;
+import org.osgi.service.useradmin.UserAdminEvent;
/** Open a wizard that enables creation of a new user. */
public class NewUser extends AbstractHandler {
// private final static Log log = LogFactory.getLog(NewUser.class);
-
public final static String ID = SecurityAdminPlugin.PLUGIN_ID + ".newUser";
- private UserAdmin userAdmin;
+ /* DEPENDENCY INJECTION */
+ private UserAdminWrapper userAdminWrapper;
// TODO implement a dynamic choice of the base dn
private String getDn(String uid) {
WizardDialog dialog = new WizardDialog(
HandlerUtil.getActiveShell(event), newUserWizard);
- // Force refresh until the listener are implemented
- if (Window.OK == dialog.open())
- forceRefresh(event);
- return null;
- }
+ dialog.open();
- private void forceRefresh(ExecutionEvent event) {
- IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
- if (iww == null)
- return;
- IWorkbenchPage activePage = iww.getActivePage();
- IWorkbenchPart part = activePage.getActivePart();
- if (part instanceof UsersView)
- ((UsersView) part).refresh();
+ // // Force refresh until the listener are implemented
+ // if (Window.OK == dialog.open())
+ // forceRefresh(event);
+ return null;
}
- public void setUserAdmin(UserAdmin userAdmin) {
- this.userAdmin = userAdmin;
- }
+ // private void forceRefresh(ExecutionEvent event) {
+ // IWorkbenchWindow iww = HandlerUtil.getActiveWorkbenchWindow(event);
+ // if (iww == null)
+ // return;
+ // IWorkbenchPage activePage = iww.getActivePage();
+ // IWorkbenchPart part = activePage.getActivePart();
+ // if (part instanceof UsersView)
+ // ((UsersView) part).refresh();
+ // }
private class NewUserWizard extends Wizard {
public void addPages() {
mainUserInfo = new MainUserInfoWizardPage();
addPage(mainUserInfo);
- String message = "Dummy wizard to ease user creation tests: mail, last name are automatically "
- + "generated form the uid, password are defauted to 'demo'.";
+ String message = "Dummy wizard to ease user creation tests:\n Mail and last name are automatically "
+ + "generated form the uid. Password are defauted to 'demo'.";
mainUserInfo.setMessage(message, WizardPage.WARNING);
}
return false;
String username = mainUserInfo.getUsername();
try {
+ userAdminWrapper.beginTransactionIfNeeded();
char[] password = mainUserInfo.getPassword();
- User user = (User) userAdmin.createRole(getDn(username),
- Role.USER);
+ User user = (User) userAdminWrapper.getUserAdmin().createRole(
+ getDn(username), Role.USER);
Dictionary props = user.getProperties();
if (UiAdminUtils.notNull(mailStr))
props.put(UserAdminConstants.KEY_MAIL, mailStr);
- // TODO MANAGE Password
- // pwd1Txt.getText();
+ user.getCredentials().put(null, password);
+
+ userAdminWrapper.notifyListeners(new UserAdminEvent(null,
+ UserAdminEvent.ROLE_CREATED, user));
return true;
} catch (Exception e) {
ErrorFeedback.show("Cannot create new user " + username, e);
if (name.trim().equals(""))
return "User name must not be empty";
- Role role = userAdmin.getRole(getDn(name));
+ Role role = userAdminWrapper.getUserAdmin()
+ .getRole(getDn(name));
if (role != null)
return "User " + name + " already exists";
if (!primaryMailTxt.getText().matches(
}
}
- // Local helpers
-
+ /* DEPENDENCY INJECTION */
+ public void setUserAdminWrapper(UserAdminWrapper userAdminWrapper) {
+ this.userAdminWrapper = userAdminWrapper;
+ }
}
\ No newline at end of file