]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/editors/UserEditor.java
Plug password management
[lgpl/argeo-commons.git] / org.argeo.security.ui.admin / src / org / argeo / security / ui / admin / editors / UserEditor.java
index 761f48b80f0d4292f3858f85fe1cffaad6245090..2f7aa41c7c2672a3562bb909c746eded2507ebbb 100644 (file)
@@ -18,9 +18,11 @@ package org.argeo.security.ui.admin.editors;
 import java.util.ArrayList;
 import java.util.List;
 
+import javax.transaction.UserTransaction;
+
 import org.argeo.ArgeoException;
-import org.argeo.security.ui.admin.SecurityAdminImages;
 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.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.ui.IEditorInput;
@@ -41,6 +43,7 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
 
        /* DEPENDENCY INJECTION */
        private UserAdmin userAdmin;
+       private UserTransaction userTransaction;
 
        // Context
        private User user;
@@ -53,20 +56,28 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
                user = (User) userAdmin.getRole(username);
 
                String commonName = getProperty(KEY_CN);
-               // this.setPartProperty("name", commonName != null ? commonName
-               // : "username");
 
-               // if (user.getType() == Role.GROUP) {
-               // this.setPartProperty("icon", "icons/users.gif");
-               // firePartPropertyChanged("icon", "icons/user.gif", "icons/users.gif");
-               // }
                setPartName(commonName != null ? commonName : "username");
-               setTitleImage(user.getType() == Role.GROUP ? SecurityAdminImages.ICON_GROUP
-                               : SecurityAdminImages.ICON_USER);
+
+               // TODO: following has been disabled because it causes NPE after a
+               // login/logout on RAP
+               // Image titleIcon = user.getType() == Role.GROUP ?
+               // SecurityAdminImages.ICON_GROUP
+               // : SecurityAdminImages.ICON_USER;
+               // setTitleImage(titleIcon);
        }
 
-       protected List<User> getFlatGroups() {
-               Authorization currAuth = userAdmin.getAuthorization(user);
+       /**
+        * returns the list of all authorisation for the given user or of the
+        * current displayed user if parameter is null
+        */
+       protected List<User> getFlatGroups(User aUser) {
+               Authorization currAuth;
+               if (aUser == null)
+                       currAuth = userAdmin.getAuthorization(this.user);
+               else
+                       currAuth = userAdmin.getAuthorization(aUser);
+
                String[] roles = currAuth.getRoles();
 
                List<User> groups = new ArrayList<User>();
@@ -106,7 +117,14 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
                        return "";
        }
 
-       /** The property is directly updated!!! */
+       protected void beginTransactionIfNeeded() {
+               UiAdminUtils.beginTransactionIfNeeded(userTransaction);
+       }
+
+       /**
+        * Updates the property in the working copy. The transaction must be
+        * explicitly committed to persist the update.
+        */
        @SuppressWarnings("unchecked")
        protected void setProperty(String key, String value) {
                user.getProperties().put(key, value);
@@ -114,8 +132,15 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
 
        @Override
        public void doSave(IProgressMonitor monitor) {
+               UiAdminUtils.beginTransactionIfNeeded(userTransaction);
                commitPages(true);
                firePropertyChange(PROP_DIRTY);
+               // FIXME transaction should be managed at a higher level
+               // try {
+               // userTransaction.commit();
+               // } catch (Exception e) {
+               // throw new ArgeoException("Could not save user editor", e);
+               // }
        }
 
        @Override
@@ -140,4 +165,9 @@ public class UserEditor extends FormEditor implements UserAdminConstants {
        public void setUserAdmin(UserAdmin userAdmin) {
                this.userAdmin = userAdmin;
        }
+
+       public void setUserTransaction(UserTransaction userTransaction) {
+               this.userTransaction = userTransaction;
+       }
+
 }
\ No newline at end of file