implementing #4120: User always needs to have the right to change password and hidin...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 14 Mar 2014 13:52:45 +0000 (13:52 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Fri, 14 Mar 2014 13:52:45 +0000 (13:52 +0000)
.gitattributes
eu.etaxonomy.taxeditor.store/plugin.xml
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/AuthenticationSourceProvider.java [moved from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RolesSourceProvider.java with 62% similarity]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java

index 15ef3f6c063abc9aa38fe582316d4a7e024b3202..801bb665a4d33d92b744bc297c04e5c557a054f7 100644 (file)
@@ -1144,6 +1144,7 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/Fe
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/OpenFeatureTreeEditorWizardHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/SelectFeatureTreeWizardPage.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/ShowLoginWindowHandler.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/identificationkey/AbstractIdentificaitonKeyWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/io/AbstractIOManager.java -text
@@ -1271,9 +1272,9 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/men
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/menu/TaxonRelationshipTypeMenuPreferences.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/VocabularyTermWizard.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/VocabularyTermWizardPage.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/AuthenticationSourceProvider.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/PermissionPropertyTester.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RequiredPermissions.java -text
-eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RolesSourceProvider.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStoreConnector.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/ContextManager.java -text
index 0d696cc577875dc395ee7e958cda58260c89e9f3..c79f7ffac9c4bc940a4a56bdd912044f6ce4bb0f 100644 (file)
                label="Switch User"
                style="push">
          </command>
+         <command
+               commandId="eu.etaxonomy.taxeditor.store.openPasswordWizzard"
+               label="Change Password"
+               style="push">
+         </command>
          <separator
                name="eu.etaxonomy.taxeditor.application.filemenu.login"
                visible="true">
             </reference>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler"
+            commandId="eu.etaxonomy.taxeditor.store.operations.showLoginWindow">
+         <enabledWhen>
+            <reference
+                  definitionId="isUserLoggedIn">
+            </reference></enabledWhen>
+      </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.handler.OpenPasswordWizzardHandler"
+            commandId="eu.etaxonomy.taxeditor.store.openPasswordWizzard">
+         <enabledWhen>
+            <reference
+                  definitionId="isUserLoggedIn">
+            </reference></enabledWhen>
+      </handler>
    </extension>
    <extension
          name="Popup Menu Commands"
             name="Update Datasource">
       </command>
       <command
-            defaultHandler="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler"
             id="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
             name="Show Login Window">
       </command>
          id="eu.etaxonomy.taxeditor.store.open.FeatureTreeEditorWizard"
          name="Open Feature Tree Editor Wizard">
          </command>
+      <command
+            id="eu.etaxonomy.taxeditor.store.openPasswordWizzard"
+            name="Open Password Wizzard">
+      </command>
    </extension>
    <extension
          point="org.eclipse.ui.importWizards">
             </test>
          </with>
       </definition>
+      <definition
+            id="isUserLoggedIn">
+            <with
+               variable="eu.etaxonomy.taxeditor.security.user">
+               <instanceof
+                     value="eu.etaxonomy.cdm.model.common.User">
+               </instanceof>
+         </with>
+      </definition>
       <definition
             id="hasROLE_USER_MANAGER">
             <with
 <extension
       point="org.eclipse.ui.services">
    <sourceProvider
-         provider="eu.etaxonomy.taxeditor.security.RolesSourceProvider">
+         provider="eu.etaxonomy.taxeditor.security.AuthenticationSourceProvider">
       <variable
             name="eu.etaxonomy.taxeditor.security.userRoles"
             priorityLevel="workbench">
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/OpenPasswordWizzardHandler.java
new file mode 100644 (file)
index 0000000..e61f23c
--- /dev/null
@@ -0,0 +1,66 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+
+package eu.etaxonomy.taxeditor.handler;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.commands.IHandler;
+import org.eclipse.jface.wizard.WizardDialog;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.model.common.User;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.password.PasswordWizard;
+
+/**
+ * <p>ShowLoginWindowHandler class.</p>
+ *
+ * @author n.hoffmann
+ * @created Aug 7, 2009
+ * @version 1.0
+ */
+public class OpenPasswordWizzardHandler extends AbstractHandler implements IHandler{
+
+       /* (non-Javadoc)
+        * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+        */
+       /** {@inheritDoc} */
+       @Override
+    public Object execute(ExecutionEvent event) throws ExecutionException {
+
+           Object principal = CdmStore.getCurrentAuthentiation().getPrincipal();
+
+           if(principal instanceof User){
+               ConversationHolder conversation = CdmStore.createConversation();
+
+               PasswordWizard wizard = new PasswordWizard(conversation, (User)principal);
+               WizardDialog dialog = new WizardDialog(AbstractUtility.getShell(), wizard);
+
+               dialog.open();
+
+               // clean up
+               conversation.commit();
+               conversation.unbind();
+               conversation.close();
+           } else {
+               // should never happen, log an error
+               AbstractUtility.error(OpenPasswordWizzardHandler.class, "The principal currently authenticated is not a eu.etaxonomy.cdm.model.common.User", null);
+           }
+
+               return null;
+
+       }
+
+
+
+}
similarity index 62%
rename from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RolesSourceProvider.java
rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/AuthenticationSourceProvider.java
index abb44e7c6c1c356e27ecc835d391a5a5141eafc2..637c8ab8a468177d0cfd07db104c2bd498650aaa 100644 (file)
@@ -20,18 +20,25 @@ import eu.etaxonomy.taxeditor.store.LoginManager;
 /**
  * Provides the Roles assigned to the currently authenticated principal as the
  * variable {@code eu.etaxonomy.taxeditor.security.userRoles}
- * 
+ *
  * @author a.kohlbecker
- * 
+ *
  */
-public class RolesSourceProvider extends AbstractSourceProvider implements Observer {
+public class AuthenticationSourceProvider extends AbstractSourceProvider implements Observer {
 
-       public final static String RIGHTS_VARIABLE = "eu.etaxonomy.taxeditor.security.userRoles";
-       private final static String[] PROVIDED_SOURCE_NAMES = new String[] { RIGHTS_VARIABLE };
+       public final static String USER_ROLES_VARIABLE = "eu.etaxonomy.taxeditor.security.userRoles";
+       public final static String USER_NAME_VARIABLE = "eu.etaxonomy.taxeditor.security.userName";
+       public final static String USER_VARIABLE = "eu.etaxonomy.taxeditor.security.user";
 
-       private final static Map<String, List<String>> stateMap = new HashMap<String, List<String>>();
+       private final static String[] PROVIDED_SOURCE_NAMES = new String[] {
+           USER_ROLES_VARIABLE,
+           USER_NAME_VARIABLE,
+           USER_VARIABLE
+           };
 
-       public RolesSourceProvider() {
+       private final static Map<String, Object> stateMap = new HashMap<String, Object>();
+
+       public AuthenticationSourceProvider() {
                super();
                initialize();
        }
@@ -55,11 +62,36 @@ public class RolesSourceProvider extends AbstractSourceProvider implements Obser
                        rolesStr.add(r.getAuthority());
                }
 
-               stateMap.put(RIGHTS_VARIABLE, rolesStr);
+               stateMap.put(USER_ROLES_VARIABLE, rolesStr);
+               stateMap.put(USER_VARIABLE, getCurrentAutheticationPrincipal());
+               stateMap.put(USER_NAME_VARIABLE, getCurrentAutheticationName());
                return stateMap;
        }
 
-       /*
+       /**
+     * @return
+     */
+    private String getCurrentAutheticationName() {
+        Authentication authentication = CdmStore.getCurrentAuthentiation();
+        if (authentication != null) {
+            return authentication.getName();
+        }
+        return null;
+    }
+
+    /**
+     * @return most probably a Cdm User instance or null
+     */
+    private Object getCurrentAutheticationPrincipal() {
+        Authentication authentication = CdmStore.getCurrentAuthentiation();
+        if (authentication != null) {
+            return authentication.getPrincipal();
+        }
+        return null;
+    }
+
+
+    /*
         * TODO refactor into User once Role is a model class
         */
        private List<Role> getCurrentAuthenticationsRoles() {
@@ -92,7 +124,8 @@ public class RolesSourceProvider extends AbstractSourceProvider implements Obser
 
        }
 
-       public String[] getProvidedSourceNames() {
+       @Override
+    public String[] getProvidedSourceNames() {
                return PROVIDED_SOURCE_NAMES;
        }
 
index 01ded5e282b0873b6f2c26d532dc7b30cc1c9094..11f5c06a03696d85cae69b70518cce6d88e3de9a 100644 (file)
@@ -41,6 +41,7 @@ import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.io.ExportManager;
 import eu.etaxonomy.taxeditor.io.ImportManager;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
 import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
@@ -98,14 +99,14 @@ public class CdmStore {
                        return instance;
                } else if (instance == null || !instance.isConnected) {
 
-                       StoreUtil
+                       AbstractUtility
                                        .warningDialog(
                                                        "Application is not connected to a datastore",
                                                        instance,
                                                        "The requested operation is only available when "
-                                                                       + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
+                                                       + "connected to a datasource. You may choose a datasource to connect to or create a new one in the datasource view.");
 
-                       StoreUtil.showView(CdmDataSourceViewPart.ID);
+                       AbstractUtility.showView(CdmDataSourceViewPart.ID);
 
                }
 
@@ -388,9 +389,7 @@ public class CdmStore {
         */
 
        /**
-        * <p>
-        * getDefaultLanguage
-        * </p>
+        * Provides access to the global default language set in the application preferences.
         *
         * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
         */