commit 63e1618b8369297463e60b470cfe9381f3000c42
Author: Andreas Kohlbecker <a.kohlbecker@bgbm.org>
Date:   Tue Sep 11 15:14:41 2012 +0000

    fixing  #3096 (visual response if a user is not granted to edit a specific part of the classification tree)

diff --git a/.gitattributes b/.gitattributes
index 7c4e0033f..64a73a9f4 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1205,6 +1205,7 @@ 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/RequiredPermissions.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
diff --git a/.gitignore b/.gitignore
index 71532edf7..202b0a502 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,6 +3,7 @@ eu.etaxonomy.taxeditor.application/.settings
 eu.etaxonomy.taxeditor.application/target
 eu.etaxonomy.taxeditor.bulkeditor/.settings
 eu.etaxonomy.taxeditor.bulkeditor/target
+eu.etaxonomy.taxeditor.cdmlib/.directory
 eu.etaxonomy.taxeditor.cdmlib/.settings
 eu.etaxonomy.taxeditor.cdmlib/cdmlib-*.jar
 eu.etaxonomy.taxeditor.cdmlib/cdmlib-*.zip
diff --git a/eu.etaxonomy.taxeditor.cdmlib/.classpath b/eu.etaxonomy.taxeditor.cdmlib/.classpath
index 02f3ef81e..415e6524b 100644
--- a/eu.etaxonomy.taxeditor.cdmlib/.classpath
+++ b/eu.etaxonomy.taxeditor.cdmlib/.classpath
@@ -93,7 +93,7 @@
 	<classpathentry exported="true" kind="lib" path="lib/spring-modules-cache-0.7.jar" sourcepath="lib/spring-modules-cache-0.7src.zip"/>
 	<classpathentry exported="true" kind="lib" path="lib/spring-modules-lucene-0.8a.jar" sourcepath="lib/spring-modules-lucene-0.8asrc.zip"/>
 	<classpathentry exported="true" kind="lib" path="lib/spring-security-config-3.0.5.RELEASE.jar"/>
-	<classpathentry exported="true" kind="lib" path="lib/spring-security-core-3.0.5.RELEASE.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/spring-security-core-3.0.5.RELEASE.jar" sourcepath="/home/andreas/.m2/repository/org/springframework/security/spring-security-core/3.0.5.RELEASE/spring-security-core-3.0.5.RELEASE-sources.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/wsdl4j-1.6.1.jar" sourcepath="lib/wsdl4j-1.6.1src.zip"/>
 	<classpathentry exported="true" kind="lib" path="lib/xalan-2.7.0.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/xercesImpl-2.7.1.jar"/>
@@ -117,12 +117,12 @@
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.0.13-SNAPSHOT-sources.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-model-3.0.13-SNAPSHOT.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.0.13-SNAPSHOT-sources.jar"/>
-	<classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.0.13-SNAPSHOT.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/cdmlib-persistence-3.0.13-SNAPSHOT.jar" sourcepath="lib/cdmlib-persistence-3.0.13-SNAPSHOT-sources.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.0.13-SNAPSHOT-sources.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-print-3.0.13-SNAPSHOT.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.0.13-SNAPSHOT-sources.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.0.13-SNAPSHOT.jar"/>
 	<classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.0.13-SNAPSHOT-sources.jar"/>
-	<classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.0.13-SNAPSHOT.jar"/>
+	<classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.0.13-SNAPSHOT.jar" sourcepath="lib/cdmlib-services-3.0.13-SNAPSHOT-sources.jar"/>
 	<classpathentry kind="output" path="bin"/>
 </classpath>
diff --git a/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
index 213d960c1..eec66e1dd 100644
--- a/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
+++ b/eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
@@ -383,6 +383,7 @@ Export-Package: com.google.api,
    org.hibernate.type,
    org.hibernate.event,
    eu.etaxonomy.cdm.model.common",
+ eu.etaxonomy.cdm.persistence.hibernate.permission,
  eu.etaxonomy.cdm.persistence.query;uses:="org.hibernate,org.hibernate.envers.query,org.hibernate.criterion",
  eu.etaxonomy.cdm.print,
  eu.etaxonomy.cdm.print.out,
diff --git a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java
index d0a823f4d..ca2a8eb05 100644
--- a/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java
+++ b/eu.etaxonomy.taxeditor.navigation/src/main/java/eu/etaxonomy/taxeditor/navigation/navigator/TaxonNodeLabelProvider.java
@@ -15,15 +15,24 @@ import org.eclipse.jface.viewers.ColumnLabelProvider;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.StyledString;
 import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
+import org.eclipse.jface.viewers.StyledString.Styler;
+import org.eclipse.swt.SWT;
 import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.TextStyle;
 import org.eclipse.ui.navigator.IDescriptionProvider;
 import org.hibernate.LazyInitializationException;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
+import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
 import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
+import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.security.RequiredPermissions;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 
 /**
  * <p>TaxonNodeLabelProvider class.</p>
@@ -35,6 +44,9 @@ import eu.etaxonomy.taxeditor.navigation.NavigationUtil;
 public class TaxonNodeLabelProvider extends ColumnLabelProvider 
 		implements ILabelProvider, IDescriptionProvider, IStyledLabelProvider {
 	
+
+	private Styler notGrantedStyler = null;
+	
 	/** {@inheritDoc} */
 	@Override
 	public Image getImage(Object element) {
@@ -84,6 +96,28 @@ public class TaxonNodeLabelProvider extends ColumnLabelProvider
 	 */
 	/** {@inheritDoc} */
 	public StyledString getStyledText(Object element) {
-		return new StyledString(getText(element));
+		// determine style base on  user grants
+		Styler styler = null;
+		if(!CdmStore.currentAuthentiationHasPermission((CdmBase)element, RequiredPermissions.TAXONNODE_EDIT)){
+			styler = getNotGrantedStyler();
+		} 
+		return new StyledString(getText(element), styler);
+		
+	}
+	
+	/**
+	 * @return
+	 */
+	private Styler getNotGrantedStyler() {
+		if (notGrantedStyler  == null) {
+			notGrantedStyler = new Styler() {
+				@Override
+				public void applyStyles(TextStyle textStyle) {
+					textStyle.underline = false;
+					textStyle.foreground = StoreUtil.getColor(Resources.COLOR_TEXT_DISABLED);
+				}
+			};
+		}
+		return notGrantedStyler;
 	}
 }
diff --git a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
index 4462122ea..fabb88353 100644
--- a/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
+++ b/eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
@@ -24,6 +24,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.preference.matching,
  eu.etaxonomy.taxeditor.preference.menu,
  eu.etaxonomy.taxeditor.preference.wizard,
+ eu.etaxonomy.taxeditor.security,
  eu.etaxonomy.taxeditor.store,
  eu.etaxonomy.taxeditor.store.internal,
  eu.etaxonomy.taxeditor.store.operations,
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RequiredPermissions.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RequiredPermissions.java
new file mode 100644
index 000000000..c09f1033f
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/security/RequiredPermissions.java
@@ -0,0 +1,23 @@
+/**
+ * 
+ */
+package eu.etaxonomy.taxeditor.security;
+
+import java.util.EnumSet;
+
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
+
+/**
+ * Provides the required permissions a user would need in order to view or edit a 
+ * specific cdm type.
+ * 
+ * @author andreas kohlbecker
+ *
+ */
+public class RequiredPermissions {
+	
+	public static final EnumSet<CRUD> TAXONNODE_EDIT = Operation.UPDATE;
+	
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
index fcada2099..5b9ed355d 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/store/CdmStore.java
@@ -12,13 +12,17 @@ package eu.etaxonomy.taxeditor.store;
 import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
+import java.util.EnumSet;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.core.runtime.jobs.Job;
 import org.eclipse.swt.widgets.Display;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
+import org.springframework.security.access.PermissionEvaluator;
 import org.springframework.security.authentication.ProviderManager;
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationController;
 import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
@@ -27,7 +31,10 @@ import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.database.DbSchemaValidation;
 import eu.etaxonomy.cdm.database.ICdmDataSource;
 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.Operation;
 import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
 import eu.etaxonomy.taxeditor.io.ExportManager;
 import eu.etaxonomy.taxeditor.io.ImportManager;
@@ -289,6 +296,18 @@ public class CdmStore {
 	public static ProviderManager getAuthenticationManager() {
 		return getCurrentApplicationConfiguration().getAuthenticationManager();
 	}
+	
+	/**
+	 * <p>
+	 * getAuthenticationManager
+	 * </p>
+	 * 
+	 * @return a
+	 *         {@link PermissionEvaluator} object.
+	 */
+	public static PermissionEvaluator getPermissionEvaluator() {
+		return getCurrentApplicationConfiguration().getPermissionEvaluator();
+	}
 
 	/**
 	 * <p>
@@ -301,6 +320,23 @@ public class CdmStore {
 		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 
+	 * @return
+	 */
+	public static boolean currentAuthentiationHasPermission(CdmBase targetDomainObject, EnumSet<CRUD> permission){
+		//TODO use getCurrentApplicationConfiguration().currentAuthentiationHasPermission(CdmBase targetDomainObject, Operation permission) instead
+		SecurityContext context = SecurityContextHolder.getContext();
+		return getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject, permission);
+	}
 
 	/*
 	 * LANGUAGE
