dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24340
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11914: set authentication principal on thread tasks
------------------------------------------------------------
revno: 11914
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-04 14:31:29 +0200
message:
set authentication principal on thread tasks
modified:
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.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-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java
dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.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-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java 2013-09-04 11:58:22 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/event/tasks/ImportEventTask.java 2013-09-04 12:31:29 +0000
@@ -32,6 +32,8 @@
import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.scheduling.TaskId;
import org.hisp.dhis.user.User;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
import java.io.IOException;
import java.io.InputStream;
@@ -50,23 +52,25 @@
private final TaskId taskId;
- private final User user;
-
private final boolean jsonInput;
- public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, User user, boolean jsonInput )
+ private final Authentication authentication;
+
+ public ImportEventTask( InputStream inputStream, EventService eventService, ImportOptions importOptions, TaskId taskId, boolean jsonInput )
{
this.inputStream = inputStream;
this.eventService = eventService;
this.importOptions = importOptions;
this.taskId = taskId;
- this.user = user;
this.jsonInput = jsonInput;
+ this.authentication = SecurityContextHolder.getContext().getAuthentication();
}
@Override
public void run()
{
+ SecurityContextHolder.getContext().setAuthentication( authentication );
+
if ( jsonInput )
{
try
=== 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 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/metadata/tasks/ImportMetaDataTask.java 2013-09-04 12:31:29 +0000
@@ -32,6 +32,8 @@
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>
@@ -41,13 +43,15 @@
{
private String userUid;
- private ImportService importService;
-
- private ImportOptions importOptions;
-
- private TaskId taskId;
-
- private MetaData metaData;
+ private final ImportService importService;
+
+ private final ImportOptions importOptions;
+
+ private final TaskId taskId;
+
+ private final MetaData metaData;
+
+ private final Authentication authentication;
public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions, TaskId taskId, MetaData metaData )
{
@@ -56,11 +60,13 @@
this.importOptions = importOptions;
this.taskId = taskId;
this.metaData = metaData;
+ this.authentication = SecurityContextHolder.getContext().getAuthentication();
}
@Override
public void run()
{
+ SecurityContextHolder.getContext().setAuthentication( authentication );
importService.importMetaData( userUid, metaData, importOptions, taskId );
}
}
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-04 11:58:22 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/EventController.java 2013-09-04 12:31:29 +0000
@@ -48,7 +48,6 @@
import org.hisp.dhis.system.scheduling.Scheduler;
import org.hisp.dhis.system.util.StreamUtils;
import org.hisp.dhis.user.CurrentUserService;
-import org.hisp.dhis.user.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.http.HttpStatus;
@@ -219,9 +218,8 @@
}
else
{
- User currentUser = currentUserService.getCurrentUser();
- TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUser );
- scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, currentUser, false ) );
+ TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser() );
+ scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, false ) );
response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.EVENT_IMPORT );
response.setStatus( HttpServletResponse.SC_NO_CONTENT );
}
@@ -252,9 +250,8 @@
}
else
{
- User currentUser = currentUserService.getCurrentUser();
- TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUser );
- scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, currentUser, true ) );
+ TaskId taskId = new TaskId( TaskCategory.EVENT_IMPORT, currentUserService.getCurrentUser() );
+ scheduler.executeTask( new ImportEventTask( inputStream, eventService, importOptions, taskId, true ) );
response.setHeader( "Location", ContextUtils.getRootPath( request ) + "/system/tasks/" + TaskCategory.EVENT_IMPORT );
response.setStatus( HttpServletResponse.SC_NO_CONTENT );
}
=== 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 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/java/org/hisp/dhis/importexport/action/util/ImportDataValueTask.java 2013-09-04 12:31:29 +0000
@@ -28,11 +28,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.InputStream;
-
import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
import org.hisp.dhis.dxf2.metadata.ImportOptions;
import org.hisp.dhis.scheduling.TaskId;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
+
+import java.io.InputStream;
/**
* @author Lars Helge Overland
@@ -45,34 +47,43 @@
public static final String FORMAT_PDF = "pdf";
private DataValueSetService dataValueSetService;
- private InputStream in;
- private ImportOptions options;
- private TaskId taskId;
- private String format;
-
- public ImportDataValueTask( DataValueSetService dataValueSetService, InputStream in, ImportOptions options, TaskId taskId, String format )
+
+ private InputStream inputStream;
+
+ private final ImportOptions options;
+
+ private final TaskId taskId;
+
+ private final String format;
+
+ private final Authentication authentication;
+
+ public ImportDataValueTask( DataValueSetService dataValueSetService, InputStream inputStream, ImportOptions options, TaskId taskId, String format )
{
this.dataValueSetService = dataValueSetService;
- this.in = in;
+ this.inputStream = inputStream;
this.options = options;
this.taskId = taskId;
this.format = format;
+ this.authentication = SecurityContextHolder.getContext().getAuthentication();
}
@Override
public void run()
{
+ SecurityContextHolder.getContext().setAuthentication( authentication );
+
if ( FORMAT_CSV.equals( format ) )
{
- dataValueSetService.saveDataValueSetCsv( in, options, taskId );
+ dataValueSetService.saveDataValueSetCsv( inputStream, options, taskId );
}
else if ( FORMAT_PDF.equals( format ) )
{
- dataValueSetService.saveDataValueSetPdf( in, options, taskId );
+ dataValueSetService.saveDataValueSetPdf( inputStream, options, taskId );
}
else
{
- dataValueSetService.saveDataValueSet( in, options, taskId );
+ dataValueSetService.saveDataValueSet( inputStream, options, taskId );
}
}
}