Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 33681)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/CadastreInterface.java	(revision 33682)
@@ -43,4 +43,5 @@
     private HttpURLConnection urlConn;
 
+    private String csrfToken;
     private String cookie;
     private String interfaceRef;
@@ -72,9 +73,12 @@
     static final String C_INTERFACE_VECTOR = "afficherCarteCommune.do";
     static final String C_INTERFACE_RASTER_TA = "afficherCarteTa.do";
-    static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do";
-    static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteFeuille.do?f=";
-    static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?f=";
+    static final String C_INTERFACE_RASTER_FEUILLE = "afficherCarteFeuille.do?CSRF_TOKEN=";
+    static final String C_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('" + C_INTERFACE_RASTER_FEUILLE;
+    static final String C_TA_IMAGE_LINK_START = "<a href=\"#\" class=\"raster\" onClick=\"popup('afficherCarteTa.do?CSRF_TOKEN=";
     static final String C_IMAGE_NAME_START = ">Feuille ";
     static final String C_TA_IMAGE_NAME_START = "Tableau d'assemblage <strong>";
+
+    static final String C_CSRF_TOKEN = "CSRF_TOKEN=";
+    static final String C_F = "&amp;f=";
 
     static final long COOKIE_EXPIRATION = 30 * 60 * 1000L; // 30 minutes expressed in milliseconds
@@ -100,6 +104,6 @@
                 throw new WMSException(tr("Cannot open a new client session.\nServer in maintenance or temporary overloaded."));
             if (interfaceRef == null) {
-                    getInterface(wmsLayer);
-                    this.lastWMSLayerName = wmsLayer.getName();
+                getInterface(wmsLayer);
+                this.lastWMSLayerName = wmsLayer.getName();
             }
             openInterface();
@@ -237,5 +241,5 @@
                         wmsLayer.setCodeCommune(listOfFeuilles.get(res).name);
                         checkLayerDuplicates(wmsLayer);
-                        interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
+                        interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune(), csrfToken);
                     }
                 }
@@ -334,12 +338,17 @@
             urlConn.disconnect();
             if (lines != null) {
-                if (lines.indexOf(C_IMAGE_FORMAT) != -1) {
-                    int i = lines.indexOf(C_IMAGE_FORMAT);
-                    int j = lines.indexOf('.', i);
-                    wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), j)));
-                }
-                if (!wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_VECTOR) != -1) {  // "afficherCarteCommune.do"
+                int i = lines.indexOf(C_IMAGE_FORMAT);
+                if (i > -1) {
+                    wmsLayer.setRaster("image".equals(lines.substring(i+C_IMAGE_FORMAT.length(), lines.indexOf('.', i))));
+                }
+                csrfToken = null;
+                i = lines.indexOf(C_CSRF_TOKEN);
+                if (i > -1) {
+                    csrfToken = lines.substring(i+C_CSRF_TOKEN.length(), Math.min(lines.indexOf('"', i), lines.indexOf('&', i)));
+                }
+                i = lines.indexOf(C_INTERFACE_VECTOR);
+                if (!wmsLayer.isRaster() && i != -1) {  // "afficherCarteCommune.do"
                     // shall be something like: interfaceRef = "afficherCarteCommune.do?c=X2269";
-                    lines = lines.substring(lines.indexOf(C_INTERFACE_VECTOR), lines.length());
+                    lines = lines.substring(i, lines.length());
                     lines = lines.substring(0, lines.indexOf('\''));
                     lines = Entities.unescape(lines);
@@ -348,7 +357,7 @@
                 } else if (wmsLayer.isRaster() && lines.indexOf(C_INTERFACE_RASTER_TA) != -1) { // "afficherCarteTa.do"
                     // list of values parsed in listOfFeuilles (list all non-georeferenced images)
-                    lines = getFeuillesList();
+                    lines = getFeuillesList(csrfToken);
                     if (!downloadCanceled) {
-                        parseFeuillesList(lines);
+                        parseFeuillesList(lines, csrfToken);
                         if (!listOfFeuilles.isEmpty()) {
                             int res = selectFeuilleDialog();
@@ -356,7 +365,7 @@
                                 wmsLayer.setCodeCommune(listOfFeuilles.get(res).name);
                                 checkLayerDuplicates(wmsLayer);
-                                interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune());
+                                interfaceRef = buildRasterFeuilleInterfaceRef(wmsLayer.getCodeCommune(), csrfToken);
                                 wmsLayer.setCodeCommune(listOfFeuilles.get(res).ref);
-                                lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref);
+                                lines = buildRasterFeuilleInterfaceRef(listOfFeuilles.get(res).ref, csrfToken);
                                 lines = Entities.unescape(lines);
                                 Logging.info("interface ref.:"+lines);
@@ -368,7 +377,6 @@
                 } else if (lines.indexOf(C_COMMUNE_LIST_START) != -1 && lines.indexOf(C_COMMUNE_LIST_END) != -1) {
                     // list of values parsed in listOfCommunes
-                    int i = lines.indexOf(C_COMMUNE_LIST_START);
-                    int j = lines.indexOf(C_COMMUNE_LIST_END, i);
-                    parseCommuneList(lines.substring(i, j));
+                    i = lines.indexOf(C_COMMUNE_LIST_START);
+                    parseCommuneList(lines.substring(i, lines.indexOf(C_COMMUNE_LIST_END, i)));
                 }
             }
@@ -400,5 +408,5 @@
     }
 
-    private String getFeuillesList() {
+    private String getFeuillesList(String csrfToken) {
         // get all images in one html page
         String ln = null;
@@ -406,5 +414,6 @@
         HttpURLConnection urlConn2 = null;
         try {
-            URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?keepVolatileSession=&offset=2000");
+            URL getAllImagesURL = new URL(BASE_URL + "/scpc/listerFeuillesParcommune.do?CSRF_TOKEN=" +
+                    csrfToken + "&keepVolatileSession=&offset=2000");
             urlConn2 = (HttpURLConnection) getAllImagesURL.openConnection();
             setCookie(urlConn2);
@@ -424,5 +433,5 @@
     }
 
-    private void parseFeuillesList(String input) {
+    private void parseFeuillesList(String input, String csrfToken) {
         listOfFeuilles.clear();
         // get "Tableau d'assemblage"
@@ -430,5 +439,6 @@
         if (Main.pref.getBoolean("cadastrewms.useTA", false)) {
             while (inputTA.indexOf(C_TA_IMAGE_LINK_START) != -1) {
-                inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length());
+                inputTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_LINK_START) + C_TA_IMAGE_LINK_START.length()
+                    + csrfToken.length() + C_F.length());
                 String refTA = inputTA.substring(0, inputTA.indexOf('\''));
                 String nameTA = inputTA.substring(inputTA.indexOf(C_TA_IMAGE_NAME_START) + C_TA_IMAGE_NAME_START.length());
@@ -439,5 +449,6 @@
         // get "Feuilles"
         while (input.indexOf(C_IMAGE_LINK_START) != -1) {
-            input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length());
+            input = input.substring(input.indexOf(C_IMAGE_LINK_START)+C_IMAGE_LINK_START.length()
+                + csrfToken.length() + C_F.length());
             String refFeuille = input.substring(0, input.indexOf('\''));
             String nameFeuille = input.substring(
@@ -449,44 +460,48 @@
 
     private String selectMunicipalityDialog() {
-        JPanel p = new JPanel(new GridBagLayout());
-        String[] communeList = new String[listOfCommunes.size() + 1];
-        communeList[0] = tr("Choose from...");
-        for (int i = 0; i < listOfCommunes.size(); i++) {
-            communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1);
-        }
-        JComboBox<String> inputCommuneList = new JComboBox<>(communeList);
-        p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
-        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
-        // this below is a temporary workaround to fix the "always on top" issue
-        JDialog dialog = pane.createDialog(Main.parent, tr("Select commune"));
-        CadastrePlugin.prepareDialog(dialog);
-        dialog.setVisible(true);
-        // till here
-        if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
-            return null;
-        return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1);
+        return GuiHelper.runInEDTAndWaitAndReturn(() -> {
+            JPanel p = new JPanel(new GridBagLayout());
+            String[] communeList = new String[listOfCommunes.size() + 1];
+            communeList[0] = tr("Choose from...");
+            for (int i = 0; i < listOfCommunes.size(); i++) {
+                communeList[i + 1] = listOfCommunes.get(i).substring(listOfCommunes.get(i).indexOf('>')+1);
+            }
+            JComboBox<String> inputCommuneList = new JComboBox<>(communeList);
+            p.add(inputCommuneList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
+            JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
+            // this below is a temporary workaround to fix the "always on top" issue
+            JDialog dialog = pane.createDialog(Main.parent, tr("Select commune"));
+            CadastrePlugin.prepareDialog(dialog);
+            dialog.setVisible(true);
+            // till here
+            if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
+                return null;
+            return listOfCommunes.get(inputCommuneList.getSelectedIndex()-1);
+        });
     }
 
     private int selectFeuilleDialog() {
-        JPanel p = new JPanel(new GridBagLayout());
-        List<String> imageNames = new ArrayList<>();
-        for (PlanImage src : listOfFeuilles) {
-            imageNames.add(src.name);
-        }
-        JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{}));
-        p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
-        JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
-        // this below is a temporary workaround to fix the "always on top" issue
-        JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
-        CadastrePlugin.prepareDialog(dialog);
-        dialog.setVisible(true);
-        // till here
-        if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
-            return -1;
-        return inputFeuilleList.getSelectedIndex();
-    }
-
-    private static String buildRasterFeuilleInterfaceRef(String codeCommune) {
-        return C_INTERFACE_RASTER_FEUILLE + "?f=" + codeCommune;
+        return GuiHelper.runInEDTAndWaitAndReturn(() -> {
+            JPanel p = new JPanel(new GridBagLayout());
+            List<String> imageNames = new ArrayList<>();
+            for (PlanImage src : listOfFeuilles) {
+                imageNames.add(src.name);
+            }
+            JComboBox<String> inputFeuilleList = new JComboBox<>(imageNames.toArray(new String[]{}));
+            p.add(inputFeuilleList, GBC.eol().fill(GBC.HORIZONTAL).insets(10, 0, 0, 0));
+            JOptionPane pane = new JOptionPane(p, JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null);
+            // this below is a temporary workaround to fix the "always on top" issue
+            JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
+            CadastrePlugin.prepareDialog(dialog);
+            dialog.setVisible(true);
+            // till here
+            if (!Integer.valueOf(JOptionPane.OK_OPTION).equals(pane.getValue()))
+                return -1;
+            return inputFeuilleList.getSelectedIndex();
+        });
+    }
+
+    private static String buildRasterFeuilleInterfaceRef(String codeCommune, String csrfToken) {
+        return C_INTERFACE_RASTER_FEUILLE + csrfToken + "&f=" + codeCommune;
     }
 
@@ -497,4 +512,5 @@
      * and store the result in the wmsLayer as well.
      * @param wmsLayer the WMSLayer where the commune data and images are stored
+     * @throws IOException if any I/O error occurs
      */
     public void retrieveCommuneBBox(WMSLayer wmsLayer) throws IOException {
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java	(revision 33681)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/DownloadWMSVectorImage.java	(revision 33682)
@@ -13,4 +13,5 @@
 import org.openstreetmap.josm.gui.MapView;
 import org.openstreetmap.josm.gui.PleaseWaitRunnable;
+import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.tools.Logging;
 
@@ -44,6 +45,7 @@
                     if (wmsLayer.isRaster()) {
                         // set raster image commune bounding box based on current view (before adjustment)
-                        JOptionPane.showMessageDialog(Main.parent,
-                                tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\""));
+                        GuiHelper.runInEDT(() ->
+                            JOptionPane.showMessageDialog(Main.parent,
+                                tr("This commune is not vectorized.\nPlease use the other menu entry to georeference a \"Plan image\"")));
                         MainApplication.getLayerManager().removeLayer(wmsLayer);
                         wmsLayer = null;
Index: /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java
===================================================================
--- /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java	(revision 33681)
+++ /applications/editors/josm/plugins/cadastre-fr/src/org/openstreetmap/josm/plugins/fr/cadastre/wms/RasterImageGeoreferencer.java	(revision 33682)
@@ -19,4 +19,5 @@
 import org.openstreetmap.josm.data.coor.EastNorth;
 import org.openstreetmap.josm.gui.MainApplication;
+import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.tools.GBC;
 import org.openstreetmap.josm.tools.Logging;
@@ -46,6 +47,7 @@
     }
 
-    /**
+   /**
     *
+    * @param wmsLayer WMS layer
     * @return false if all operations are canceled
     */
@@ -57,9 +59,9 @@
        mouseClickedTime = System.currentTimeMillis();
        Object[] options = {"OK", "Cancel"};
-       int ret = JOptionPane.showOptionDialog(null,
+       int ret = GuiHelper.runInEDTAndWaitAndReturn(() -> JOptionPane.showOptionDialog(null,
                tr("Click first corner for image cropping\n(two points required)"),
                tr("Image cropping"),
                JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE,
-               null, options, options[0]);
+               null, options, options[0]));
        if (ret == JOptionPane.OK_OPTION) {
            mouseClickedTime = System.currentTimeMillis();
@@ -70,8 +72,8 @@
    }
 
-   /**
-    *
-    * @return false if all operations are canceled
-    */
+  /**
+   * @param wmsLayer WMS layer
+   * @return false if all operations are canceled
+   */
   public boolean startGeoreferencing(WMSLayer wmsLayer) {
       this.wmsLayer = wmsLayer;
