dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #39628
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20073: properly set user security context when doing imports through UI
------------------------------------------------------------
revno: 20073
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2015-09-10 15:59:49 +0700
message:
properly set user security context when doing imports through UI
modified:
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-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-06-15 13:44:20 +0000
+++ 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
@@ -30,12 +30,14 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+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.dxf2.common.JacksonUtils;
import org.hisp.dhis.scheduling.TaskId;
-import org.hisp.dhis.commons.util.DebugUtils;
+import org.springframework.security.core.Authentication;
+import org.springframework.security.core.context.SecurityContextHolder;
import java.io.IOException;
import java.io.InputStream;
@@ -60,7 +62,9 @@
private String format;
- public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions,
+ private final Authentication authentication;
+
+ public ImportMetaDataTask( String userUid, ImportService importService, ImportOptions importOptions,
InputStream inputStream, TaskId taskId, String format )
{
this.userUid = userUid;
@@ -69,11 +73,13 @@
this.inputStream = inputStream;
this.taskId = taskId;
this.format = format;
+ this.authentication = SecurityContextHolder.getContext().getAuthentication();
}
@Override
public void run()
{
+ SecurityContextHolder.getContext().setAuthentication( authentication );
MetaData metaData = null;
try
@@ -90,7 +96,7 @@
catch ( IOException ex )
{
log.error( DebugUtils.getStackTrace( ex ) );
-
+
throw new RuntimeException( "Failed to parse meta data input stream", ex );
}