- Timestamp:
- 2017-12-25T18:08:44+01:00 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/remotecontrol/handler/RequestHandler.java
r12854 r13241 22 22 import org.openstreetmap.josm.spi.preferences.Config; 23 23 import org.openstreetmap.josm.tools.Logging; 24 import org.openstreetmap.josm.tools.Pair; 24 25 import org.openstreetmap.josm.tools.Utils; 25 26 … … 35 36 public static final String loadInNewLayerKey = "remotecontrol.new-layer"; 36 37 public static final boolean loadInNewLayerDefault = false; 38 39 /** past confirmations */ 40 protected static PermissionCache PERMISSIONS = new PermissionCache(); 37 41 38 42 /** The GET request arguments */ … … 153 157 Logging.info(err); 154 158 throw new RequestHandlerForbiddenException(err); 159 } 160 161 /* 162 * Did the user confirm this action previously? 163 * If yes, skip the global confirmation dialog. 164 */ 165 if (PERMISSIONS.isAllowed(myCommand, sender)) { 166 return; 155 167 } 156 168 … … 167 179 label.setText(message.replaceFirst("<div>", "<div style=\"width:" + maxWidth + "px;\">")); 168 180 } 169 if (JOptionPane.showConfirmDialog(Main.parent, label, 170 tr("Confirm Remote Control action"), 171 JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) { 172 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by user''s choice", myCommand); 173 throw new RequestHandlerForbiddenException(err); 181 Object[] choices = new Object[] {tr("Yes, always"), tr("Yes, once"), tr("No")}; 182 int choice = JOptionPane.showOptionDialog(Main.parent, label, tr("Confirm Remote Control action"), 183 JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE, null, choices, choices[1]); 184 if (choice != JOptionPane.YES_OPTION && choice != JOptionPane.NO_OPTION) { // Yes/no refer to always/once 185 String err = MessageFormat.format("RemoteControl: ''{0}'' forbidden by user''s choice", myCommand); 186 throw new RequestHandlerForbiddenException(err); 187 } else if (choice == JOptionPane.YES_OPTION) { 188 PERMISSIONS.allow(myCommand, sender); 174 189 } 175 190 } … … 391 406 } 392 407 } 408 409 static class PermissionCache { 410 private final Set<Pair<String, String>> allowed = new HashSet<>(); 411 412 public void allow(String command, String sender) { 413 allowed.add(Pair.create(command, sender)); 414 } 415 416 public boolean isAllowed(String command, String sender) { 417 return allowed.contains(Pair.create(command, sender)); 418 } 419 420 public void clear() { 421 allowed.clear(); 422 } 423 } 393 424 }
Note:
See TracChangeset
for help on using the changeset viewer.