#5098 : Fix issue with authentication when using search bar
[taxeditor.git] / eu.etaxonomy.taxeditor.cdmlib / src / main / java / eu / etaxonomy / cdm / api / application / CdmApplicationState.java
index cf47b3cfce64fce2bf7da00713e2f6b4bbbac9e3..41f33d8196fd7a420fb9933f4897179e99a3620d 100644 (file)
@@ -13,9 +13,12 @@ import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
 import java.lang.reflect.Type;
 
+import org.springframework.security.core.context.SecurityContext;
+
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.ITestService;
+import eu.etaxonomy.taxeditor.service.ICachedCommonService;
 
 /**
  * @author cmathew
@@ -30,6 +33,9 @@ public class CdmApplicationState {
 
     private ICdmDataChangeService dataChangeService;
 
+    private SecurityContext securityContext;
+
+
     public static CdmApplicationState getInstance() {
         if(cdmApplicationState == null) {
             cdmApplicationState = new CdmApplicationState();
@@ -75,11 +81,43 @@ public class CdmApplicationState {
         getInstance().setDataChangeService(dataChangeService);
     }
 
+
+
+    /**
+     * @return the securityContext
+     */
+    public SecurityContext getSecurityContext() {
+        return securityContext;
+    }
+
+    /**
+     * @param securityContext the securityContext to set
+     */
+    public void setSecurityContext(SecurityContext securityContext) {
+        this.securityContext = securityContext;
+    }
+
+    /**
+     * @return the securityContext
+     */
+    public static SecurityContext getCurrentSecurityContext() {
+        return getInstance().getSecurityContext();
+    }
+
+    /**
+     * @param securityContext the securityContext to set
+     */
+    public static void setCurrentSecurityContext(SecurityContext securityContext) {
+        getInstance().setSecurityContext(securityContext);
+    }
+
     public static void dispose() {
         getInstance().setCurrentDataChangeService(null);
         getInstance().setAppConfig(null);
+        getInstance().setSecurityContext(null);
     }
 
+
     /**
      * 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
@@ -117,6 +155,7 @@ public class CdmApplicationState {
         return service;
     }
 
+
     /**
      * @see #getService(Class)
      * As ICommonService is not extending IService we need a specific request here
@@ -135,4 +174,11 @@ public class CdmApplicationState {
 
     }
 
+    public static ICachedCommonService getCachedCommonService() {
+        ICdmApplicationConfiguration configuration = getCurrentAppConfig();
+
+        return ((CdmApplicationRemoteController)configuration).getCachedCommonService();
+
+    }
+
 }