Split security UI to security admin ui
authorMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Mar 2011 12:34:22 +0000 (12:34 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Thu, 17 Mar 2011 12:34:22 +0000 (12:34 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@4310 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

52 files changed:
security/plugins/org.argeo.security.ui.admin/META-INF/spring/commands.xml
security/plugins/org.argeo.security.ui.admin/META-INF/spring/editors.xml
security/plugins/org.argeo.security.ui.admin/META-INF/spring/views.xml
security/plugins/org.argeo.security.ui.admin/icons/add.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/password.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/refresh.png [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/remove.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/role.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/save.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/save_security.png [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/save_security_disabled.png [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/security.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/user.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/icons/users.gif [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/plugin.xml
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPerspective.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPlugin.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/AddRole.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/OpenArgeoUserEditor.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/RefreshUsersList.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/SaveArgeoUser.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditor.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditorInput.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/DefaultUserMainPage.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/RolesView.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/UsersView.java [new file with mode: 0644]
security/plugins/org.argeo.security.ui/META-INF/spring/commands.xml
security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml [deleted file]
security/plugins/org.argeo.security.ui/META-INF/spring/views.xml [deleted file]
security/plugins/org.argeo.security.ui/icons/add.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/password.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/refresh.png [deleted file]
security/plugins/org.argeo.security.ui/icons/remove.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/role.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/save.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/save_security.png [deleted file]
security/plugins/org.argeo.security.ui/icons/save_security_disabled.png [deleted file]
security/plugins/org.argeo.security.ui/icons/security.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/user.gif [deleted file]
security/plugins/org.argeo.security.ui/icons/users.gif [deleted file]
security/plugins/org.argeo.security.ui/plugin.xml
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java [deleted file]
security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java [deleted file]

index f2009b9cca9d9bbad6bcbd3c78019075a8c1441f..cc36ad9fbae4f300c1f4261fe2a23f4b06c7f5d1 100644 (file)
@@ -4,18 +4,14 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-       <bean id="openArgeoUserEditor" class="org.argeo.security.ui.commands.OpenArgeoUserEditor"
+       <bean id="openArgeoUserEditor" class="org.argeo.security.ui.admin.commands.OpenArgeoUserEditor"
                scope="prototype" />
-       <bean id="newArgeoUserEditor" class="org.argeo.security.ui.commands.OpenArgeoUserEditor"
+       <bean id="newArgeoUserEditor" class="org.argeo.security.ui.admin.commands.OpenArgeoUserEditor"
                scope="prototype" />
-       <bean id="addRole" class="org.argeo.security.ui.commands.AddRole"
+       <bean id="addRole" class="org.argeo.security.ui.admin.commands.AddRole"
                scope="prototype">
                <property name="securityService" ref="securityService" />
        </bean>
-       <bean id="openChangePasswordDialog" class="org.argeo.security.ui.commands.OpenChangePasswordDialog"
-               scope="prototype">
-               <property name="securityService" ref="securityService" />
-       </bean>
-       <bean id="refreshUsersList" class="org.argeo.security.ui.commands.RefreshUsersList"
+       <bean id="refreshUsersList" class="org.argeo.security.ui.admin.commands.RefreshUsersList"
                scope="prototype" />
 </beans>
index bd01515132f2490f7833e23e4ec11daf3cd4bb48..8ff9cec583def5557e6b60793d8adca58fd689da 100644 (file)
@@ -5,7 +5,7 @@
         http://www.springframework.org/schema/beans/spring-beans.xsd">
 
        <!-- Editors -->
-       <bean id="adminArgeoUserEditor" class="org.argeo.security.ui.editors.ArgeoUserEditor"
+       <bean id="adminArgeoUserEditor" class="org.argeo.security.ui.admin.editors.ArgeoUserEditor"
                scope="prototype">
                <property name="securityService" ref="securityService" />
        </bean>
index cdc214f9a033ac12111c65975fc34d63ff9b37f1..a94e3da3056eae5d0f43dc132314636976eefdd3 100644 (file)
@@ -4,11 +4,11 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-       <bean id="adminUsersView" class="org.argeo.security.ui.views.UsersView"
+       <bean id="adminUsersView" class="org.argeo.security.ui.admin.views.UsersView"
                scope="prototype">
                <property name="securityService" ref="securityService" />
        </bean>
-       <bean id="adminRolesView" class="org.argeo.security.ui.views.RolesView"
+       <bean id="adminRolesView" class="org.argeo.security.ui.admin.views.RolesView"
                scope="prototype">
                <property name="securityService" ref="securityService" />
        </bean>
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/add.gif b/security/plugins/org.argeo.security.ui.admin/icons/add.gif
new file mode 100644 (file)
index 0000000..252d7eb
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/add.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/password.gif b/security/plugins/org.argeo.security.ui.admin/icons/password.gif
new file mode 100644 (file)
index 0000000..a6b251f
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/password.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/refresh.png b/security/plugins/org.argeo.security.ui.admin/icons/refresh.png
new file mode 100644 (file)
index 0000000..a3884fb
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/refresh.png differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/remove.gif b/security/plugins/org.argeo.security.ui.admin/icons/remove.gif
new file mode 100644 (file)
index 0000000..0ae6dec
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/remove.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/role.gif b/security/plugins/org.argeo.security.ui.admin/icons/role.gif
new file mode 100644 (file)
index 0000000..274a850
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/role.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/save.gif b/security/plugins/org.argeo.security.ui.admin/icons/save.gif
new file mode 100644 (file)
index 0000000..654ad7b
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/save.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/save_security.png b/security/plugins/org.argeo.security.ui.admin/icons/save_security.png
new file mode 100644 (file)
index 0000000..ca41dc9
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/save_security.png differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/save_security_disabled.png b/security/plugins/org.argeo.security.ui.admin/icons/save_security_disabled.png
new file mode 100644 (file)
index 0000000..fb7d08d
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/save_security_disabled.png differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/security.gif b/security/plugins/org.argeo.security.ui.admin/icons/security.gif
new file mode 100644 (file)
index 0000000..57fb95e
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/security.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/user.gif b/security/plugins/org.argeo.security.ui.admin/icons/user.gif
new file mode 100644 (file)
index 0000000..90a0014
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/user.gif differ
diff --git a/security/plugins/org.argeo.security.ui.admin/icons/users.gif b/security/plugins/org.argeo.security.ui.admin/icons/users.gif
new file mode 100644 (file)
index 0000000..2de7edd
Binary files /dev/null and b/security/plugins/org.argeo.security.ui.admin/icons/users.gif differ
index 0a78645affcec7938c6e5f00687d763f475550c3..74fe49297904313199b3f53e8aae2259a0ce602a 100644 (file)
@@ -4,9 +4,9 @@
    <extension
          point="org.eclipse.ui.perspectives">
       <perspective
-            class="org.argeo.security.ui.SecurityPerspective"
+            class="org.argeo.security.ui.admin.SecurityPerspective"
             icon="icons/security.gif"
-            id="org.argeo.security.ui.adminSecurityPerspective"
+            id="org.argeo.security.ui.admin.adminSecurityPerspective"
             name="Security">
       </perspective>
    </extension>
       <view
             class="org.argeo.eclipse.spring.SpringExtensionFactory"
             icon="icons/users.gif"
-            id="org.argeo.security.ui.adminUsersView"
+            id="org.argeo.security.ui.admin.adminUsersView"
             name="Users"
             restorable="false">
       </view>
       <view
             class="org.argeo.eclipse.spring.SpringExtensionFactory"
             icon="icons/role.gif"
-            id="org.argeo.security.ui.adminRolesView"
+            id="org.argeo.security.ui.admin.adminRolesView"
             name="Roles"
             restorable="false">
       </view>
    </extension>
-   
-   <!-- Security -->
-   <extension
-         id="defaultLoginDialog"
-         name="Default Login Dialog"
-         point="org.eclipse.equinox.security.callbackHandler">
-      <callbackHandler
-            class="org.argeo.security.ui.dialogs.DefaultLoginDialog">
-      </callbackHandler>
-   </extension>
-   <extension
-         point="org.eclipse.equinox.security.callbackHandlerMapping">
-      <callbackHandlerMapping
-            callbackHandlerId="org.argeo.security.ui.defaultLoginDialog"
-            configName="SPRING">
-      </callbackHandlerMapping>
-   </extension>
-   <extension
-         point="org.eclipse.equinox.security.callbackHandlerMapping">
-         <callbackHandlerMapping
-            callbackHandlerId="org.argeo.security.ui.defaultLoginDialog"
-            configName="UNIX">
-      </callbackHandlerMapping>
-   </extension>
-   <extension
-         point="org.eclipse.equinox.security.callbackHandlerMapping">
-      <callbackHandlerMapping
-            callbackHandlerId="org.argeo.security.ui.defaultLoginDialog"
-            configName="SPRING_SECURITY_CONTEXT">
-      </callbackHandlerMapping>
-   </extension>
    <extension
            point="org.eclipse.ui.editors">
                <editor
                  class="org.argeo.eclipse.spring.SpringExtensionFactory"
-              id="org.argeo.security.ui.adminArgeoUserEditor"
+              id="org.argeo.security.ui.admin.adminArgeoUserEditor"
               name="User"
               icon="icons/user.gif"
               default="false">
          point="org.eclipse.ui.commands">
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.openArgeoUserEditor"
+            id="org.argeo.security.ui.admin.openArgeoUserEditor"
             name="OpenArgeoUserEditor">
                        <commandParameter
-                       id="org.argeo.security.ui.username"
+                       id="org.argeo.security.ui.admin.username"
                        name="Username">
                        </commandParameter>
       </command>
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.newArgeoUserEditor"
+            id="org.argeo.security.ui.admin.newArgeoUserEditor"
             name="OpenArgeoUserEditor">
       </command>
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.addRole"
+            id="org.argeo.security.ui.admin.addRole"
             name="AddRole">
       </command>
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.openChangePasswordDialog"
-            name="OpenChangePasswordDialog">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.refreshUsersList"
+            id="org.argeo.security.ui.admin.refreshUsersList"
             name="refreshUsersList">
       </command>
     </extension>
      <extension
          point="org.eclipse.ui.menus">
        <menuContribution
-            locationURI="toolbar:org.argeo.security.ui.rolesView">
+            locationURI="toolbar:org.argeo.security.ui.admin.rolesView">
             <command
-                  commandId="org.argeo.security.ui.addRole"
+                  commandId="org.argeo.security.ui.admin.addRole"
                   icon="icons/add.gif"
                   label="Add Role"
                   tooltip="Add new role">
             </command>
         </menuContribution>
        <menuContribution
-            locationURI="toolbar:org.argeo.security.ui.usersView">
+            locationURI="toolbar:org.argeo.security.ui.admin.usersView">
             <command
-                  commandId="org.argeo.security.ui.newArgeoUserEditor"
+                  commandId="org.argeo.security.ui.admin.newArgeoUserEditor"
                   icon="icons/add.gif"
                   label="Add User"
                   tooltip="Add new user">
             </command>
             <command
-                  commandId="org.argeo.security.ui.refreshUsersList"
+                  commandId="org.argeo.security.ui.admin.refreshUsersList"
                   icon="icons/refresh.png"
                   label="Refresh"
                   tooltip="Refresh user list">
             </command>
         </menuContribution>
-        <menuContribution
-                locationURI="menu:file?after=additions">
-                <command
-                      commandId="org.argeo.security.ui.openChangePasswordDialog"
-                      icon="icons/password.gif"
-                      label="Change password"
-                      style="push"
-                      tooltip="Change password">
-                </command>
-          </menuContribution>
   </extension>
-     <extension
-           id="product"
-           point="org.eclipse.core.runtime.products">
-        <product
-              application="org.argeo.security.ui.application.secureUi"
-              name="Agfa Sebi">
-           <property
-                 name="appName"
-                 value="Agfa Sebi">
-           </property>
-        </product>
-     </extension>
-     <extension
-           point="org.eclipse.ui.services">
-        <sourceProvider
-              provider="org.argeo.security.ui.RolesSourceProvider">
-           <variable
-                 name="org.argeo.security.ui.rolesVariable"
-                 priorityLevel="workbench">
-           </variable>
-        </sourceProvider>
-     </extension>
-     <extension
+  <extension
            point="org.eclipse.ui.activities">
         <activity
               description="Only for admins"
-              id="org.argeo.security.ui.adminActivity"
+              id="org.argeo.security.ui.admin.adminActivity"
               name="Admin">
                  <enabledWhen>
                    <with variable="roles">
                  </enabledWhen>
         </activity>
         <activityPatternBinding
-              activityId="org.argeo.security.ui.adminActivity"
+              activityId="org.argeo.security.ui.admin.adminActivity"
               isEqualityPattern="true"
-              pattern="org.argeo.security.ui/.*admin.*">
+              pattern="org.argeo.security.ui.admin/.*">
         </activityPatternBinding>
      </extension>
  </plugin>
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPerspective.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPerspective.java
new file mode 100644 (file)
index 0000000..49f537c
--- /dev/null
@@ -0,0 +1,19 @@
+package org.argeo.security.ui.admin;
+
+import org.eclipse.ui.IFolderLayout;
+import org.eclipse.ui.IPageLayout;
+import org.eclipse.ui.IPerspectiveFactory;
+
+public class SecurityAdminPerspective implements IPerspectiveFactory {
+       public void createInitialLayout(IPageLayout layout) {
+               String editorArea = layout.getEditorArea();
+               layout.setEditorAreaVisible(true);
+               layout.setFixed(false);
+
+               IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT,
+                               0.4f, editorArea);
+               left.addView("org.argeo.security.ui.admin.adminUsersView");
+               left.addView("org.argeo.security.ui.admin.adminRolesView");
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPlugin.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/SecurityAdminPlugin.java
new file mode 100644 (file)
index 0000000..cc5d429
--- /dev/null
@@ -0,0 +1,58 @@
+package org.argeo.security.ui.admin;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+public class SecurityAdminPlugin extends AbstractUIPlugin {
+
+       // The plug-in ID
+       public static final String PLUGIN_ID = "org.argeo.security.ui.admin"; //$NON-NLS-1$
+
+       // The shared instance
+       private static SecurityAdminPlugin plugin;
+
+       /**
+        * The constructor
+        */
+       public SecurityAdminPlugin() {
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext
+        * )
+        */
+       public void start(BundleContext context) throws Exception {
+               super.start(context);
+               plugin = this;
+       }
+
+       /*
+        * (non-Javadoc)
+        * 
+        * @see
+        * org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext
+        * )
+        */
+       public void stop(BundleContext context) throws Exception {
+               plugin = null;
+               super.stop(context);
+       }
+
+       /**
+        * Returns the shared instance
+        * 
+        * @return the shared instance
+        */
+       public static SecurityAdminPlugin getDefault() {
+               return plugin;
+       }
+
+       public static ImageDescriptor getImageDescriptor(String path) {
+               return imageDescriptorFromPlugin(PLUGIN_ID, path);
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/AddRole.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/AddRole.java
new file mode 100644 (file)
index 0000000..e8825bc
--- /dev/null
@@ -0,0 +1,40 @@
+package org.argeo.security.ui.admin.commands;
+
+import org.argeo.ArgeoException;
+import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.ui.admin.views.RolesView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Add a new role. */
+public class AddRole extends AbstractHandler {
+       public final static String COMMAND_ID = "org.argeo.security.ui.addRole";
+       private ArgeoSecurityService securityService;
+       private String rolePrefix = "ROLE_";
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               RolesView rolesView = (RolesView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(RolesView.ID);
+               String role = rolesView.getNewRole();
+               if (role.trim().equals(""))
+                       return null;
+               if (role.equals(rolesView.getAddNewRoleText()))
+                       return null;
+               role = role.trim().toUpperCase();
+               if (!role.startsWith(rolePrefix))
+                       role = rolePrefix + role;
+               if (securityService.listEditableRoles().contains(role))
+                       throw new ArgeoException("Role " + role + " already exists");
+               securityService.newRole(role);
+               rolesView.refresh();
+               return null;
+       }
+
+       public void setSecurityService(ArgeoSecurityService securityService) {
+               this.securityService = securityService;
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/OpenArgeoUserEditor.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/OpenArgeoUserEditor.java
new file mode 100644 (file)
index 0000000..7cac7f4
--- /dev/null
@@ -0,0 +1,28 @@
+package org.argeo.security.ui.admin.commands;
+
+import org.argeo.security.ui.admin.editors.ArgeoUserEditor;
+import org.argeo.security.ui.admin.editors.ArgeoUserEditorInput;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Command handler to set visible or open a Argeo user. */
+public class OpenArgeoUserEditor extends AbstractHandler {
+       public final static String COMMAND_ID = "org.argeo.security.ui.openArgeoUserEditor";
+       public final static String PARAM_USERNAME = "org.argeo.security.ui.username";
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               try {
+                       ArgeoUserEditorInput editorInput = new ArgeoUserEditorInput(
+                                       event.getParameter(PARAM_USERNAME));
+                       IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(
+                                       event).getActivePage();
+                       activePage.openEditor(editorInput, ArgeoUserEditor.ID);
+               } catch (Exception e) {
+                       throw new ExecutionException("Cannot open editor", e);
+               }
+               return null;
+       }
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/RefreshUsersList.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/RefreshUsersList.java
new file mode 100644 (file)
index 0000000..10e413a
--- /dev/null
@@ -0,0 +1,20 @@
+package org.argeo.security.ui.admin.commands;
+
+import org.argeo.security.ui.admin.views.UsersView;
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Refresh the main EBI list. */
+public class RefreshUsersList extends AbstractHandler {
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               UsersView view = (UsersView) HandlerUtil
+                               .getActiveWorkbenchWindow(event).getActivePage()
+                               .findView(UsersView.ID);
+               view.refresh();
+               return null;
+       }
+
+}
\ No newline at end of file
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/SaveArgeoUser.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/commands/SaveArgeoUser.java
new file mode 100644 (file)
index 0000000..1624514
--- /dev/null
@@ -0,0 +1,32 @@
+package org.argeo.security.ui.admin.commands;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/** Save the currently edited Argeo user. */
+public class SaveArgeoUser extends AbstractHandler {
+       public final static String COMMAND_ID = "org.argeo.security.ui.saveArgeoUser";
+
+       public Object execute(ExecutionEvent event) throws ExecutionException {
+               try {
+                       IWorkbenchPart iwp = HandlerUtil.getActiveWorkbenchWindow(event)
+                                       .getActivePage().getActivePart();
+
+                       if (!(iwp instanceof IEditorPart))
+                               return null;
+                       IEditorPart editor = (IEditorPart) iwp;
+                       editor.doSave(null);
+               } catch (Exception e) {
+                       MessageDialog.openError(Display.getDefault().getActiveShell(),
+                                       "Error", "Cannot save user: " + e.getMessage());
+               }
+               return null;
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditor.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditor.java
new file mode 100644 (file)
index 0000000..41e6d4f
--- /dev/null
@@ -0,0 +1,72 @@
+package org.argeo.security.ui.admin.editors;
+
+import org.argeo.ArgeoException;
+import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.SimpleArgeoUser;
+import org.argeo.security.nature.SimpleUserNature;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+/** Editor for an Argeo user. */
+public class ArgeoUserEditor extends FormEditor {
+       public final static String ID = "org.argeo.security.ui.adminArgeoUserEditor";
+
+       private ArgeoUser user;
+       private ArgeoSecurityService securityService;
+
+       public void init(IEditorSite site, IEditorInput input)
+                       throws PartInitException {
+               super.init(site, input);
+               String username = ((ArgeoUserEditorInput) getEditorInput())
+                               .getUsername();
+               if (username == null) {// new
+                       user = new SimpleArgeoUser();
+                       user.getUserNatures().put(SimpleUserNature.TYPE,
+                                       new SimpleUserNature());
+               } else
+                       user = securityService.getUser(username);
+               this.setPartProperty("name", username != null ? username : "<new user>");
+               setPartName(username != null ? username : "<new user>");
+       }
+
+       protected void addPages() {
+               try {
+                       addPage(new DefaultUserMainPage(this, securityService, user));
+
+               } catch (PartInitException e) {
+                       throw new ArgeoException("Not able to add page ", e);
+               }
+       }
+
+       @Override
+       public void doSave(IProgressMonitor monitor) {
+               // list pages
+               // TODO: make it more generic
+               findPage(DefaultUserMainPage.ID).doSave(monitor);
+
+               if (securityService.userExists(user.getUsername()))
+                       securityService.updateUser(user);
+               else {
+                       securityService.newUser(user);
+                       setPartName(user.getUsername());
+               }
+               firePropertyChange(PROP_DIRTY);
+       }
+
+       @Override
+       public void doSaveAs() {
+       }
+
+       @Override
+       public boolean isSaveAsAllowed() {
+               return false;
+       }
+
+       public void setSecurityService(ArgeoSecurityService securityService) {
+               this.securityService = securityService;
+       }
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditorInput.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/ArgeoUserEditorInput.java
new file mode 100644 (file)
index 0000000..8812ee3
--- /dev/null
@@ -0,0 +1,51 @@
+package org.argeo.security.ui.admin.editors;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/** Editor input for an Argeo user. */
+public class ArgeoUserEditorInput implements IEditorInput {
+       private final String username;
+
+       public ArgeoUserEditorInput(String username) {
+               this.username = username;
+       }
+
+       public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+               return null;
+       }
+
+       public boolean exists() {
+               return username != null;
+       }
+
+       public ImageDescriptor getImageDescriptor() {
+               return null;
+       }
+
+       public String getName() {
+               return username != null ? username : "<new user>";
+       }
+
+       public IPersistableElement getPersistable() {
+               return null;
+       }
+
+       public String getToolTipText() {
+               return username != null ? username : "<new user>";
+       }
+
+       public boolean equals(Object obj) {
+               if (!(obj instanceof ArgeoUserEditorInput))
+                       return false;
+               if (((ArgeoUserEditorInput) obj).getUsername() == null)
+                       return false;
+               return ((ArgeoUserEditorInput) obj).getUsername().equals(username);
+       }
+
+       public String getUsername() {
+               return username;
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/DefaultUserMainPage.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/editors/DefaultUserMainPage.java
new file mode 100644 (file)
index 0000000..e476123
--- /dev/null
@@ -0,0 +1,337 @@
+package org.argeo.security.ui.admin.editors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.SimpleArgeoUser;
+import org.argeo.security.nature.SimpleUserNature;
+import org.argeo.security.ui.admin.SecurityAdminPlugin;
+import org.eclipse.jface.viewers.CellEditor;
+import org.eclipse.jface.viewers.CheckboxCellEditor;
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.EditingSupport;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.TableViewerColumn;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.AbstractFormPart;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.SectionPart;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * Display/edit the properties common to all {@link ArgeoUser} (username and
+ * roles) as well as the properties of the {@link SimpleUserNature}.
+ */
+public class DefaultUserMainPage extends FormPage {
+       final static String ID = "argeoUserEditor.mainPage";
+
+       private final static Log log = LogFactory.getLog(DefaultUserMainPage.class);
+       private final static Image ROLE_CHECKED = SecurityAdminPlugin
+                       .getImageDescriptor("icons/security.gif").createImage();
+
+       private ArgeoUser user;
+       private SimpleUserNature simpleNature;
+       private String simpleNatureType;
+       private ArgeoSecurityService securityService;
+
+       public DefaultUserMainPage(FormEditor editor,
+                       ArgeoSecurityService securityService, ArgeoUser user) {
+               super(editor, ID, "Main");
+               this.securityService = securityService;
+               this.user = user;
+               this.simpleNature = SimpleUserNature.findSimpleUserNature(user,
+                               simpleNatureType);
+       }
+
+       protected void createFormContent(final IManagedForm mf) {
+               ScrolledForm form = mf.getForm();
+               form.setText(simpleNature.getFirstName() + " "
+                               + simpleNature.getLastName());
+               ColumnLayout mainLayout = new ColumnLayout();
+               mainLayout.minNumColumns = 1;
+               mainLayout.maxNumColumns = 4;
+               mainLayout.topMargin = 0;
+               mainLayout.bottomMargin = 5;
+               mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10;
+               form.getBody().setLayout(mainLayout);
+
+               createGeneralPart(form.getBody());
+               createRolesPart(form.getBody());
+               createPassworPart(form.getBody());
+       }
+
+       /** Creates the general section */
+       protected void createGeneralPart(Composite parent) {
+               FormToolkit tk = getManagedForm().getToolkit();
+               Section section = tk.createSection(parent, Section.TITLE_BAR);
+               section.setText("General");
+
+               Composite body = tk.createComposite(section, SWT.WRAP);
+               section.setClient(body);
+               GridLayout layout = new GridLayout();
+               layout.marginWidth = layout.marginHeight = 0;
+               layout.numColumns = 2;
+               body.setLayout(layout);
+
+               // add widgets (view)
+               final Text username;
+               if (user.getUsername() != null) {
+                       tk.createLabel(body, "Username");
+                       tk.createLabel(body, user.getUsername());
+                       username = null;
+               } else {
+                       username = createLT(body, "Username", "");
+               }
+               final Text firstName = createLT(body, "First name",
+                               simpleNature.getFirstName());
+               final Text lastName = createLT(body, "Last name",
+                               simpleNature.getLastName());
+               final Text email = createLT(body, "Email", simpleNature.getEmail());
+               final Text description = createLT(body, "Description",
+                               simpleNature.getDescription());
+
+               // create form part (controller)
+               AbstractFormPart part = new SectionPart(section) {
+                       public void commit(boolean onSave) {
+                               if (username != null) {
+                                       ((SimpleArgeoUser) user).setUsername(username.getText());
+                                       username.setEditable(false);
+                                       username.setEnabled(false);
+                               }
+                               simpleNature.setFirstName(firstName.getText());
+                               simpleNature.setLastName(lastName.getText());
+                               simpleNature.setEmail(email.getText());
+                               simpleNature.setDescription(description.getText());
+                               super.commit(onSave);
+                               if (log.isTraceEnabled())
+                                       log.trace("General part committed");
+                       }
+               };
+               if (username != null)
+                       username.addModifyListener(new FormPartML(part));
+               firstName.addModifyListener(new FormPartML(part));
+               lastName.addModifyListener(new FormPartML(part));
+               email.addModifyListener(new FormPartML(part));
+               description.addModifyListener(new FormPartML(part));
+               getManagedForm().addPart(part);
+       }
+
+       /** Creates the password section */
+       protected void createPassworPart(Composite parent) {
+               FormToolkit tk = getManagedForm().getToolkit();
+               Section section = tk.createSection(parent, Section.TITLE_BAR);
+               section.setText("Password");
+
+               Composite body = tk.createComposite(section, SWT.WRAP);
+               section.setClient(body);
+               GridLayout layout = new GridLayout();
+               layout.marginWidth = layout.marginHeight = 0;
+               layout.numColumns = 2;
+               body.setLayout(layout);
+
+               // add widgets (view)
+               final Text password1 = createLP(body, "New password", "");
+               final Text password2 = createLP(body, "Repeat password", "");
+               // create form part (controller)
+               AbstractFormPart part = new SectionPart(section) {
+                       public void commit(boolean onSave) {
+                               if (!password1.getText().equals("")
+                                               && password1.getText().equals(password2.getText())) {
+                                       ((SimpleArgeoUser) user).setPassword(password1.getText());
+                               }
+                               super.commit(onSave);
+                               if (log.isTraceEnabled())
+                                       log.trace("Password part committed");
+                       }
+               };
+               password1.addModifyListener(new FormPartML(part));
+               password2.addModifyListener(new FormPartML(part));
+               getManagedForm().addPart(part);
+       }
+
+       /** Creates the role section */
+       protected void createRolesPart(Composite parent) {
+               FormToolkit tk = getManagedForm().getToolkit();
+               Section section = tk.createSection(parent, Section.DESCRIPTION
+                               | Section.TITLE_BAR);
+               section.setText("Roles");
+               section.setDescription("Roles define "
+                               + "the authorizations for this user.");
+               Table table = new Table(section, SWT.MULTI | SWT.H_SCROLL
+                               | SWT.V_SCROLL);
+               section.setClient(table);
+
+               AbstractFormPart part = new SectionPart(section) {
+                       public void commit(boolean onSave) {
+                               // roles have already been modified in editing
+                               super.commit(onSave);
+                               if (log.isTraceEnabled())
+                                       log.trace("Role part committed");
+                       }
+               };
+               getManagedForm().addPart(part);
+
+               GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
+               gridData.verticalSpan = 20;
+               table.setLayoutData(gridData);
+               table.setLinesVisible(true);
+               table.setHeaderVisible(false);
+               TableViewer viewer = new TableViewer(table);
+
+               // check column
+               TableViewerColumn column = createTableViewerColumn(viewer, "checked",
+                               20);
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       public String getText(Object element) {
+                               return null;
+                       }
+
+                       public Image getImage(Object element) {
+                               String role = element.toString();
+                               if (user.getRoles().contains(role)) {
+                                       return ROLE_CHECKED;
+                               } else {
+                                       return null;
+                               }
+                       }
+               });
+               column.setEditingSupport(new RoleEditingSupport(viewer, part));
+
+               // role column
+               column = createTableViewerColumn(viewer, "Role", 200);
+               column.setLabelProvider(new ColumnLabelProvider() {
+                       public String getText(Object element) {
+                               return element.toString();
+                       }
+
+                       public Image getImage(Object element) {
+                               return null;
+                       }
+               });
+               viewer.setContentProvider(new RolesContentProvider());
+               viewer.setInput(getEditorSite());
+       }
+
+       protected TableViewerColumn createTableViewerColumn(TableViewer viewer,
+                       String title, int bound) {
+               final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
+                               SWT.NONE);
+               final TableColumn column = viewerColumn.getColumn();
+               column.setText(title);
+               column.setWidth(bound);
+               column.setResizable(true);
+               column.setMoveable(true);
+               return viewerColumn;
+
+       }
+
+       /** Creates label and text. */
+       protected Text createLT(Composite body, String label, String value) {
+               FormToolkit toolkit = getManagedForm().getToolkit();
+               toolkit.createLabel(body, label);
+               Text text = toolkit.createText(body, value, SWT.BORDER);
+               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               return text;
+       }
+
+       /** Creates label and password. */
+       protected Text createLP(Composite body, String label, String value) {
+               FormToolkit toolkit = getManagedForm().getToolkit();
+               toolkit.createLabel(body, label);
+               Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD);
+               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               return text;
+       }
+
+       public void setSimpleNatureType(String simpleNatureType) {
+               this.simpleNatureType = simpleNatureType;
+       }
+
+       private class FormPartML implements ModifyListener {
+               private AbstractFormPart formPart;
+
+               public FormPartML(AbstractFormPart generalPart) {
+                       this.formPart = generalPart;
+               }
+
+               public void modifyText(ModifyEvent e) {
+                       formPart.markDirty();
+               }
+
+       }
+
+       private class RolesContentProvider implements IStructuredContentProvider {
+               public Object[] getElements(Object inputElement) {
+                       return securityService.listEditableRoles().toArray();
+               }
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+       }
+
+       /** Select the columns by editing the checkbox in the first column */
+       class RoleEditingSupport extends EditingSupport {
+
+               private final TableViewer viewer;
+               private final AbstractFormPart formPart;
+
+               public RoleEditingSupport(TableViewer viewer, AbstractFormPart formPart) {
+                       super(viewer);
+                       this.viewer = viewer;
+                       this.formPart = formPart;
+               }
+
+               @Override
+               protected CellEditor getCellEditor(Object element) {
+                       return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
+
+               }
+
+               @Override
+               protected boolean canEdit(Object element) {
+                       return true;
+               }
+
+               @Override
+               protected Object getValue(Object element) {
+                       String role = element.toString();
+                       return user.getRoles().contains(role);
+
+               }
+
+               @Override
+               protected void setValue(Object element, Object value) {
+                       Boolean inRole = (Boolean) value;
+                       String role = element.toString();
+                       if (inRole && !user.getRoles().contains(role)) {
+                               user.getRoles().add(role);
+                               formPart.markDirty();
+                       } else if (!inRole && user.getRoles().contains(role)) {
+                               user.getRoles().remove(role);
+                               formPart.markDirty();
+                       }
+                       viewer.refresh();
+               }
+       }
+
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/RolesView.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/RolesView.java
new file mode 100644 (file)
index 0000000..8a7e5ec
--- /dev/null
@@ -0,0 +1,177 @@
+package org.argeo.security.ui.admin.views;
+
+import java.util.ArrayList;
+
+import org.argeo.ArgeoException;
+import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.ui.admin.SecurityAdminPlugin;
+import org.argeo.security.ui.admin.commands.AddRole;
+import org.argeo.security.ui.admin.commands.OpenArgeoUserEditor;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.part.ViewPart;
+
+/** List all roles. */
+public class RolesView extends ViewPart {
+       public final static String ID = "org.argeo.security.ui.rolesView";
+
+       private Text newRole;
+
+       private TableViewer viewer;
+       private ArgeoSecurityService securityService;
+
+       private String addNewRoleText = "<add new role here>";
+
+       @Override
+       public void createPartControl(Composite parent) {
+               parent.setLayout(new GridLayout(1, false));
+
+               // new role text field
+               newRole = new Text(parent, SWT.BORDER);
+               newRole.setText(addNewRoleText);
+               newRole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
+               // default action is add role
+               newRole.addListener(SWT.DefaultSelection, new Listener() {
+                       public void handleEvent(Event evt) {
+                               IWorkbench iw = SecurityAdminPlugin.getDefault().getWorkbench();
+                               IHandlerService handlerService = (IHandlerService) iw
+                                               .getService(IHandlerService.class);
+                               try {
+                                       handlerService.executeCommand(AddRole.COMMAND_ID, evt);
+                               } catch (Exception e) {
+                                       throw new ArgeoException("Cannot execute add role command",
+                                                       e);
+                               }
+                       }
+               });
+               // select all on focus
+               newRole.addListener(SWT.FocusIn, new Listener() {
+                       public void handleEvent(Event e) {
+                               newRole.selectAll();
+                       }
+               });
+
+               // roles table
+               Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
+               table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               table.setLinesVisible(false);
+               table.setHeaderVisible(false);
+               viewer = new TableViewer(table);
+               viewer.setContentProvider(new RolesContentProvider());
+               viewer.setLabelProvider(new UsersLabelProvider());
+               viewer.setInput(getViewSite());
+               viewer.addDoubleClickListener(new ViewDoubleClickListener());
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTable().setFocus();
+       }
+
+       public void setSecurityService(ArgeoSecurityService securityService) {
+               this.securityService = securityService;
+       }
+
+       public String getAddNewRoleText() {
+               return addNewRoleText;
+       }
+
+       private class RolesContentProvider implements IStructuredContentProvider {
+
+               public Object[] getElements(Object inputElement) {
+                       return securityService.listEditableRoles().toArray();
+               }
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+
+       }
+
+       private class UsersLabelProvider extends LabelProvider implements
+                       ITableLabelProvider {
+               public String getColumnText(Object element, int columnIndex) {
+                       return element.toString();
+               }
+
+               public Image getColumnImage(Object element, int columnIndex) {
+                       return null;
+               }
+
+       }
+
+       class ViewDoubleClickListener implements IDoubleClickListener {
+               public void doubleClick(DoubleClickEvent evt) {
+                       Object obj = ((IStructuredSelection) evt.getSelection())
+                                       .getFirstElement();
+
+                       if (obj instanceof ArgeoUser) {
+                               ArgeoUser argeoUser = (ArgeoUser) obj;
+
+                               IWorkbench iw = SecurityAdminPlugin.getDefault().getWorkbench();
+                               IHandlerService handlerService = (IHandlerService) iw
+                                               .getService(IHandlerService.class);
+                               try {
+                                       String commandId = OpenArgeoUserEditor.COMMAND_ID;
+                                       String paramName = OpenArgeoUserEditor.PARAM_USERNAME;
+
+                                       // TODO: factorize this
+                                       // execute related command
+                                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
+                                       ICommandService cmdService = (ICommandService) window
+                                                       .getService(ICommandService.class);
+                                       Command cmd = cmdService.getCommand(commandId);
+                                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+                                       IParameter iparam = cmd.getParameter(paramName);
+                                       Parameterization param = new Parameterization(iparam,
+                                                       argeoUser.getUsername());
+                                       parameters.add(param);
+                                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
+                                                       parameters.toArray(new Parameterization[parameters
+                                                                       .size()]));
+                                       handlerService = (IHandlerService) window
+                                                       .getService(IHandlerService.class);
+                                       handlerService.executeCommand(pc, null);
+                               } catch (Exception e) {
+                                       throw new ArgeoException("Cannot open editor", e);
+                               }
+
+                       }
+               }
+       }
+
+       public String getNewRole() {
+               return newRole.getText();
+       }
+
+       public void refresh() {
+               viewer.refresh();
+               newRole.setText(addNewRoleText);
+       }
+}
diff --git a/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/UsersView.java b/security/plugins/org.argeo.security.ui.admin/src/main/java/org/argeo/security/ui/admin/views/UsersView.java
new file mode 100644 (file)
index 0000000..9ef5afe
--- /dev/null
@@ -0,0 +1,174 @@
+package org.argeo.security.ui.admin.views;
+
+import java.util.ArrayList;
+
+import org.argeo.ArgeoException;
+import org.argeo.security.ArgeoSecurityService;
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.nature.SimpleUserNature;
+import org.argeo.security.ui.admin.SecurityAdminPlugin;
+import org.argeo.security.ui.admin.commands.OpenArgeoUserEditor;
+import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IParameter;
+import org.eclipse.core.commands.Parameterization;
+import org.eclipse.core.commands.ParameterizedCommand;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITableLabelProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerService;
+import org.eclipse.ui.part.ViewPart;
+
+/** List all users. */
+public class UsersView extends ViewPart {
+       public final static String ID = "org.argeo.security.ui.usersView";
+
+       private TableViewer viewer;
+       private ArgeoSecurityService securityService;
+
+       private String simpleNatureType = null;
+
+       @Override
+       public void createPartControl(Composite parent) {
+               viewer = new TableViewer(createTable(parent));
+               viewer.setContentProvider(new UsersContentProvider());
+               viewer.setLabelProvider(new UsersLabelProvider());
+               viewer.addDoubleClickListener(new ViewDoubleClickListener());
+               viewer.setInput(getViewSite());
+       }
+
+       protected Table createTable(Composite parent) {
+               Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
+               table.setLinesVisible(true);
+               table.setHeaderVisible(true);
+               TableColumn column = new TableColumn(table, SWT.LEFT, 0);
+               column.setText("User");
+               column.setWidth(50);
+               column = new TableColumn(table, SWT.LEFT, 1);
+               column.setText("First Name");
+               column.setWidth(100);
+               column = new TableColumn(table, SWT.LEFT, 2);
+               column.setText("Last Name");
+               column.setWidth(100);
+               column = new TableColumn(table, SWT.LEFT, 3);
+               column.setText("E-mail");
+               column.setWidth(100);
+               return table;
+       }
+
+       @Override
+       public void setFocus() {
+               viewer.getTable().setFocus();
+       }
+
+       public void setSecurityService(ArgeoSecurityService securityService) {
+               this.securityService = securityService;
+       }
+
+       public void setSimpleNatureType(String simpleNatureType) {
+               this.simpleNatureType = simpleNatureType;
+       }
+
+       public void refresh() {
+               viewer.refresh();
+       }
+
+       private class UsersContentProvider implements IStructuredContentProvider {
+
+               public Object[] getElements(Object inputElement) {
+                       return securityService.listUsers().toArray();
+               }
+
+               public void dispose() {
+               }
+
+               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+               }
+
+       }
+
+       private class UsersLabelProvider extends LabelProvider implements
+                       ITableLabelProvider {
+               public String getColumnText(Object element, int columnIndex) {
+                       //String currentUsername = CurrentUser.getUsername();
+                       String currentUsername = "";
+                       ArgeoUser user = (ArgeoUser) element;
+                       SimpleUserNature simpleNature = SimpleUserNature
+                                       .findSimpleUserNature(user, simpleNatureType);
+                       switch (columnIndex) {
+                       case 0:
+                               String userName = user.getUsername();
+                               if (userName.equals(currentUsername))
+                                       userName = userName + "*";
+                               return userName;
+                       case 1:
+                               return simpleNature.getFirstName();
+                       case 2:
+                               return simpleNature.getLastName();
+                       case 3:
+                               return simpleNature.getEmail();
+                       default:
+                               throw new ArgeoException("Unmanaged column " + columnIndex);
+                       }
+               }
+
+               public Image getColumnImage(Object element, int columnIndex) {
+                       // TODO Auto-generated method stub
+                       return null;
+               }
+
+       }
+
+       class ViewDoubleClickListener implements IDoubleClickListener {
+               public void doubleClick(DoubleClickEvent evt) {
+                       Object obj = ((IStructuredSelection) evt.getSelection())
+                                       .getFirstElement();
+
+                       if (obj instanceof ArgeoUser) {
+                               ArgeoUser argeoUser = (ArgeoUser) obj;
+
+                               IWorkbench iw = SecurityAdminPlugin.getDefault().getWorkbench();
+                               IHandlerService handlerService = (IHandlerService) iw
+                                               .getService(IHandlerService.class);
+                               try {
+                                       String commandId = OpenArgeoUserEditor.COMMAND_ID;
+                                       String paramName = OpenArgeoUserEditor.PARAM_USERNAME;
+
+                                       // TODO: factorize this
+                                       // execute related command
+                                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
+                                       ICommandService cmdService = (ICommandService) window
+                                                       .getService(ICommandService.class);
+                                       Command cmd = cmdService.getCommand(commandId);
+                                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
+                                       IParameter iparam = cmd.getParameter(paramName);
+                                       Parameterization param = new Parameterization(iparam,
+                                                       argeoUser.getUsername());
+                                       parameters.add(param);
+                                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
+                                                       parameters.toArray(new Parameterization[parameters
+                                                                       .size()]));
+                                       handlerService = (IHandlerService) window
+                                                       .getService(IHandlerService.class);
+                                       handlerService.executeCommand(pc, null);
+                               } catch (Exception e) {
+                                       throw new ArgeoException("Cannot open editor", e);
+                               }
+
+                       }
+               }
+       }
+
+}
index f2009b9cca9d9bbad6bcbd3c78019075a8c1441f..5d25238502522e7de01c9f0f1d2271ad94a2ba43 100644 (file)
@@ -4,18 +4,8 @@
        xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd">
 
-       <bean id="openArgeoUserEditor" class="org.argeo.security.ui.commands.OpenArgeoUserEditor"
-               scope="prototype" />
-       <bean id="newArgeoUserEditor" class="org.argeo.security.ui.commands.OpenArgeoUserEditor"
-               scope="prototype" />
-       <bean id="addRole" class="org.argeo.security.ui.commands.AddRole"
-               scope="prototype">
-               <property name="securityService" ref="securityService" />
-       </bean>
        <bean id="openChangePasswordDialog" class="org.argeo.security.ui.commands.OpenChangePasswordDialog"
                scope="prototype">
                <property name="securityService" ref="securityService" />
        </bean>
-       <bean id="refreshUsersList" class="org.argeo.security.ui.commands.RefreshUsersList"
-               scope="prototype" />
 </beans>
diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/editors.xml
deleted file mode 100644 (file)
index bd01515..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-       <!-- Editors -->
-       <bean id="adminArgeoUserEditor" class="org.argeo.security.ui.editors.ArgeoUserEditor"
-               scope="prototype">
-               <property name="securityService" ref="securityService" />
-       </bean>
-</beans>
diff --git a/security/plugins/org.argeo.security.ui/META-INF/spring/views.xml b/security/plugins/org.argeo.security.ui/META-INF/spring/views.xml
deleted file mode 100644 (file)
index cdc214f..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://www.springframework.org/schema/beans"
-       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
-       xsi:schemaLocation="http://www.springframework.org/schema/beans
-        http://www.springframework.org/schema/beans/spring-beans.xsd">
-
-       <bean id="adminUsersView" class="org.argeo.security.ui.views.UsersView"
-               scope="prototype">
-               <property name="securityService" ref="securityService" />
-       </bean>
-       <bean id="adminRolesView" class="org.argeo.security.ui.views.RolesView"
-               scope="prototype">
-               <property name="securityService" ref="securityService" />
-       </bean>
-</beans>
diff --git a/security/plugins/org.argeo.security.ui/icons/add.gif b/security/plugins/org.argeo.security.ui/icons/add.gif
deleted file mode 100644 (file)
index 252d7eb..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/add.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/password.gif b/security/plugins/org.argeo.security.ui/icons/password.gif
deleted file mode 100644 (file)
index a6b251f..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/password.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/refresh.png b/security/plugins/org.argeo.security.ui/icons/refresh.png
deleted file mode 100644 (file)
index a3884fb..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/refresh.png and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/remove.gif b/security/plugins/org.argeo.security.ui/icons/remove.gif
deleted file mode 100644 (file)
index 0ae6dec..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/remove.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/role.gif b/security/plugins/org.argeo.security.ui/icons/role.gif
deleted file mode 100644 (file)
index 274a850..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/role.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/save.gif b/security/plugins/org.argeo.security.ui/icons/save.gif
deleted file mode 100644 (file)
index 654ad7b..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/save.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/save_security.png b/security/plugins/org.argeo.security.ui/icons/save_security.png
deleted file mode 100644 (file)
index ca41dc9..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/save_security.png and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png b/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png
deleted file mode 100644 (file)
index fb7d08d..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/save_security_disabled.png and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/security.gif b/security/plugins/org.argeo.security.ui/icons/security.gif
deleted file mode 100644 (file)
index 57fb95e..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/security.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/user.gif b/security/plugins/org.argeo.security.ui/icons/user.gif
deleted file mode 100644 (file)
index 90a0014..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/user.gif and /dev/null differ
diff --git a/security/plugins/org.argeo.security.ui/icons/users.gif b/security/plugins/org.argeo.security.ui/icons/users.gif
deleted file mode 100644 (file)
index 2de7edd..0000000
Binary files a/security/plugins/org.argeo.security.ui/icons/users.gif and /dev/null differ
index 0a78645affcec7938c6e5f00687d763f475550c3..e189e5efe1c2b91039c321e83f797d7b659c7e17 100644 (file)
@@ -1,33 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.4"?>
 <plugin>
-   <extension
-         point="org.eclipse.ui.perspectives">
-      <perspective
-            class="org.argeo.security.ui.SecurityPerspective"
-            icon="icons/security.gif"
-            id="org.argeo.security.ui.adminSecurityPerspective"
-            name="Security">
-      </perspective>
-   </extension>
-   <extension
-         point="org.eclipse.ui.views">
-      <view
-            class="org.argeo.eclipse.spring.SpringExtensionFactory"
-            icon="icons/users.gif"
-            id="org.argeo.security.ui.adminUsersView"
-            name="Users"
-            restorable="false">
-      </view>
-      <view
-            class="org.argeo.eclipse.spring.SpringExtensionFactory"
-            icon="icons/role.gif"
-            id="org.argeo.security.ui.adminRolesView"
-            name="Roles"
-            restorable="false">
-      </view>
-   </extension>
-   
    <!-- Security -->
    <extension
          id="defaultLoginDialog"
       </callbackHandlerMapping>
    </extension>
    <extension
-           point="org.eclipse.ui.editors">
-               <editor
-                 class="org.argeo.eclipse.spring.SpringExtensionFactory"
-              id="org.argeo.security.ui.adminArgeoUserEditor"
-              name="User"
-              icon="icons/user.gif"
-              default="false">
-        </editor>
-     </extension>
-    <extension
          point="org.eclipse.ui.commands">
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.openArgeoUserEditor"
-            name="OpenArgeoUserEditor">
-                       <commandParameter
-                       id="org.argeo.security.ui.username"
-                       name="Username">
-                       </commandParameter>
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.newArgeoUserEditor"
-            name="OpenArgeoUserEditor">
-      </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.addRole"
-            name="AddRole">
-      </command>
       <command
             defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
             id="org.argeo.security.ui.openChangePasswordDialog"
             name="OpenChangePasswordDialog">
       </command>
-      <command
-            defaultHandler="org.argeo.eclipse.spring.SpringCommandHandler"
-            id="org.argeo.security.ui.refreshUsersList"
-            name="refreshUsersList">
-      </command>
     </extension>
      <extension
          point="org.eclipse.ui.menus">
-       <menuContribution
-            locationURI="toolbar:org.argeo.security.ui.rolesView">
-            <command
-                  commandId="org.argeo.security.ui.addRole"
-                  icon="icons/add.gif"
-                  label="Add Role"
-                  tooltip="Add new role">
-            </command>
-        </menuContribution>
-       <menuContribution
-            locationURI="toolbar:org.argeo.security.ui.usersView">
-            <command
-                  commandId="org.argeo.security.ui.newArgeoUserEditor"
-                  icon="icons/add.gif"
-                  label="Add User"
-                  tooltip="Add new user">
-            </command>
-            <command
-                  commandId="org.argeo.security.ui.refreshUsersList"
-                  icon="icons/refresh.png"
-                  label="Refresh"
-                  tooltip="Refresh user list">
-            </command>
-        </menuContribution>
         <menuContribution
                 locationURI="menu:file?after=additions">
                 <command
                 </command>
           </menuContribution>
   </extension>
-     <extension
-           id="product"
-           point="org.eclipse.core.runtime.products">
-        <product
-              application="org.argeo.security.ui.application.secureUi"
-              name="Agfa Sebi">
-           <property
-                 name="appName"
-                 value="Agfa Sebi">
-           </property>
-        </product>
-     </extension>
-     <extension
+  <extension
            point="org.eclipse.ui.services">
         <sourceProvider
               provider="org.argeo.security.ui.RolesSourceProvider">
            </variable>
         </sourceProvider>
      </extension>
-     <extension
-           point="org.eclipse.ui.activities">
-        <activity
-              description="Only for admins"
-              id="org.argeo.security.ui.adminActivity"
-              name="Admin">
-                 <enabledWhen>
-                   <with variable="roles">
-                     <iterate ifEmpty="false" operator="or">
-                       <equals value="ROLE_ADMIN" />
-                     </iterate>
-                   </with>
-                 </enabledWhen>
-        </activity>
-        <activityPatternBinding
-              activityId="org.argeo.security.ui.adminActivity"
-              isEqualityPattern="true"
-              pattern="org.argeo.security.ui/.*admin.*">
-        </activityPatternBinding>
-     </extension>
  </plugin>
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/SecurityPerspective.java
deleted file mode 100644 (file)
index 8183de5..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-package org.argeo.security.ui;
-
-import org.eclipse.ui.IFolderLayout;
-import org.eclipse.ui.IPageLayout;
-import org.eclipse.ui.IPerspectiveFactory;
-
-public class SecurityPerspective implements IPerspectiveFactory {
-       private String adminRole = "ROLE_ADMIN";
-
-       public void createInitialLayout(IPageLayout layout) {
-//             if (!CurrentUser.roles().contains(adminRole)) {
-//                     MessageDialog
-//                                     .openError(Display.getCurrent().getActiveShell(),
-//                                                     "Forbidden",
-//                                                     "You are not allowed to access this resource.");
-//                     return;
-//             }
-
-               String editorArea = layout.getEditorArea();
-               layout.setEditorAreaVisible(true);
-               layout.setFixed(false);
-
-               IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT,
-                               0.4f, editorArea);
-
-               left.addView("org.argeo.security.ui.adminUsersView");
-               left.addView("org.argeo.security.ui.adminRolesView");
-       }
-
-       public void setAdminRole(String adminRole) {
-               this.adminRole = adminRole;
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/AddRole.java
deleted file mode 100644 (file)
index 1873a13..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-package org.argeo.security.ui.commands;
-
-import org.argeo.ArgeoException;
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ui.views.RolesView;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Add a new role. */
-public class AddRole extends AbstractHandler {
-       public final static String COMMAND_ID = "org.argeo.security.ui.addRole";
-       private ArgeoSecurityService securityService;
-       private String rolePrefix = "ROLE_";
-
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               RolesView rolesView = (RolesView) HandlerUtil
-                               .getActiveWorkbenchWindow(event).getActivePage()
-                               .findView(RolesView.ID);
-               String role = rolesView.getNewRole();
-               if (role.trim().equals(""))
-                       return null;
-               if (role.equals(rolesView.getAddNewRoleText()))
-                       return null;
-               role = role.trim().toUpperCase();
-               if (!role.startsWith(rolePrefix))
-                       role = rolePrefix + role;
-               if (securityService.listEditableRoles().contains(role))
-                       throw new ArgeoException("Role " + role + " already exists");
-               securityService.newRole(role);
-               rolesView.refresh();
-               return null;
-       }
-
-       public void setSecurityService(ArgeoSecurityService securityService) {
-               this.securityService = securityService;
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/OpenArgeoUserEditor.java
deleted file mode 100644 (file)
index c9bd25f..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package org.argeo.security.ui.commands;
-
-import org.argeo.security.ui.editors.ArgeoUserEditor;
-import org.argeo.security.ui.editors.ArgeoUserEditorInput;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Command handler to set visible or open a Argeo user. */
-public class OpenArgeoUserEditor extends AbstractHandler {
-       public final static String COMMAND_ID = "org.argeo.security.ui.openArgeoUserEditor";
-       public final static String PARAM_USERNAME = "org.argeo.security.ui.username";
-
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               try {
-                       ArgeoUserEditorInput editorInput = new ArgeoUserEditorInput(
-                                       event.getParameter(PARAM_USERNAME));
-                       IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(
-                                       event).getActivePage();
-                       activePage.openEditor(editorInput, ArgeoUserEditor.ID);
-               } catch (Exception e) {
-                       throw new ExecutionException("Cannot open editor", e);
-               }
-               return null;
-       }
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/RefreshUsersList.java
deleted file mode 100644 (file)
index a385eb9..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-package org.argeo.security.ui.commands;
-
-import org.argeo.security.ui.views.UsersView;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Refresh the main EBI list. */
-public class RefreshUsersList extends AbstractHandler {
-
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               UsersView view = (UsersView) HandlerUtil
-                               .getActiveWorkbenchWindow(event).getActivePage()
-                               .findView(UsersView.ID);
-               view.refresh();
-               return null;
-       }
-
-}
\ No newline at end of file
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/commands/SaveArgeoUser.java
deleted file mode 100644 (file)
index 7d81743..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-package org.argeo.security.ui.commands;
-
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
-
-/** Save the currently edited Argeo user. */
-public class SaveArgeoUser extends AbstractHandler {
-       public final static String COMMAND_ID = "org.argeo.security.ui.saveArgeoUser";
-
-       public Object execute(ExecutionEvent event) throws ExecutionException {
-               try {
-                       IWorkbenchPart iwp = HandlerUtil.getActiveWorkbenchWindow(event)
-                                       .getActivePage().getActivePart();
-
-                       if (!(iwp instanceof IEditorPart))
-                               return null;
-                       IEditorPart editor = (IEditorPart) iwp;
-                       editor.doSave(null);
-               } catch (Exception e) {
-                       MessageDialog.openError(Display.getDefault().getActiveShell(),
-                                       "Error", "Cannot save user: " + e.getMessage());
-               }
-               return null;
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditor.java
deleted file mode 100644 (file)
index a896f61..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.argeo.security.ui.editors;
-
-import org.argeo.ArgeoException;
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ArgeoUser;
-import org.argeo.security.SimpleArgeoUser;
-import org.argeo.security.nature.SimpleUserNature;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.forms.editor.FormEditor;
-
-/** Editor for an Argeo user. */
-public class ArgeoUserEditor extends FormEditor {
-       public final static String ID = "org.argeo.security.ui.adminArgeoUserEditor";
-
-       private ArgeoUser user;
-       private ArgeoSecurityService securityService;
-
-       public void init(IEditorSite site, IEditorInput input)
-                       throws PartInitException {
-               super.init(site, input);
-               String username = ((ArgeoUserEditorInput) getEditorInput())
-                               .getUsername();
-               if (username == null) {// new
-                       user = new SimpleArgeoUser();
-                       user.getUserNatures().put(SimpleUserNature.TYPE,
-                                       new SimpleUserNature());
-               } else
-                       user = securityService.getUser(username);
-               this.setPartProperty("name", username != null ? username : "<new user>");
-               setPartName(username != null ? username : "<new user>");
-       }
-
-       protected void addPages() {
-               try {
-                       addPage(new DefaultUserMainPage(this, securityService, user));
-
-               } catch (PartInitException e) {
-                       throw new ArgeoException("Not able to add page ", e);
-               }
-       }
-
-       @Override
-       public void doSave(IProgressMonitor monitor) {
-               // list pages
-               // TODO: make it more generic
-               findPage(DefaultUserMainPage.ID).doSave(monitor);
-
-               if (securityService.userExists(user.getUsername()))
-                       securityService.updateUser(user);
-               else {
-                       securityService.newUser(user);
-                       setPartName(user.getUsername());
-               }
-               firePropertyChange(PROP_DIRTY);
-       }
-
-       @Override
-       public void doSaveAs() {
-       }
-
-       @Override
-       public boolean isSaveAsAllowed() {
-               return false;
-       }
-
-       public void setSecurityService(ArgeoSecurityService securityService) {
-               this.securityService = securityService;
-       }
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/ArgeoUserEditorInput.java
deleted file mode 100644 (file)
index 9d61e9f..0000000
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.argeo.security.ui.editors;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IPersistableElement;
-
-/** Editor input for an Argeo user. */
-public class ArgeoUserEditorInput implements IEditorInput {
-       private final String username;
-
-       public ArgeoUserEditorInput(String username) {
-               this.username = username;
-       }
-
-       public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
-               return null;
-       }
-
-       public boolean exists() {
-               return username != null;
-       }
-
-       public ImageDescriptor getImageDescriptor() {
-               return null;
-       }
-
-       public String getName() {
-               return username != null ? username : "<new user>";
-       }
-
-       public IPersistableElement getPersistable() {
-               return null;
-       }
-
-       public String getToolTipText() {
-               return username != null ? username : "<new user>";
-       }
-
-       public boolean equals(Object obj) {
-               if (!(obj instanceof ArgeoUserEditorInput))
-                       return false;
-               if (((ArgeoUserEditorInput) obj).getUsername() == null)
-                       return false;
-               return ((ArgeoUserEditorInput) obj).getUsername().equals(username);
-       }
-
-       public String getUsername() {
-               return username;
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/editors/DefaultUserMainPage.java
deleted file mode 100644 (file)
index 6180de4..0000000
+++ /dev/null
@@ -1,337 +0,0 @@
-package org.argeo.security.ui.editors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ArgeoUser;
-import org.argeo.security.SimpleArgeoUser;
-import org.argeo.security.nature.SimpleUserNature;
-import org.argeo.security.ui.SecurityUiPlugin;
-import org.eclipse.jface.viewers.CellEditor;
-import org.eclipse.jface.viewers.CheckboxCellEditor;
-import org.eclipse.jface.viewers.ColumnLabelProvider;
-import org.eclipse.jface.viewers.EditingSupport;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.TableViewerColumn;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.AbstractFormPart;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.SectionPart;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ColumnLayout;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-import org.eclipse.ui.forms.widgets.Section;
-
-/**
- * Display/edit the properties common to all {@link ArgeoUser} (username and
- * roles) as well as the properties of the {@link SimpleUserNature}.
- */
-public class DefaultUserMainPage extends FormPage {
-       final static String ID = "argeoUserEditor.mainPage";
-
-       private final static Log log = LogFactory.getLog(DefaultUserMainPage.class);
-       private final static Image ROLE_CHECKED = SecurityUiPlugin
-                       .getImageDescriptor("icons/security.gif").createImage();
-
-       private ArgeoUser user;
-       private SimpleUserNature simpleNature;
-       private String simpleNatureType;
-       private ArgeoSecurityService securityService;
-
-       public DefaultUserMainPage(FormEditor editor,
-                       ArgeoSecurityService securityService, ArgeoUser user) {
-               super(editor, ID, "Main");
-               this.securityService = securityService;
-               this.user = user;
-               this.simpleNature = SimpleUserNature.findSimpleUserNature(user,
-                               simpleNatureType);
-       }
-
-       protected void createFormContent(final IManagedForm mf) {
-               ScrolledForm form = mf.getForm();
-               form.setText(simpleNature.getFirstName() + " "
-                               + simpleNature.getLastName());
-               ColumnLayout mainLayout = new ColumnLayout();
-               mainLayout.minNumColumns = 1;
-               mainLayout.maxNumColumns = 4;
-               mainLayout.topMargin = 0;
-               mainLayout.bottomMargin = 5;
-               mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10;
-               form.getBody().setLayout(mainLayout);
-
-               createGeneralPart(form.getBody());
-               createRolesPart(form.getBody());
-               createPassworPart(form.getBody());
-       }
-
-       /** Creates the general section */
-       protected void createGeneralPart(Composite parent) {
-               FormToolkit tk = getManagedForm().getToolkit();
-               Section section = tk.createSection(parent, Section.TITLE_BAR);
-               section.setText("General");
-
-               Composite body = tk.createComposite(section, SWT.WRAP);
-               section.setClient(body);
-               GridLayout layout = new GridLayout();
-               layout.marginWidth = layout.marginHeight = 0;
-               layout.numColumns = 2;
-               body.setLayout(layout);
-
-               // add widgets (view)
-               final Text username;
-               if (user.getUsername() != null) {
-                       tk.createLabel(body, "Username");
-                       tk.createLabel(body, user.getUsername());
-                       username = null;
-               } else {
-                       username = createLT(body, "Username", "");
-               }
-               final Text firstName = createLT(body, "First name",
-                               simpleNature.getFirstName());
-               final Text lastName = createLT(body, "Last name",
-                               simpleNature.getLastName());
-               final Text email = createLT(body, "Email", simpleNature.getEmail());
-               final Text description = createLT(body, "Description",
-                               simpleNature.getDescription());
-
-               // create form part (controller)
-               AbstractFormPart part = new SectionPart(section) {
-                       public void commit(boolean onSave) {
-                               if (username != null) {
-                                       ((SimpleArgeoUser) user).setUsername(username.getText());
-                                       username.setEditable(false);
-                                       username.setEnabled(false);
-                               }
-                               simpleNature.setFirstName(firstName.getText());
-                               simpleNature.setLastName(lastName.getText());
-                               simpleNature.setEmail(email.getText());
-                               simpleNature.setDescription(description.getText());
-                               super.commit(onSave);
-                               if (log.isTraceEnabled())
-                                       log.trace("General part committed");
-                       }
-               };
-               if (username != null)
-                       username.addModifyListener(new FormPartML(part));
-               firstName.addModifyListener(new FormPartML(part));
-               lastName.addModifyListener(new FormPartML(part));
-               email.addModifyListener(new FormPartML(part));
-               description.addModifyListener(new FormPartML(part));
-               getManagedForm().addPart(part);
-       }
-
-       /** Creates the password section */
-       protected void createPassworPart(Composite parent) {
-               FormToolkit tk = getManagedForm().getToolkit();
-               Section section = tk.createSection(parent, Section.TITLE_BAR);
-               section.setText("Password");
-
-               Composite body = tk.createComposite(section, SWT.WRAP);
-               section.setClient(body);
-               GridLayout layout = new GridLayout();
-               layout.marginWidth = layout.marginHeight = 0;
-               layout.numColumns = 2;
-               body.setLayout(layout);
-
-               // add widgets (view)
-               final Text password1 = createLP(body, "New password", "");
-               final Text password2 = createLP(body, "Repeat password", "");
-               // create form part (controller)
-               AbstractFormPart part = new SectionPart(section) {
-                       public void commit(boolean onSave) {
-                               if (!password1.getText().equals("")
-                                               && password1.getText().equals(password2.getText())) {
-                                       ((SimpleArgeoUser) user).setPassword(password1.getText());
-                               }
-                               super.commit(onSave);
-                               if (log.isTraceEnabled())
-                                       log.trace("Password part committed");
-                       }
-               };
-               password1.addModifyListener(new FormPartML(part));
-               password2.addModifyListener(new FormPartML(part));
-               getManagedForm().addPart(part);
-       }
-
-       /** Creates the role section */
-       protected void createRolesPart(Composite parent) {
-               FormToolkit tk = getManagedForm().getToolkit();
-               Section section = tk.createSection(parent, Section.DESCRIPTION
-                               | Section.TITLE_BAR);
-               section.setText("Roles");
-               section.setDescription("Roles define "
-                               + "the authorizations for this user.");
-               Table table = new Table(section, SWT.MULTI | SWT.H_SCROLL
-                               | SWT.V_SCROLL);
-               section.setClient(table);
-
-               AbstractFormPart part = new SectionPart(section) {
-                       public void commit(boolean onSave) {
-                               // roles have already been modified in editing
-                               super.commit(onSave);
-                               if (log.isTraceEnabled())
-                                       log.trace("Role part committed");
-                       }
-               };
-               getManagedForm().addPart(part);
-
-               GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
-               gridData.verticalSpan = 20;
-               table.setLayoutData(gridData);
-               table.setLinesVisible(true);
-               table.setHeaderVisible(false);
-               TableViewer viewer = new TableViewer(table);
-
-               // check column
-               TableViewerColumn column = createTableViewerColumn(viewer, "checked",
-                               20);
-               column.setLabelProvider(new ColumnLabelProvider() {
-                       public String getText(Object element) {
-                               return null;
-                       }
-
-                       public Image getImage(Object element) {
-                               String role = element.toString();
-                               if (user.getRoles().contains(role)) {
-                                       return ROLE_CHECKED;
-                               } else {
-                                       return null;
-                               }
-                       }
-               });
-               column.setEditingSupport(new RoleEditingSupport(viewer, part));
-
-               // role column
-               column = createTableViewerColumn(viewer, "Role", 200);
-               column.setLabelProvider(new ColumnLabelProvider() {
-                       public String getText(Object element) {
-                               return element.toString();
-                       }
-
-                       public Image getImage(Object element) {
-                               return null;
-                       }
-               });
-               viewer.setContentProvider(new RolesContentProvider());
-               viewer.setInput(getEditorSite());
-       }
-
-       protected TableViewerColumn createTableViewerColumn(TableViewer viewer,
-                       String title, int bound) {
-               final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
-                               SWT.NONE);
-               final TableColumn column = viewerColumn.getColumn();
-               column.setText(title);
-               column.setWidth(bound);
-               column.setResizable(true);
-               column.setMoveable(true);
-               return viewerColumn;
-
-       }
-
-       /** Creates label and text. */
-       protected Text createLT(Composite body, String label, String value) {
-               FormToolkit toolkit = getManagedForm().getToolkit();
-               toolkit.createLabel(body, label);
-               Text text = toolkit.createText(body, value, SWT.BORDER);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               return text;
-       }
-
-       /** Creates label and password. */
-       protected Text createLP(Composite body, String label, String value) {
-               FormToolkit toolkit = getManagedForm().getToolkit();
-               toolkit.createLabel(body, label);
-               Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD);
-               text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               return text;
-       }
-
-       public void setSimpleNatureType(String simpleNatureType) {
-               this.simpleNatureType = simpleNatureType;
-       }
-
-       private class FormPartML implements ModifyListener {
-               private AbstractFormPart formPart;
-
-               public FormPartML(AbstractFormPart generalPart) {
-                       this.formPart = generalPart;
-               }
-
-               public void modifyText(ModifyEvent e) {
-                       formPart.markDirty();
-               }
-
-       }
-
-       private class RolesContentProvider implements IStructuredContentProvider {
-               public Object[] getElements(Object inputElement) {
-                       return securityService.listEditableRoles().toArray();
-               }
-
-               public void dispose() {
-               }
-
-               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-               }
-       }
-
-       /** Select the columns by editing the checkbox in the first column */
-       class RoleEditingSupport extends EditingSupport {
-
-               private final TableViewer viewer;
-               private final AbstractFormPart formPart;
-
-               public RoleEditingSupport(TableViewer viewer, AbstractFormPart formPart) {
-                       super(viewer);
-                       this.viewer = viewer;
-                       this.formPart = formPart;
-               }
-
-               @Override
-               protected CellEditor getCellEditor(Object element) {
-                       return new CheckboxCellEditor(null, SWT.CHECK | SWT.READ_ONLY);
-
-               }
-
-               @Override
-               protected boolean canEdit(Object element) {
-                       return true;
-               }
-
-               @Override
-               protected Object getValue(Object element) {
-                       String role = element.toString();
-                       return user.getRoles().contains(role);
-
-               }
-
-               @Override
-               protected void setValue(Object element, Object value) {
-                       Boolean inRole = (Boolean) value;
-                       String role = element.toString();
-                       if (inRole && !user.getRoles().contains(role)) {
-                               user.getRoles().add(role);
-                               formPart.markDirty();
-                       } else if (!inRole && user.getRoles().contains(role)) {
-                               user.getRoles().remove(role);
-                               formPart.markDirty();
-                       }
-                       viewer.refresh();
-               }
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/CurrentUserView.java
deleted file mode 100644 (file)
index 366ac34..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-package org.argeo.security.ui.views;
-
-import org.argeo.security.ui.internal.CurrentUser;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.part.ViewPart;
-
-public class CurrentUserView extends ViewPart {
-       private TableViewer viewer;
-
-       @Override
-       public void createPartControl(Composite parent) {
-
-               // viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
-               // | SWT.V_SCROLL);
-               viewer = new TableViewer(createTable(parent));
-               viewer.setContentProvider(new UsersContentProvider());
-               viewer.setLabelProvider(new UsersLabelProvider());
-               viewer.setInput(getViewSite());
-               // viewer.setInput(SecurityContextHolder.getContext());
-       }
-
-       protected Table createTable(Composite parent) {
-               int style = SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL;
-
-               Table table = new Table(parent, style);
-
-               // GridData gridData = new GridData(GridData.FILL_BOTH);
-               // gridData.grabExcessVerticalSpace = true;
-               // gridData.grabExcessHorizontalSpace = true;
-               // gridData.horizontalSpan = 3;
-               // table.setLayoutData(gridData);
-
-               table.setLinesVisible(true);
-               table.setHeaderVisible(true);
-
-               TableColumn column = new TableColumn(table, SWT.LEFT, 0);
-               column.setText("ID");
-               column.setWidth(100);
-
-               // column = new TableColumn(table, SWT.LEFT, 1);
-               // column.setText("Password");
-               // column.setWidth(200);
-
-               // column = new TableColumn(table, SWT.LEFT, 2);
-               // column.setText("Roles");
-               // column.setWidth(300);
-
-               return table;
-       }
-
-       @Override
-       public void setFocus() {
-               viewer.getTable().setFocus();
-       }
-
-       private class UsersContentProvider implements IStructuredContentProvider {
-
-               public Object[] getElements(Object inputElement) {
-                       return getChildren(inputElement);
-               }
-
-               public Object[] getChildren(Object parentElement) {
-                       // ILoginContext secureContext = LoginContextFactory
-                       // .createContext("SPRING");
-                       // try {
-                       // secureContext.login();
-                       // } catch (LoginException e) {
-                       // // login failed
-                       // }
-                       //
-                       // Subject subject = null;
-                       // // subject = Subject.getSubject(AccessController.getContext());
-                       // try {
-                       // subject = secureContext.getSubject();
-                       // } catch (Exception e) {
-                       // e.printStackTrace();
-                       // throw new ArgeoException("Cannot retrieve subject", e);
-                       // }
-                       //
-                       // if (subject == null)
-                       // throw new ArgeoException("No subject found");
-                       // return subject.getPrincipals().toArray();
-                       return CurrentUser.roles().toArray();
-               }
-
-               public void dispose() {
-                       // TODO Auto-generated method stub
-
-               }
-
-               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-                       // TODO Auto-generated method stub
-
-               }
-
-       }
-
-       private class UsersLabelProvider extends LabelProvider implements
-                       ITableLabelProvider {
-               public String getColumnText(Object element, int columnIndex) {
-                       // Principal argeoUser = (Principal) element;
-                       // switch (columnIndex) {
-                       // case 0:
-                       // return argeoUser.getName();
-                       // case 1:
-                       // return argeoUser.toString();
-                       // default:
-                       // throw new ArgeoException("Unmanaged column " + columnIndex);
-                       // }
-                       return element.toString();
-               }
-
-               public Image getColumnImage(Object element, int columnIndex) {
-                       // TODO Auto-generated method stub
-                       return null;
-               }
-
-       }
-
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/RolesView.java
deleted file mode 100644 (file)
index a58675e..0000000
+++ /dev/null
@@ -1,177 +0,0 @@
-package org.argeo.security.ui.views;
-
-import java.util.ArrayList;
-
-import org.argeo.ArgeoException;
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ArgeoUser;
-import org.argeo.security.ui.SecurityUiPlugin;
-import org.argeo.security.ui.commands.AddRole;
-import org.argeo.security.ui.commands.OpenArgeoUserEditor;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.IParameter;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.part.ViewPart;
-
-/** List all roles. */
-public class RolesView extends ViewPart {
-       public final static String ID = "org.argeo.security.ui.rolesView";
-
-       private Text newRole;
-
-       private TableViewer viewer;
-       private ArgeoSecurityService securityService;
-
-       private String addNewRoleText = "<add new role here>";
-
-       @Override
-       public void createPartControl(Composite parent) {
-               parent.setLayout(new GridLayout(1, false));
-
-               // new role text field
-               newRole = new Text(parent, SWT.BORDER);
-               newRole.setText(addNewRoleText);
-               newRole.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
-               // default action is add role
-               newRole.addListener(SWT.DefaultSelection, new Listener() {
-                       public void handleEvent(Event evt) {
-                               IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench();
-                               IHandlerService handlerService = (IHandlerService) iw
-                                               .getService(IHandlerService.class);
-                               try {
-                                       handlerService.executeCommand(AddRole.COMMAND_ID, evt);
-                               } catch (Exception e) {
-                                       throw new ArgeoException("Cannot execute add role command",
-                                                       e);
-                               }
-                       }
-               });
-               // select all on focus
-               newRole.addListener(SWT.FocusIn, new Listener() {
-                       public void handleEvent(Event e) {
-                               newRole.selectAll();
-                       }
-               });
-
-               // roles table
-               Table table = new Table(parent, SWT.V_SCROLL | SWT.BORDER);
-               table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               table.setLinesVisible(false);
-               table.setHeaderVisible(false);
-               viewer = new TableViewer(table);
-               viewer.setContentProvider(new RolesContentProvider());
-               viewer.setLabelProvider(new UsersLabelProvider());
-               viewer.setInput(getViewSite());
-               viewer.addDoubleClickListener(new ViewDoubleClickListener());
-       }
-
-       @Override
-       public void setFocus() {
-               viewer.getTable().setFocus();
-       }
-
-       public void setSecurityService(ArgeoSecurityService securityService) {
-               this.securityService = securityService;
-       }
-
-       public String getAddNewRoleText() {
-               return addNewRoleText;
-       }
-
-       private class RolesContentProvider implements IStructuredContentProvider {
-
-               public Object[] getElements(Object inputElement) {
-                       return securityService.listEditableRoles().toArray();
-               }
-
-               public void dispose() {
-               }
-
-               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-               }
-
-       }
-
-       private class UsersLabelProvider extends LabelProvider implements
-                       ITableLabelProvider {
-               public String getColumnText(Object element, int columnIndex) {
-                       return element.toString();
-               }
-
-               public Image getColumnImage(Object element, int columnIndex) {
-                       return null;
-               }
-
-       }
-
-       class ViewDoubleClickListener implements IDoubleClickListener {
-               public void doubleClick(DoubleClickEvent evt) {
-                       Object obj = ((IStructuredSelection) evt.getSelection())
-                                       .getFirstElement();
-
-                       if (obj instanceof ArgeoUser) {
-                               ArgeoUser argeoUser = (ArgeoUser) obj;
-
-                               IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench();
-                               IHandlerService handlerService = (IHandlerService) iw
-                                               .getService(IHandlerService.class);
-                               try {
-                                       String commandId = OpenArgeoUserEditor.COMMAND_ID;
-                                       String paramName = OpenArgeoUserEditor.PARAM_USERNAME;
-
-                                       // TODO: factorize this
-                                       // execute related command
-                                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
-                                       ICommandService cmdService = (ICommandService) window
-                                                       .getService(ICommandService.class);
-                                       Command cmd = cmdService.getCommand(commandId);
-                                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
-                                       IParameter iparam = cmd.getParameter(paramName);
-                                       Parameterization param = new Parameterization(iparam,
-                                                       argeoUser.getUsername());
-                                       parameters.add(param);
-                                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
-                                                       parameters.toArray(new Parameterization[parameters
-                                                                       .size()]));
-                                       handlerService = (IHandlerService) window
-                                                       .getService(IHandlerService.class);
-                                       handlerService.executeCommand(pc, null);
-                               } catch (Exception e) {
-                                       throw new ArgeoException("Cannot open editor", e);
-                               }
-
-                       }
-               }
-       }
-
-       public String getNewRole() {
-               return newRole.getText();
-       }
-
-       public void refresh() {
-               viewer.refresh();
-               newRole.setText(addNewRoleText);
-       }
-}
diff --git a/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java b/security/plugins/org.argeo.security.ui/src/main/java/org/argeo/security/ui/views/UsersView.java
deleted file mode 100644 (file)
index 08bf7b5..0000000
+++ /dev/null
@@ -1,174 +0,0 @@
-package org.argeo.security.ui.views;
-
-import java.util.ArrayList;
-
-import org.argeo.ArgeoException;
-import org.argeo.security.ArgeoSecurityService;
-import org.argeo.security.ArgeoUser;
-import org.argeo.security.nature.SimpleUserNature;
-import org.argeo.security.ui.SecurityUiPlugin;
-import org.argeo.security.ui.commands.OpenArgeoUserEditor;
-import org.argeo.security.ui.internal.CurrentUser;
-import org.eclipse.core.commands.Command;
-import org.eclipse.core.commands.IParameter;
-import org.eclipse.core.commands.Parameterization;
-import org.eclipse.core.commands.ParameterizedCommand;
-import org.eclipse.jface.viewers.DoubleClickEvent;
-import org.eclipse.jface.viewers.IDoubleClickListener;
-import org.eclipse.jface.viewers.IStructuredContentProvider;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.ITableLabelProvider;
-import org.eclipse.jface.viewers.LabelProvider;
-import org.eclipse.jface.viewers.TableViewer;
-import org.eclipse.jface.viewers.Viewer;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableColumn;
-import org.eclipse.ui.IWorkbench;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.commands.ICommandService;
-import org.eclipse.ui.handlers.IHandlerService;
-import org.eclipse.ui.part.ViewPart;
-
-/** List all users. */
-public class UsersView extends ViewPart {
-       public final static String ID = "org.argeo.security.ui.usersView";
-
-       private TableViewer viewer;
-       private ArgeoSecurityService securityService;
-
-       private String simpleNatureType = null;
-
-       @Override
-       public void createPartControl(Composite parent) {
-               viewer = new TableViewer(createTable(parent));
-               viewer.setContentProvider(new UsersContentProvider());
-               viewer.setLabelProvider(new UsersLabelProvider());
-               viewer.addDoubleClickListener(new ViewDoubleClickListener());
-               viewer.setInput(getViewSite());
-       }
-
-       protected Table createTable(Composite parent) {
-               Table table = new Table(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
-               table.setLinesVisible(true);
-               table.setHeaderVisible(true);
-               TableColumn column = new TableColumn(table, SWT.LEFT, 0);
-               column.setText("User");
-               column.setWidth(50);
-               column = new TableColumn(table, SWT.LEFT, 1);
-               column.setText("First Name");
-               column.setWidth(100);
-               column = new TableColumn(table, SWT.LEFT, 2);
-               column.setText("Last Name");
-               column.setWidth(100);
-               column = new TableColumn(table, SWT.LEFT, 3);
-               column.setText("E-mail");
-               column.setWidth(100);
-               return table;
-       }
-
-       @Override
-       public void setFocus() {
-               viewer.getTable().setFocus();
-       }
-
-       public void setSecurityService(ArgeoSecurityService securityService) {
-               this.securityService = securityService;
-       }
-
-       public void setSimpleNatureType(String simpleNatureType) {
-               this.simpleNatureType = simpleNatureType;
-       }
-
-       public void refresh() {
-               viewer.refresh();
-       }
-
-       private class UsersContentProvider implements IStructuredContentProvider {
-
-               public Object[] getElements(Object inputElement) {
-                       return securityService.listUsers().toArray();
-               }
-
-               public void dispose() {
-               }
-
-               public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
-               }
-
-       }
-
-       private class UsersLabelProvider extends LabelProvider implements
-                       ITableLabelProvider {
-               public String getColumnText(Object element, int columnIndex) {
-                       String currentUsername = CurrentUser.getUsername();
-                       ArgeoUser user = (ArgeoUser) element;
-                       SimpleUserNature simpleNature = SimpleUserNature
-                                       .findSimpleUserNature(user, simpleNatureType);
-                       switch (columnIndex) {
-                       case 0:
-                               String userName = user.getUsername();
-                               if (userName.equals(currentUsername))
-                                       userName = userName + "*";
-                               return userName;
-                       case 1:
-                               return simpleNature.getFirstName();
-                       case 2:
-                               return simpleNature.getLastName();
-                       case 3:
-                               return simpleNature.getEmail();
-                       default:
-                               throw new ArgeoException("Unmanaged column " + columnIndex);
-                       }
-               }
-
-               public Image getColumnImage(Object element, int columnIndex) {
-                       // TODO Auto-generated method stub
-                       return null;
-               }
-
-       }
-
-       class ViewDoubleClickListener implements IDoubleClickListener {
-               public void doubleClick(DoubleClickEvent evt) {
-                       Object obj = ((IStructuredSelection) evt.getSelection())
-                                       .getFirstElement();
-
-                       if (obj instanceof ArgeoUser) {
-                               ArgeoUser argeoUser = (ArgeoUser) obj;
-
-                               IWorkbench iw = SecurityUiPlugin.getDefault().getWorkbench();
-                               IHandlerService handlerService = (IHandlerService) iw
-                                               .getService(IHandlerService.class);
-                               try {
-                                       String commandId = OpenArgeoUserEditor.COMMAND_ID;
-                                       String paramName = OpenArgeoUserEditor.PARAM_USERNAME;
-
-                                       // TODO: factorize this
-                                       // execute related command
-                                       IWorkbenchWindow window = iw.getActiveWorkbenchWindow();
-                                       ICommandService cmdService = (ICommandService) window
-                                                       .getService(ICommandService.class);
-                                       Command cmd = cmdService.getCommand(commandId);
-                                       ArrayList<Parameterization> parameters = new ArrayList<Parameterization>();
-                                       IParameter iparam = cmd.getParameter(paramName);
-                                       Parameterization param = new Parameterization(iparam,
-                                                       argeoUser.getUsername());
-                                       parameters.add(param);
-                                       ParameterizedCommand pc = new ParameterizedCommand(cmd,
-                                                       parameters.toArray(new Parameterization[parameters
-                                                                       .size()]));
-                                       handlerService = (IHandlerService) window
-                                                       .getService(IHandlerService.class);
-                                       handlerService.executeCommand(pc, null);
-                               } catch (Exception e) {
-                                       throw new ArgeoException("Cannot open editor", e);
-                               }
-
-                       }
-               }
-       }
-
-}