catching PermissionDeniedExceptions when only doing a check, so these exceptions...
authorAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 13 Mar 2014 12:39:49 +0000 (12:39 +0000)
committerAndreas Kohlbecker <a.kohlbecker@bgbm.org>
Thu, 13 Mar 2014 12:39:49 +0000 (12:39 +0000)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java

index 83c558e1ab0f1444346b8413e487c504a6fb4459..06c791ca1b1b898b92b013ef0ce9db56c57a5bcc 100644 (file)
@@ -1,8 +1,8 @@
 /**
  * Copyright (C) 2007 EDIT
- * European Distributed Institute of Taxonomy 
+ * 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.
  */
@@ -34,7 +34,6 @@ import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
-import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionEvaluator;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
 import eu.etaxonomy.cdm.persistence.hibernate.permission.Role;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
@@ -48,10 +47,10 @@ import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart;
  * This implementation of ICdmDataRepository depends on hibernate sessions to
  * store the data correctly for the current session. No state is held in this
  * class.
- * 
+ *
  * Only methods that either get or manipulate data are exposed here. So this
  * class acts as a facade for the methods in cdmlib-service.
- * 
+ *
  * @author n.hoffmann
  * @created 17.03.2009
  * @version 1.0
@@ -89,7 +88,7 @@ public class CdmStore {
         * <p>
         * getDefault
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.taxeditor.store.CdmStore} object.
         */
        protected static CdmStore getDefault() {
@@ -124,7 +123,7 @@ public class CdmStore {
 
        /**
         * Initialize with a specific datasource
-        * 
+        *
         * @param datasource
         *            a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
         */
@@ -135,7 +134,7 @@ public class CdmStore {
 
        /**
         * Initialize and provide
-        * 
+        *
         * @param datasource
         * @param dbSchemaValidation
         * @param applicationContextBean
@@ -159,7 +158,7 @@ public class CdmStore {
 
        /**
         * Closes the current application context
-        * 
+        *
         * @param monitor
         *            a {@link org.eclipse.core.runtime.IProgressMonitor} object.
         */
@@ -167,7 +166,7 @@ public class CdmStore {
                Display.getDefault().asyncExec(new Runnable() {
                        /*
                         * (non-Javadoc)
-                        * 
+                        *
                         * @see java.lang.Runnable#run()
                         */
                        @Override
@@ -200,7 +199,7 @@ public class CdmStore {
 
        /**
         * All calls to the datastore require
-        * 
+        *
         * @return
         */
        private ICdmApplicationConfiguration getApplicationConfiguration() {
@@ -216,7 +215,7 @@ public class CdmStore {
         * <p>
         * getCurrentApplicationController
         * </p>
-        * 
+        *
         * @return a
         *         {@link eu.etaxonomy.cdm.remote.api.application.CdmApplicationController}
         *         object.
@@ -235,7 +234,7 @@ public class CdmStore {
        /**
         * Creates a new conversation, binds resources to the conversation and start
         * a transaction for this conversation.
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder}
         *         object.
         */
@@ -252,9 +251,9 @@ public class CdmStore {
 
        /**
         * Generic method that will scan the getters of {@link ICdmApplicationConfiguration} for the given service
-        * interface. If a matching getter is found the according service implementation is returned by 
-        * invoking the getter otherwise the method returns <code>null</code>. 
-        * 
+        * interface. If a matching getter is found the according service implementation is returned by
+        * invoking the getter otherwise the method returns <code>null</code>.
+        *
         * @param <T>
         * @param serviceClass
         * @return the configured implementation of <code>serviceClass</code> or <code>null</code>
@@ -290,7 +289,7 @@ public class CdmStore {
         * <p>
         * getAuthenticationManager
         * </p>
-        * 
+        *
         * @return a
         *         {@link org.springframework.security.authentication.ProviderManager}
         *         object.
@@ -298,12 +297,12 @@ public class CdmStore {
        public static ProviderManager getAuthenticationManager() {
                return getCurrentApplicationConfiguration().getAuthenticationManager();
        }
-       
+
        /**
         * <p>
         * getAuthenticationManager
         * </p>
-        * 
+        *
         * @return a
         *         {@link ICdmPermissionEvaluator} object.
         */
@@ -315,52 +314,71 @@ public class CdmStore {
         * <p>
         * getGeoService
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.ext.geo.IEditGeoService} object.
         */
        public static IEditGeoService getGeoService() {
                return (IEditGeoService) getCurrentApplicationConfiguration().getBean(
                                "editGeoService");
        }
-       
+
        /*
         * SECURITY RELATED CONVENIENCE METHODS
         */
-       
+
        /**
         * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
      *
         * @param targetDomainObject
-        * @param permission 
+        * @param permission
         * @return
         */
        public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
                //TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
                SecurityContext context = SecurityContextHolder.getContext();
                PermissionEvaluator pe = getPermissionEvaluator();
-               return getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject, permission);
+               boolean hasPermission = false;
+               try {
+            hasPermission = getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject,
+                    permission);
+        } catch (org.springframework.security.access.AccessDeniedException e) {
+            /* IGNORE */
+        }
+        return hasPermission;
        }
 
        /**
         * @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, java.lang.Object, java.lang.Object)
      *
         * @param targetDomainObject
-        * @param permission 
+        * @param permission
         * @return
         */
        public static boolean currentAuthentiationHasPermission(Class<? extends CdmBase> targetType, EnumSet<CRUD> permission){
-               return getPermissionEvaluator().hasPermission(getCurrentAuthentiation(), null, targetType.getName(), permission);
+           boolean hasPermission = false;
+        try {
+            hasPermission = getPermissionEvaluator().hasPermission(getCurrentAuthentiation(), null, targetType.getName(), permission);
+        } catch (org.springframework.security.access.AccessDeniedException e) {
+            /* IGNORE */
+        }
+        return hasPermission;
        }
-       
+
        public static boolean currentAuthentiationHasOneOfRoles(Role ... roles){
-               return getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
+           boolean hasPermission = false;
+        try {
+            hasPermission =  getPermissionEvaluator().hasOneOfRoles(getCurrentAuthentiation(), roles);
+        } catch (org.springframework.security.access.AccessDeniedException e) {
+            /* IGNORE */
+        }
+        return hasPermission;
        }
-       
+
        public static Authentication getCurrentAuthentiation() {
                SecurityContext context = SecurityContextHolder.getContext();
                return context.getAuthentication();
        }
-       
+
        /*
         * LANGUAGE
         */
@@ -369,7 +387,7 @@ public class CdmStore {
         * <p>
         * getDefaultLanguage
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.model.common.Language} object.
         */
        public static Language getDefaultLanguage() {
@@ -383,7 +401,7 @@ public class CdmStore {
         * <p>
         * setDefaultLanguage
         * </p>
-        * 
+        *
         * @param language
         *            a {@link eu.etaxonomy.cdm.model.common.Language} object.
         */
@@ -414,7 +432,7 @@ public class CdmStore {
         * <p>
         * Getter for the field <code>loginManager</code>.
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.taxeditor.store.LoginManager} object.
         */
        public static LoginManager getLoginManager() {
@@ -425,7 +443,7 @@ public class CdmStore {
         * <p>
         * Getter for the field <code>contextManager</code>.
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.taxeditor.store.ContextManager} object.
         */
        public static ContextManager getContextManager() {
@@ -452,7 +470,7 @@ public class CdmStore {
         * <p>
         * Getter for the field <code>importHandler</code>.
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.taxeditor.io.ImportManager} object.
         */
        public static ImportManager getImportManager() {
@@ -463,7 +481,7 @@ public class CdmStore {
         * <p>
         * Getter for the field <code>exportHandler</code>.
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.taxeditor.io.ExportManager} object.
         */
        public static ExportManager getExportManager() {
@@ -472,7 +490,7 @@ public class CdmStore {
 
        /**
         * Whether this CdmStore is currently connected to a datasource
-        * 
+        *
         * @return a boolean.
         */
        public static boolean isActive() {
@@ -483,7 +501,7 @@ public class CdmStore {
         * <p>
         * getDataSource
         * </p>
-        * 
+        *
         * @return a {@link eu.etaxonomy.cdm.database.ICdmDataSource} object.
         */
        public static ICdmDataSource getDataSource() {