← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20074: add two new classes: SecurityContextRunnable which runs a thread in users security context and No...

 

------------------------------------------------------------
revno: 20074
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-10 17:22:46 +0700
message:
  add two new classes: SecurityContextRunnable which runs a thread in users security context and NoSecurityContextRunnable which make sure that the security contect is always cleared out before running, updated task classes to use this
added:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/NoSecurityContextRunnable.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityContextRunnable.java
modified:
  dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/scheduling/AnalyticsTableTask.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventsTask.java
  dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataGmlTask.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/scheduling/AnalyticsTableTask.java'
--- dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/scheduling/AnalyticsTableTask.java	2015-07-15 06:49:50 +0000
+++ dhis-2/dhis-services/dhis-service-analytics/src/main/java/org/hisp/dhis/analytics/table/scheduling/AnalyticsTableTask.java	2015-09-10 10:22:46 +0000
@@ -28,73 +28,77 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.hisp.dhis.setting.SystemSettingManager.KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE;
-import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
-import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
-import static org.hisp.dhis.setting.SystemSettingManager.KEY_APPLICATION_TITLE;
-import java.util.Date;
-import javax.annotation.Resource;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.analytics.AnalyticsTableService;
 import org.hisp.dhis.commons.util.Clock;
 import org.hisp.dhis.commons.util.DebugUtils;
+import org.hisp.dhis.commons.util.TextUtils;
 import org.hisp.dhis.message.MessageService;
 import org.hisp.dhis.scheduling.TaskId;
+import org.hisp.dhis.security.NoSecurityContextRunnable;
 import org.hisp.dhis.setting.SystemSettingManager;
 import org.hisp.dhis.system.notification.Notifier;
-import org.hisp.dhis.commons.util.TextUtils;
+import org.hisp.dhis.user.CurrentUserService;
 import org.joda.time.DateTime;
 import org.springframework.beans.factory.annotation.Autowired;
 
+import javax.annotation.Resource;
+import java.util.Date;
+
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_APPLICATION_TITLE;
+import static org.hisp.dhis.setting.SystemSettingManager.KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE;
+import static org.hisp.dhis.system.notification.NotificationLevel.ERROR;
+import static org.hisp.dhis.system.notification.NotificationLevel.INFO;
+
 /**
  * @author Lars Helge Overland
  */
 public class AnalyticsTableTask
-    implements Runnable
+    extends NoSecurityContextRunnable
 {
     private static final Log log = LogFactory.getLog( AnalyticsTableTask.class );
-    
-    @Resource(name="org.hisp.dhis.analytics.AnalyticsTableService")
+
+    @Resource( name = "org.hisp.dhis.analytics.AnalyticsTableService" )
     private AnalyticsTableService analyticsTableService;
 
-    @Resource(name="org.hisp.dhis.analytics.CompletenessTableService")
+    @Resource( name = "org.hisp.dhis.analytics.CompletenessTableService" )
     private AnalyticsTableService completenessTableService;
-    
-    @Resource(name="org.hisp.dhis.analytics.CompletenessTargetTableService")
+
+    @Resource( name = "org.hisp.dhis.analytics.CompletenessTargetTableService" )
     private AnalyticsTableService completenessTargetTableService;
-    
-    @Resource(name="org.hisp.dhis.analytics.OrgUnitTargetTableService")
+
+    @Resource( name = "org.hisp.dhis.analytics.OrgUnitTargetTableService" )
     private AnalyticsTableService orgUnitTargetTableService;
-    
-    @Resource(name="org.hisp.dhis.analytics.EventAnalyticsTableService")
+
+    @Resource( name = "org.hisp.dhis.analytics.EventAnalyticsTableService" )
     private AnalyticsTableService eventAnalyticsTableService;
-    
+
     @Autowired
     private Notifier notifier;
-    
+
     @Autowired
     private MessageService messageService;
 
     @Autowired
     private SystemSettingManager systemSettingManager;
-    
+
     private Integer lastYears;
 
     public void setLastYears( Integer lastYears )
     {
         this.lastYears = lastYears;
     }
-    
+
     private boolean skipResourceTables = false;
 
     public void setSkipResourceTables( boolean skipResourceTables )
     {
         this.skipResourceTables = skipResourceTables;
     }
-    
+
     private boolean skipAggregate = false;
-    
+
     public void setSkipAggregate( boolean skipAggregate )
     {
         this.skipAggregate = skipAggregate;
@@ -119,11 +123,11 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void run()
+    public void call()
     {
         final Date startTime = new Date();
         final Clock clock = new Clock( log ).startClock();
-        
+
         notifier.clear( taskId ).notify( taskId, "Analytics table update process started" );
 
         try
@@ -131,49 +135,49 @@
             if ( !skipResourceTables )
             {
                 notifier.notify( taskId, "Updating resource tables" );
-                analyticsTableService.generateResourceTables();    
+                analyticsTableService.generateResourceTables();
             }
-            
+
             if ( !skipAggregate )
             {
                 notifier.notify( taskId, "Updating analytics tables" );
                 analyticsTableService.update( lastYears, taskId );
 
                 notifier.notify( taskId, "Updating completeness table" );
-                completenessTableService.update( lastYears, taskId );    
+                completenessTableService.update( lastYears, taskId );
 
                 notifier.notify( taskId, "Updating completeness target table" );
-                completenessTargetTableService.update( lastYears, taskId );      
+                completenessTargetTableService.update( lastYears, taskId );
 
-                notifier.notify( taskId, "Updating organisation unit target table" );                
-                orgUnitTargetTableService.update( lastYears, taskId );        
+                notifier.notify( taskId, "Updating organisation unit target table" );
+                orgUnitTargetTableService.update( lastYears, taskId );
             }
-            
+
             if ( !skipEvents )
             {
-                notifier.notify( taskId, "Updating event analytics table" );  
+                notifier.notify( taskId, "Updating event analytics table" );
                 eventAnalyticsTableService.update( lastYears, taskId );
             }
-            
+
             clock.logTime( "Analytics tables updated" );
             notifier.notify( taskId, INFO, "Analytics tables updated: " + clock.time(), true );
         }
         catch ( RuntimeException ex )
         {
             String appTitle = (String) systemSettingManager.getSystemSetting( KEY_APPLICATION_TITLE, TextUtils.EMPTY );
-            
+
             notifier.notify( taskId, ERROR, "Process failed: " + ex.getMessage(), true );
-            
-            messageService.sendSystemNotification( 
+
+            messageService.sendSystemNotification(
                 "Analytics table process failed",
                 "Analytics table process failed, please check the logs. Time: " + new DateTime().toString() + ". " +
-                "Application title: " + appTitle + " " +
-                "Message: " + ex.getMessage() + " " +
-                "Cause: " + DebugUtils.getStackTrace( ex.getCause() ) );
-            
+                    "Application title: " + appTitle + " " +
+                    "Message: " + ex.getMessage() + " " +
+                    "Cause: " + DebugUtils.getStackTrace( ex.getCause() ) );
+
             throw ex;
         }
-        
+
         systemSettingManager.saveSystemSetting( KEY_LAST_SUCCESSFUL_ANALYTICS_TABLES_UPDATE, startTime );
     }
 }

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/NoSecurityContextRunnable.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/NoSecurityContextRunnable.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/NoSecurityContextRunnable.java	2015-09-10 10:22:46 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.security;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/**
+ * Implementation of a runnable that makes sure the thread is run without
+ * any security context (user = null). Useful for cases where you want to have
+ * access to all objects without the user flag interfering.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public abstract class NoSecurityContextRunnable
+    implements Runnable
+{
+    @Override
+    final public void run()
+    {
+        SecurityContextHolder.clearContext();
+        call();
+    }
+
+    public abstract void call();
+}

=== added file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityContextRunnable.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityContextRunnable.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/security/SecurityContextRunnable.java	2015-09-10 10:22:46 +0000
@@ -0,0 +1,65 @@
+package org.hisp.dhis.security;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.springframework.security.core.context.SecurityContext;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+/**
+ * Implementation of a runnable that makes sure the thread is run in the same
+ * security context as the creator, you must implement the call method.
+ *
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public abstract class SecurityContextRunnable
+    implements Runnable
+{
+    private final SecurityContext securityContext;
+
+    public SecurityContextRunnable()
+    {
+        this.securityContext = SecurityContextHolder.getContext();
+    }
+
+    @Override
+    final public void run()
+    {
+        try
+        {
+            SecurityContextHolder.setContext( securityContext );
+            call();
+        }
+        finally
+        {
+            SecurityContextHolder.clearContext();
+        }
+    }
+
+    public abstract void call();
+}

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java	2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventTask.java	2015-09-10 10:22:46 +0000
@@ -28,10 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -40,7 +39,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportEventTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private final InputStream inputStream;
 
@@ -52,8 +51,6 @@
 
     private final boolean jsonInput;
 
-    private final Authentication authentication;
-
     public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, boolean jsonInput )
     {
         this.inputStream = inputStream;
@@ -61,14 +58,11 @@
         this.importOptions = importOptions;
         this.taskId = taskId;
         this.jsonInput = jsonInput;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
     }
 
     @Override
-    public void run()
+    public void call()
     {
-        SecurityContextHolder.getContext().setAuthentication( authentication );
-
         if ( jsonInput )
         {
             try

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventsTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventsTask.java	2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/ImportEventsTask.java	2015-09-10 10:22:46 +0000
@@ -28,10 +28,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.util.List;
 
@@ -39,7 +38,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportEventsTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private final List<Event> events;
 
@@ -49,21 +48,18 @@
 
     private final TaskId taskId;
 
-    private final Authentication authentication;
-
     public ImportEventsTask( List<Event> events, EventService eventService, ImportOptions importOptions, TaskId taskId )
     {
+        super();
         this.events = events;
         this.eventService = eventService;
         this.importOptions = importOptions;
         this.taskId = taskId;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
     }
 
     @Override
-    public void run()
+    public void call()
     {
-        SecurityContextHolder.getContext().setAuthentication( authentication );
         eventService.addEvents( events, importOptions, taskId );
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java	2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java	2015-09-10 10:22:46 +0000
@@ -28,18 +28,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportMetaDataTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private String userUid;
 
@@ -51,22 +50,19 @@
 
     private final MetaData metaData;
 
-    private final Authentication authentication;
-
     public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, TaskId taskId, MetaData metaData )
     {
+        super();
         this.userUid = userUid;
         this.importService = importService;
         this.importOptions = importOptions;
         this.taskId = taskId;
         this.metaData = metaData;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
     }
 
     @Override
-    public void run()
+    public void call()
     {
-        SecurityContextHolder.getContext().setAuthentication( authentication );
         importService.importMetaData( userUid, metaData, importOptions, taskId );
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java	2015-02-17 06:00:52 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java	2015-09-10 10:22:46 +0000
@@ -28,11 +28,10 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.security.SecurityContextRunnable;
+import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
-import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.io.InputStream;
 
@@ -40,7 +39,7 @@
  * @author Lars Helge Overland
  */
 public class ImportDataValueTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     public static final String FORMAT_XML = "xml";
     public static final String FORMAT_JSON = "json";
@@ -57,8 +56,6 @@
 
     private final String format;
 
-    private final Authentication authentication;
-
     public ImportDataValueTask( DataValueSetService dataValueSetService, InputStream inputStream, ImportOptions options, TaskId taskId, String format )
     {
         this.dataValueSetService = dataValueSetService;
@@ -66,14 +63,11 @@
         this.options = options;
         this.taskId = taskId;
         this.format = format;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
     }
 
     @Override
-    public void run()
+    public void call()
     {
-        SecurityContextHolder.getContext().setAuthentication( authentication );
-
         if ( FORMAT_JSON.equals( format ) )
         {
             dataValueSetService.saveDataValueSetJson( inputStream, options, taskId );

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java	2015-03-27 11:01:54 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataCsvTask.java	2015-09-10 10:22:46 +0000
@@ -28,30 +28,31 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.io.IOException;
-import java.io.InputStream;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject;
+import org.hisp.dhis.security.SecurityContextRunnable;
+import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.csv.CsvImportService;
-import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.scheduling.TaskId;
 
+import java.io.IOException;
+import java.io.InputStream;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportMetaDataCsvTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private static final Log log = LogFactory.getLog( ImportMetaDataTask.class );
 
     private ImportService importService;
-    
+
     private CsvImportService csvImportService;
-    
+
     private ImportOptions importOptions;
 
     private InputStream inputStream;
@@ -59,14 +60,15 @@
     private TaskId taskId;
 
     private String userUid;
-    
+
     private Class<? extends IdentifiableObject> clazz;
 
-    public ImportMetaDataCsvTask( String userUid, ImportService importService, 
+    public ImportMetaDataCsvTask( String userUid, ImportService importService,
         CsvImportService csvImportService,
         ImportOptions importOptions, InputStream inputStream,
         TaskId taskId, Class<? extends IdentifiableObject> clazz )
     {
+        super();
         this.userUid = userUid;
         this.importService = importService;
         this.csvImportService = csvImportService;
@@ -81,9 +83,9 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void run()
+    public void call()
     {
-        MetaData metaData = null;
+        MetaData metaData;
 
         try
         {

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataGmlTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataGmlTask.java	2015-08-30 17:07:42 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataGmlTask.java	2015-09-10 10:22:46 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.gml.GmlImportService;
 import org.hisp.dhis.importexport.ImportStrategy;
@@ -39,7 +40,7 @@
  * @author Halvdan Hoem Grelland
  */
 public class ImportMetaDataGmlTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private TaskId taskId;
 
@@ -62,6 +63,7 @@
     public ImportMetaDataGmlTask( String userUid, GmlImportService gmlImportService,
         ImportOptions importOptions, InputStream inputStream, TaskId taskId )
     {
+        super();
         this.userUid = userUid;
         this.gmlImportService = gmlImportService;
         this.importOptions = importOptions;
@@ -74,7 +76,7 @@
     // -------------------------------------------------------------------------
 
     @Override
-    public void run()
+    public void call()
     {
         importOptions.setImportStrategy( ImportStrategy.UPDATE );
         gmlImportService.importGml( inputStream, userUid, importOptions, taskId );

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2015-09-10 08:59:49 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportMetaDataTask.java	2015-09-10 10:22:46 +0000
@@ -30,14 +30,13 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.security.SecurityContextRunnable;
 import org.hisp.dhis.commons.util.DebugUtils;
 import org.hisp.dhis.dxf2.common.ImportOptions;
 import org.hisp.dhis.dxf2.common.JacksonUtils;
 import org.hisp.dhis.dxf2.metadata.ImportService;
 import org.hisp.dhis.dxf2.metadata.MetaData;
 import org.hisp.dhis.scheduling.TaskId;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.context.SecurityContextHolder;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -46,7 +45,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 public class ImportMetaDataTask
-    implements Runnable
+    extends SecurityContextRunnable
 {
     private static final Log log = LogFactory.getLog( ImportMetaDataTask.class );
 
@@ -62,25 +61,22 @@
 
     private String format;
 
-    private final Authentication authentication;
-
     public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions,
         InputStream inputStream, TaskId taskId, String format )
     {
+        super();
         this.userUid = userUid;
         this.importService = importService;
         this.importOptions = importOptions;
         this.inputStream = inputStream;
         this.taskId = taskId;
         this.format = format;
-        this.authentication = SecurityContextHolder.getContext().getAuthentication();
     }
 
     @Override
-    public void run()
+    public void call()
     {
-        SecurityContextHolder.getContext().setAuthentication( authentication );
-        MetaData metaData = null;
+        MetaData metaData;
 
         try
         {