]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/internal/parts/UserBatchUpdateWizard.java
Improve and simplify OSGi Boot
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / internal / parts / UserBatchUpdateWizard.java
index aa6e2c6befa89e6cc8796f776469ceb1b4a3f3d6..31b2042b6ec14d2ec91eabefc5f43d2af0697c50 100644 (file)
@@ -1,18 +1,3 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *         http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
 package org.argeo.security.ui.admin.internal.parts;
 
 import java.util.ArrayList;
@@ -20,89 +5,82 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-import javax.jcr.Node;
-import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-import javax.jcr.version.VersionManager;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.ArgeoMonitor;
-import org.argeo.eclipse.ui.EclipseArgeoMonitor;
-import org.argeo.eclipse.ui.parts.UsersTable;
+import org.argeo.cms.CmsException;
+import org.argeo.cms.auth.AuthConstants;
+import org.argeo.cms.util.useradmin.UserAdminUtils;
+import org.argeo.eclipse.ui.ColumnDefinition;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.eclipse.ui.parts.LdifUsersTable;
 import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrUserDetails;
-import org.argeo.security.ui.PrivilegedJob;
-import org.argeo.security.ui.admin.SecurityAdminPlugin;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
+import org.argeo.osgi.useradmin.LdifName;
+import org.argeo.security.ui.admin.internal.UserAdminWrapper;
+import org.argeo.security.ui.admin.internal.providers.CommonNameLP;
+import org.argeo.security.ui.admin.internal.providers.DomainNameLP;
+import org.argeo.security.ui.admin.internal.providers.MailLP;
+import org.argeo.security.ui.admin.internal.providers.UserNameLP;
 import org.eclipse.jface.dialogs.IPageChangeProvider;
 import org.eclipse.jface.dialogs.IPageChangedListener;
+import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.dialogs.PageChangedEvent;
 import org.eclipse.jface.wizard.IWizardContainer;
 import org.eclipse.jface.wizard.Wizard;
 import org.eclipse.jface.wizard.WizardPage;
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
 import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.layout.FillLayout;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Combo;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
+import org.osgi.framework.InvalidSyntaxException;
+import org.osgi.service.useradmin.Role;
+import org.osgi.service.useradmin.User;
 
 /** Wizard to update users */
 public class UserBatchUpdateWizard extends Wizard {
+
        private final static Log log = LogFactory
                        .getLog(UserBatchUpdateWizard.class);
-       private Session session;
-       private UserAdminService userAdminService;
+       private UserAdminWrapper userAdminWrapper;
 
        // pages
        private ChooseCommandWizardPage chooseCommandPage;
        private ChooseUsersWizardPage userListPage;
        private ValidateAndLaunchWizardPage validatePage;
 
-       // /////////////////////////////////////////////////
-       // / Definition of the various implemented commands
+       // Various implemented commands keys
        private final static String CMD_UPDATE_PASSWORD = "resetPassword";
        private final static String CMD_GROUP_MEMBERSHIP = "groupMembership";
 
        private final Map<String, String> commands = new HashMap<String, String>() {
                private static final long serialVersionUID = 1L;
                {
-                       put("Enable user(s)", ArgeoNames.ARGEO_ENABLED);
-                       put("Expire credentials", ArgeoNames.ARGEO_CREDENTIALS_NON_EXPIRED);
-                       put("Expire account(s)", ArgeoNames.ARGEO_ACCOUNT_NON_EXPIRED);
-                       put("Lock account(s)", ArgeoNames.ARGEO_ACCOUNT_NON_LOCKED);
                        put("Reset password(s)", CMD_UPDATE_PASSWORD);
                        // TODO implement role / group management
                        // put("Add/Remove from group", CMD_GROUP_MEMBERSHIP);
                }
        };
 
-       public UserBatchUpdateWizard(Session session,
-                       UserAdminService userAdminService) {
-               this.session = session;
-               this.userAdminService = userAdminService;
+       public UserBatchUpdateWizard(UserAdminWrapper userAdminWrapper) {
+               this.userAdminWrapper = userAdminWrapper;
        }
 
        @Override
        public void addPages() {
                chooseCommandPage = new ChooseCommandWizardPage();
                addPage(chooseCommandPage);
-               userListPage = new ChooseUsersWizardPage(session);
+               userListPage = new ChooseUsersWizardPage();
                addPage(userListPage);
-               validatePage = new ValidateAndLaunchWizardPage(session);
+               validatePage = new ValidateAndLaunchWizardPage();
                addPage(validatePage);
        }
 
@@ -110,203 +88,160 @@ public class UserBatchUpdateWizard extends Wizard {
        public boolean performFinish() {
                if (!canFinish())
                        return false;
+               UserTransaction ut = userAdminWrapper.getUserTransaction();
+               try {
+                       if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION
+                                       && !MessageDialog.openConfirm(getShell(),
+                                                       "Existing Transaction",
+                                                       "A user transaction is already existing, "
+                                                                       + "are you sure you want to proceed ?"))
+                               return false;
+               } catch (SystemException e) {
+                       throw new CmsException("Cannot get user transaction state "
+                                       + "before user batch update", e);
+               }
+
+               // We cannot use jobs, user modifications are still meant to be done in
+               // the UIThread
+               // UpdateJob job = null;
+               // if (job != null)
+               // job.schedule();
 
-               UpdateJob job = null;
-               if (ArgeoNames.ARGEO_ENABLED.equals(chooseCommandPage.getCommand())) {
-                       job = new UpdateBoolean(session, userListPage.getSelectedUsers(),
-                                       ArgeoNames.ARGEO_ENABLED,
-                                       chooseCommandPage.getBoleanValue());
-               } else if (ArgeoNames.ARGEO_CREDENTIALS_NON_EXPIRED
-                               .equals(chooseCommandPage.getCommand())) {
-                       job = new UpdateBoolean(session, userListPage.getSelectedUsers(),
-                                       ArgeoNames.ARGEO_CREDENTIALS_NON_EXPIRED,
-                                       chooseCommandPage.getBoleanValue());
-               } else if (ArgeoNames.ARGEO_ACCOUNT_NON_EXPIRED
-                               .equals(chooseCommandPage.getCommand())) {
-                       job = new UpdateBoolean(session, userListPage.getSelectedUsers(),
-                                       ArgeoNames.ARGEO_ACCOUNT_NON_EXPIRED,
-                                       chooseCommandPage.getBoleanValue());
-               } else if (ArgeoNames.ARGEO_ACCOUNT_NON_LOCKED.equals(chooseCommandPage
-                               .getCommand())) {
-                       job = new UpdateBoolean(session, userListPage.getSelectedUsers(),
-                                       ArgeoNames.ARGEO_ACCOUNT_NON_LOCKED,
-                                       chooseCommandPage.getBoleanValue());
-               } else if (CMD_UPDATE_PASSWORD.equals(chooseCommandPage.getCommand())) {
-                       String newValue = chooseCommandPage.getPwdValue();
+               if (CMD_UPDATE_PASSWORD.equals(chooseCommandPage.getCommand())) {
+                       char[] newValue = chooseCommandPage.getPwdValue();
                        if (newValue == null)
-                               throw new ArgeoException(
+                               throw new CmsException(
                                                "Password cannot be null or an empty string");
-                       job = new ResetPassword(session, userAdminService,
+                       ResetPassword job = new ResetPassword(userAdminWrapper,
                                        userListPage.getSelectedUsers(), newValue);
+                       job.doUpdate();
                }
-
-               if (job != null)
-                       job.schedule();
                return true;
        }
 
-       public void setSession(Session session) {
-               this.session = session;
-       }
-
        public boolean canFinish() {
                if (this.getContainer().getCurrentPage() == validatePage)
                        return true;
                return false;
        }
 
-       // /////////////////////////
-       // REEL UPDATE JOB
-       private class UpdateBoolean extends UpdateJob {
-               private String propertyName;
-               private boolean value;
-
-               public UpdateBoolean(Session session, List<Node> nodesToUpdate,
-                               String propertyName, boolean value) {
-                       super(session, nodesToUpdate);
-                       this.propertyName = propertyName;
-                       this.value = value;
-               }
+       private class ResetPassword {
+               private char[] newPwd;
+               private UserAdminWrapper userAdminWrapper;
+               private List<User> usersToUpdate;
 
-               protected void doUpdate(Node node) {
-                       try {
-                               node.setProperty(propertyName, value);
-                       } catch (RepositoryException re) {
-                               throw new ArgeoException(
-                                               "Unable to update boolean value for node " + node, re);
-                       }
+               public ResetPassword(UserAdminWrapper userAdminWrapper,
+                               List<User> usersToUpdate, char[] newPwd) {
+                       this.newPwd = newPwd;
+                       this.usersToUpdate = usersToUpdate;
+                       this.userAdminWrapper = userAdminWrapper;
                }
-       }
-
-       private class ResetPassword extends UpdateJob {
-               private String newValue;
-               private UserAdminService userAdminService;
 
-               public ResetPassword(Session session,
-                               UserAdminService userAdminService, List<Node> nodesToUpdate,
-                               String newValue) {
-                       super(session, nodesToUpdate);
-                       this.newValue = newValue;
-                       this.userAdminService = userAdminService;
-               }
-
-               protected void doUpdate(Node node) {
+               @SuppressWarnings("unchecked")
+               protected void doUpdate() {
+                       userAdminWrapper.beginTransactionIfNeeded();
                        try {
-                               String userId = node.getProperty(ArgeoNames.ARGEO_USER_ID)
-                                               .getString();
-                               if (userAdminService.userExists(userId)) {
-                                       JcrUserDetails userDetails = (JcrUserDetails) userAdminService
-                                                       .loadUserByUsername(userId);
-                                       userAdminService.updateUser(userDetails
-                                                       .cloneWithNewPassword(newValue));
-                               }
-                       } catch (RepositoryException re) {
-                               throw new ArgeoException(
-                                               "Unable to update boolean value for node " + node, re);
-                       }
-               }
-       }
-
-       @SuppressWarnings("unused")
-       private class AddToGroup extends UpdateJob {
-               private String groupID;
-               private Session session;
-
-               public AddToGroup(Session session, List<Node> nodesToUpdate,
-                               String groupID) {
-                       super(session, nodesToUpdate);
-                       this.session = session;
-                       this.groupID = groupID;
-               }
-
-               protected void doUpdate(Node node) {
-                       log.info("Add/Remove to group actions are not yet implemented");
-                       // TODO implement this
-                       // try {
-                       // throw new ArgeoException("Not yet implemented");
-                       // } catch (RepositoryException re) {
-                       // throw new ArgeoException(
-                       // "Unable to update boolean value for node " + node, re);
-                       // }
-               }
-       }
-
-       /**
-        * Base privileged job that will be run asynchronously to perform the batch
-        * update
-        */
-       private abstract class UpdateJob extends PrivilegedJob {
-
-               private final Session currSession;
-               private final List<Node> nodesToUpdate;
-
-               protected abstract void doUpdate(Node node);
-
-               public UpdateJob(Session session, List<Node> nodesToUpdate) {
-                       super("Perform update");
-                       try {
-                               this.currSession = session.getRepository().login();
-                               // "move" nodes to update in the new session
-                               // the "old" session will be closed by the calling command
-                               // before the job has effectively ran
-                               // TODO there must be a cleaner way to do.
-                               List<Node> nodes = new ArrayList<Node>();
-                               for (Node node : nodesToUpdate) {
-                                       nodes.add(currSession.getNode(node.getPath()));
-                               }
-                               this.nodesToUpdate = nodes;
-                       } catch (RepositoryException e) {
-                               throw new ArgeoException("Error while dupplicating "
-                                               + "session for job", e);
-                       }
-               }
-
-               @Override
-               protected IStatus doRun(IProgressMonitor progressMonitor) {
-                       try {
-                               ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
-                               VersionManager vm = currSession.getWorkspace()
-                                               .getVersionManager();
-                               int total = nodesToUpdate.size();
-                               monitor.beginTask("Performing change", total);
-                               for (Node node : nodesToUpdate) {
-                                       String path = node.getPath();
-                                       vm.checkout(path);
-                                       doUpdate(node);
-                                       currSession.save();
-                                       vm.checkin(path);
-                                       monitor.worked(1);
+                               for (User user : usersToUpdate) {
+                                       // the char array is emptied after being used.
+                                       user.getCredentials().put(null, newPwd.clone());
                                }
+                               userAdminWrapper.commitOrNotifyTransactionStateChange();
                        } catch (Exception e) {
-                               log.error("Cannot perform batch update on users", e);
-                               // e.printStackTrace();
-
-                               // Dig exception to find the root cause that will enable the
-                               // user to understand the problem
-                               Throwable cause = e;
-                               Throwable originalCause = e;
-                               while (cause != null) {
-                                       if (log.isTraceEnabled())
-                                               log.trace("Parent Cause message : "
-                                                               + cause.getMessage());
-                                       originalCause = cause;
-                                       cause = cause.getCause();
-                               }
-                               return new Status(IStatus.ERROR, SecurityAdminPlugin.PLUGIN_ID,
-                                               "Cannot perform updates.", originalCause);
+                               throw new CmsException("Cannot perform batch update on users",
+                                               e);
                        } finally {
-                               JcrUtils.logoutQuietly(currSession);
+                               UserTransaction ut = userAdminWrapper.getUserTransaction();
+                               try {
+                                       if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
+                                               ut.rollback();
+                               } catch (IllegalStateException | SecurityException
+                                               | SystemException e) {
+                                       log.error("Unable to rollback session in 'finally', "
+                                                       + "the system might be in a dirty state");
+                                       e.printStackTrace();
+                               }
                        }
-                       return Status.OK_STATUS;
                }
        }
 
-       // //////////////////////
-       // Pages definition
+       // @SuppressWarnings("unused")
+       // private class AddToGroup extends UpdateJob {
+       // private String groupID;
+       // private Session session;
+       //
+       // public AddToGroup(Session session, List<Node> nodesToUpdate,
+       // String groupID) {
+       // super(session, nodesToUpdate);
+       // this.session = session;
+       // this.groupID = groupID;
+       // }
+       //
+       // protected void doUpdate(Node node) {
+       // log.info("Add/Remove to group actions are not yet implemented");
+       // // TODO implement this
+       // // try {
+       // // throw new CmsException("Not yet implemented");
+       // // } catch (RepositoryException re) {
+       // // throw new CmsException(
+       // // "Unable to update boolean value for node " + node, re);
+       // // }
+       // }
+       // }
+
+       // /**
+       // * Base privileged job that will be run asynchronously to perform the
+       // batch
+       // * update
+       // */
+       // private abstract class UpdateJob extends PrivilegedJob {
+       //
+       // private final UserAdminWrapper userAdminWrapper;
+       // private final List<User> usersToUpdate;
+       //
+       // protected abstract void doUpdate(User user);
+       //
+       // public UpdateJob(UserAdminWrapper userAdminWrapper,
+       // List<User> usersToUpdate) {
+       // super("Perform update");
+       // this.usersToUpdate = usersToUpdate;
+       // this.userAdminWrapper = userAdminWrapper;
+       // }
+       //
+       // @Override
+       // protected IStatus doRun(IProgressMonitor progressMonitor) {
+       // try {
+       // ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor);
+       // int total = usersToUpdate.size();
+       // monitor.beginTask("Performing change", total);
+       // userAdminWrapper.beginTransactionIfNeeded();
+       // for (User user : usersToUpdate) {
+       // doUpdate(user);
+       // monitor.worked(1);
+       // }
+       // userAdminWrapper.getUserTransaction().commit();
+       // } catch (Exception e) {
+       // throw new CmsException(
+       // "Cannot perform batch update on users", e);
+       // } finally {
+       // UserTransaction ut = userAdminWrapper.getUserTransaction();
+       // try {
+       // if (ut.getStatus() != javax.transaction.Status.STATUS_NO_TRANSACTION)
+       // ut.rollback();
+       // } catch (IllegalStateException | SecurityException
+       // | SystemException e) {
+       // log.error("Unable to rollback session in 'finally', "
+       // + "the system might be in a dirty state");
+       // e.printStackTrace();
+       // }
+       // }
+       // return Status.OK_STATUS;
+       // }
+       // }
+
+       // PAGES
        /** Displays a combo box that enables user to choose which action to perform */
        private class ChooseCommandWizardPage extends WizardPage {
-               private static final long serialVersionUID = 1L;
-
+               private static final long serialVersionUID = -8069434295293996633L;
                private Combo chooseCommandCmb;
                private Button trueChk;
                private Text valueTxt;
@@ -324,21 +259,16 @@ public class UserBatchUpdateWizard extends Wizard {
                        Composite container = new Composite(parent, SWT.NO_FOCUS);
                        container.setLayout(gl);
 
-                       chooseCommandCmb = new Combo(container, SWT.NO_FOCUS);
-                       String[] values = commands.keySet().toArray(
-                                       new String[commands.size()]);
+                       chooseCommandCmb = new Combo(container, SWT.READ_ONLY);
+                       chooseCommandCmb.setLayoutData(EclipseUiUtils.fillWidth());
+                       String[] values = commands.keySet().toArray(new String[0]);
                        chooseCommandCmb.setItems(values);
-                       chooseCommandCmb.setLayoutData(new GridData(SWT.FILL, SWT.TOP,
-                                       true, false));
 
                        final Composite bottomPart = new Composite(container, SWT.NO_FOCUS);
-                       gl = new GridLayout();
-                       gl.horizontalSpacing = gl.marginWidth = gl.verticalSpacing = 0;
-                       bottomPart.setLayout(gl);
-                       bottomPart.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,
-                                       true));
+                       bottomPart.setLayoutData(EclipseUiUtils.fillAll());
+                       bottomPart.setLayout(EclipseUiUtils.noSpaceGridLayout());
 
-                       chooseCommandCmb.addSelectionListener(new SelectionListener() {
+                       chooseCommandCmb.addSelectionListener(new SelectionAdapter() {
                                private static final long serialVersionUID = 1L;
 
                                @Override
@@ -349,27 +279,15 @@ public class UserBatchUpdateWizard extends Wizard {
                                                populateGroupCmp(bottomPart);
                                        else
                                                populateBooleanFlagCmp(bottomPart);
-                                       bottomPart.pack(true);
-                                       bottomPart.layout();
-                               }
-
-                               @Override
-                               public void widgetDefaultSelected(SelectionEvent e) {
+                                       checkPageComplete();
+                                       bottomPart.layout(true, true);
                                }
                        });
-
                        setControl(container);
                }
 
-               private void cleanParent(Composite parent) {
-                       if (parent.getChildren().length > 0) {
-                               for (Control control : parent.getChildren())
-                                       control.dispose();
-                       }
-               }
-
                private void populateBooleanFlagCmp(Composite parent) {
-                       cleanParent(parent);
+                       EclipseUiUtils.clear(parent);
                        trueChk = new Button(parent, SWT.CHECK);
                        trueChk.setText("Do it. (It will to the contrary if unchecked)");
                        trueChk.setSelection(true);
@@ -377,30 +295,49 @@ public class UserBatchUpdateWizard extends Wizard {
                }
 
                private void populatePasswordCmp(Composite parent) {
-                       cleanParent(parent);
+                       EclipseUiUtils.clear(parent);
                        Composite body = new Composite(parent, SWT.NO_FOCUS);
+
+                       ModifyListener ml = new ModifyListener() {
+                               private static final long serialVersionUID = -1558726363536729634L;
+
+                               @Override
+                               public void modifyText(ModifyEvent event) {
+                                       checkPageComplete();
+                               }
+                       };
+
                        body.setLayout(new GridLayout(2, false));
                        body.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-                       pwdTxt = createLP(body, "New password", "");
-                       pwd2Txt = createLP(body, "Repeat password", "");
+                       pwdTxt = EclipseUiUtils.createGridLP(body, "New password", ml);
+                       pwd2Txt = EclipseUiUtils.createGridLP(body, "Repeat password", ml);
                }
 
-               /** Creates label and password. */
-               protected Text createLP(Composite body, String label, String value) {
-                       Label lbl = new Label(body, SWT.NONE);
-                       lbl.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
-                       lbl.setText(label);
-                       Text text = new Text(body, SWT.BORDER | SWT.PASSWORD);
-                       text.setText(value);
-                       text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
-                       return text;
+               private void checkPageComplete() {
+                       String errorMsg = null;
+                       if (chooseCommandCmb.getSelectionIndex() < 0)
+                               errorMsg = "Please select an action";
+                       else if (CMD_UPDATE_PASSWORD.equals(getCommand())) {
+                               if (EclipseUiUtils.isEmpty(pwdTxt.getText())
+                                               || pwdTxt.getText().length() < 4)
+                                       errorMsg = "Please enter a password that is at least 4 character long";
+                               else if (!pwdTxt.getText().equals(pwd2Txt.getText()))
+                                       errorMsg = "Passwords are different";
+                       }
+                       if (EclipseUiUtils.notEmpty(errorMsg)) {
+                               setMessage(errorMsg, WizardPage.ERROR);
+                               setPageComplete(false);
+                       } else {
+                               setMessage("Page complete, you can proceed to user choice",
+                                               WizardPage.INFORMATION);
+                               setPageComplete(true);
+                       }
+
+                       getContainer().updateButtons();
                }
 
                private void populateGroupCmp(Composite parent) {
-                       if (parent.getChildren().length > 0) {
-                               for (Control control : parent.getChildren())
-                                       control.dispose();
-                       }
+                       EclipseUiUtils.clear(parent);
                        trueChk = new Button(parent, SWT.CHECK);
                        trueChk.setText("Add to group. (It will remove user(s) from the "
                                        + "corresponding group if unchecked)");
@@ -418,6 +355,7 @@ public class UserBatchUpdateWizard extends Wizard {
                                        .getSelectionIndex());
                }
 
+               @SuppressWarnings("unused")
                protected boolean getBoleanValue() {
                        // FIXME this is not consistent and will lead to errors.
                        if (ArgeoNames.ARGEO_ENABLED.equals(getCommand()))
@@ -437,22 +375,15 @@ public class UserBatchUpdateWizard extends Wizard {
                        return value;
                }
 
-               protected String getPwdValue() {
-                       String newPwd = null;
-                       if (pwdTxt == null || pwd2Txt == null)
+               protected char[] getPwdValue() {
+                       // We do not directly reset the password text fields: There is no
+                       // need to over secure this process: setting a pwd to multi users
+                       // at the same time is anyhow a bad practice and should be used only
+                       // in test environment or for temporary access
+                       if (pwdTxt == null || pwdTxt.isDisposed())
                                return null;
-                       if (!pwdTxt.getText().equals("") || !pwd2Txt.getText().equals("")) {
-                               if (pwdTxt.getText().equals(pwd2Txt.getText())) {
-                                       newPwd = pwdTxt.getText();
-                                       pwdTxt.setText("");
-                                       pwd2Txt.setText("");
-                               } else {
-                                       pwdTxt.setText("");
-                                       pwd2Txt.setText("");
-                                       throw new ArgeoException("Passwords are not equals");
-                               }
-                       }
-                       return newPwd;
+                       else
+                               return pwdTxt.getText().toCharArray();
                }
        }
 
@@ -462,29 +393,45 @@ public class UserBatchUpdateWizard extends Wizard {
         */
        private class ChooseUsersWizardPage extends WizardPage implements
                        IPageChangedListener {
-               private static final long serialVersionUID = 1L;
-               private UsersTable userTableCmp;
-               private Composite container;
-               private Session session;
+               private static final long serialVersionUID = 7651807402211214274L;
+               private ChooseUserTableViewer userTableCmp;
 
-               public ChooseUsersWizardPage(Session session) {
+               public ChooseUsersWizardPage() {
                        super("Choose Users");
-                       this.session = session;
                        setTitle("Select users who will be impacted");
                }
 
                @Override
                public void createControl(Composite parent) {
-                       container = new Composite(parent, SWT.NONE);
-                       container.setLayout(new FillLayout());
-                       userTableCmp = new MyUserTableCmp(container, SWT.NO_FOCUS, session);
+                       Composite pageCmp = new Composite(parent, SWT.NONE);
+                       pageCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
+
+                       // Define the displayed columns
+                       List<ColumnDefinition> columnDefs = new ArrayList<ColumnDefinition>();
+                       columnDefs.add(new ColumnDefinition(new CommonNameLP(),
+                                       "Common Name", 150));
+                       columnDefs.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
+                       columnDefs.add(new ColumnDefinition(new DomainNameLP(), "Domain",
+                                       200));
+
+                       // Only show technical DN to admin
+                       if (UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
+                               columnDefs.add(new ColumnDefinition(new UserNameLP(),
+                                               "Distinguished Name", 300));
+
+                       userTableCmp = new ChooseUserTableViewer(pageCmp, SWT.MULTI
+                                       | SWT.H_SCROLL | SWT.V_SCROLL);
+                       userTableCmp.setLayoutData(EclipseUiUtils.fillAll());
+                       userTableCmp.setColumnDefinitions(columnDefs);
                        userTableCmp.populate(true, true);
-                       setControl(container);
+                       userTableCmp.refresh();
+
+                       setControl(pageCmp);
 
                        // Add listener to update message when shown
-                       final IWizardContainer container = this.getContainer();
-                       if (container instanceof IPageChangeProvider) {
-                               ((IPageChangeProvider) container).addPageChangedListener(this);
+                       final IWizardContainer wContainer = this.getContainer();
+                       if (wContainer instanceof IPageChangeProvider) {
+                               ((IPageChangeProvider) wContainer).addPageChangedListener(this);
                        }
 
                }
@@ -498,71 +445,105 @@ public class UserBatchUpdateWizard extends Wizard {
                        }
                }
 
-               protected List<Node> getSelectedUsers() {
+               protected List<User> getSelectedUsers() {
                        return userTableCmp.getSelectedUsers();
                }
 
-               private class MyUserTableCmp extends UsersTable {
+               private class ChooseUserTableViewer extends LdifUsersTable {
+                       private static final long serialVersionUID = 5080437561015853124L;
+                       private final String[] knownProps = { LdifName.uid.name(),
+                                       LdifName.dn.name(), LdifName.cn.name(),
+                                       LdifName.givenName.name(), LdifName.sn.name(),
+                                       LdifName.mail.name() };
 
-                       private static final long serialVersionUID = 1L;
-
-                       public MyUserTableCmp(Composite parent, int style, Session session) {
-                               super(parent, style, session);
+                       public ChooseUserTableViewer(Composite parent, int style) {
+                               super(parent, style);
                        }
 
                        @Override
-                       protected void refreshFilteredList() {
-                               List<Node> nodes = new ArrayList<Node>();
+                       protected List<User> listFilteredElements(String filter) {
+                               Role[] roles;
+
                                try {
-                                       NodeIterator ni = listFilteredElements(session,
-                                                       getFilterString());
-
-                                       users: while (ni.hasNext()) {
-                                               Node currNode = ni.nextNode();
-                                               String username = currNode.hasProperty(ARGEO_USER_ID) ? currNode
-                                                               .getProperty(ARGEO_USER_ID).getString() : "";
-                                               if (username.equals(session.getUserID()))
-                                                       continue users;
-                                               else
-                                                       nodes.add(currNode);
-                                       }
-                                       getTableViewer().setInput(nodes.toArray());
-                               } catch (RepositoryException e) {
-                                       throw new ArgeoException("Unable to list users", e);
+                                       StringBuilder builder = new StringBuilder();
+
+                                       StringBuilder tmpBuilder = new StringBuilder();
+                                       if (EclipseUiUtils.notEmpty(filter))
+                                               for (String prop : knownProps) {
+                                                       tmpBuilder.append("(");
+                                                       tmpBuilder.append(prop);
+                                                       tmpBuilder.append("=*");
+                                                       tmpBuilder.append(filter);
+                                                       tmpBuilder.append("*)");
+                                               }
+                                       if (tmpBuilder.length() > 1) {
+                                               builder.append("(&(")
+                                                               .append(LdifName.objectClass.name())
+                                                               .append("=")
+                                                               .append(LdifName.inetOrgPerson.name())
+                                                               .append(")(|");
+                                               builder.append(tmpBuilder.toString());
+                                               builder.append("))");
+                                       } else
+                                               builder.append("(").append(LdifName.objectClass.name())
+                                                               .append("=")
+                                                               .append(LdifName.inetOrgPerson.name())
+                                                               .append(")");
+                                       roles = userAdminWrapper.getUserAdmin().getRoles(
+                                                       builder.toString());
+                               } catch (InvalidSyntaxException e) {
+                                       throw new CmsException("Unable to get roles with filter: "
+                                                       + filter, e);
                                }
+                               List<User> users = new ArrayList<User>();
+                               for (Role role : roles)
+                                       // Prevent current logged in user to perform batch on
+                                       // himself
+                                       if (!UserAdminUtils.isCurrentUser((User) role))
+                                               users.add((User) role);
+                               return users;
                        }
                }
        }
 
-       /**
-        * Recapitulation of input data before running real update
-        */
+       /** Summary of input data before launching the process */
        private class ValidateAndLaunchWizardPage extends WizardPage implements
                        IPageChangedListener {
-               private static final long serialVersionUID = 1L;
-               private UsersTable userTableCmp;
-               private Session session;
+               private static final long serialVersionUID = 7098918351451743853L;
+               private ChosenUsersTableViewer userTableCmp;
 
-               public ValidateAndLaunchWizardPage(Session session) {
+               public ValidateAndLaunchWizardPage() {
                        super("Validate and launch");
-                       this.session = session;
                        setTitle("Validate and launch");
                }
 
                @Override
                public void createControl(Composite parent) {
-                       Composite mainCmp = new Composite(parent, SWT.NO_FOCUS);
-                       mainCmp.setLayout(new FillLayout());
-
-                       // Add listener to update user list when shown
-                       final IWizardContainer container = this.getContainer();
-                       if (container instanceof IPageChangeProvider) {
-                               ((IPageChangeProvider) container).addPageChangedListener(this);
-                       }
-
-                       userTableCmp = new UsersTable(mainCmp, SWT.NO_FOCUS, session);
+                       Composite pageCmp = new Composite(parent, SWT.NO_FOCUS);
+                       pageCmp.setLayout(EclipseUiUtils.noSpaceGridLayout());
+
+                       List<ColumnDefinition> columnDefs = new ArrayList<ColumnDefinition>();
+                       columnDefs.add(new ColumnDefinition(new CommonNameLP(),
+                                       "Common Name", 150));
+                       columnDefs.add(new ColumnDefinition(new MailLP(), "E-mail", 150));
+                       columnDefs.add(new ColumnDefinition(new DomainNameLP(), "Domain",
+                                       200));
+                       // Only show technical DN to admin
+                       if (UserAdminUtils.isUserInRole(AuthConstants.ROLE_ADMIN))
+                               columnDefs.add(new ColumnDefinition(new UserNameLP(),
+                                               "Distinguished Name", 300));
+                       userTableCmp = new ChosenUsersTableViewer(pageCmp, SWT.MULTI
+                                       | SWT.H_SCROLL | SWT.V_SCROLL);
+                       userTableCmp.setLayoutData(EclipseUiUtils.fillAll());
+                       userTableCmp.setColumnDefinitions(columnDefs);
                        userTableCmp.populate(false, false);
-                       setControl(mainCmp);
+                       userTableCmp.refresh();
+                       setControl(pageCmp);
+                       // Add listener to update message when shown
+                       final IWizardContainer wContainer = this.getContainer();
+                       if (wContainer instanceof IPageChangeProvider) {
+                               ((IPageChangeProvider) wContainer).addPageChangedListener(this);
+                       }
                }
 
                @Override
@@ -575,30 +556,23 @@ public class UserBatchUpdateWizard extends Wizard {
                                userTableCmp.getTableViewer().setInput(values);
                                String msg = "Following batch action: ["
                                                + chooseCommandPage.getCommandLbl()
-                                               + "] will be perfomed on the users listed below.\n"
-                                               + "Are you sure you want to proceed?";
-                               ((WizardPage) event.getSelectedPage()).setMessage(msg);
+                                               + "] will be perfomed on the users listed below.\n";
+                               // + "Are you sure you want to proceed?";
+                               setMessage(msg);
                        }
                }
 
-               // private class MyUserTableCmp extends UserTableComposite {
-               // public MyUserTableCmp(Composite parent, int style, Session session) {
-               // super(parent, style, session);
-               // }
-               //
-               // @Override
-               // protected void refreshFilteredList() {
-               // @SuppressWarnings({ "unchecked", "rawtypes" })
-               //
-               // setFilteredList(values);
-               // }
-               //
-               // @Override
-               // public void setVisible(boolean visible) {
-               // super.setVisible(visible);
-               // if (visible)
-               // refreshFilteredList();
-               // }
-               // }
+               private class ChosenUsersTableViewer extends LdifUsersTable {
+                       private static final long serialVersionUID = 7814764735794270541L;
+
+                       public ChosenUsersTableViewer(Composite parent, int style) {
+                               super(parent, style);
+                       }
+
+                       @Override
+                       protected List<User> listFilteredElements(String filter) {
+                               return userListPage.getSelectedUsers();
+                       }
+               }
        }
 }
\ No newline at end of file