1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
package org.openpermis.editor.policy.view; |
11 | |
|
12 | |
import static org.picocontainer.Characteristics.CACHE; |
13 | |
import static org.picocontainer.Characteristics.NO_CACHE; |
14 | |
|
15 | |
import java.awt.Component; |
16 | |
import java.awt.event.WindowAdapter; |
17 | |
import java.awt.event.WindowEvent; |
18 | |
import java.io.BufferedReader; |
19 | |
import java.io.BufferedWriter; |
20 | |
import java.io.File; |
21 | |
import java.io.FileNotFoundException; |
22 | |
import java.io.FileReader; |
23 | |
import java.io.FileWriter; |
24 | |
import java.io.PrintWriter; |
25 | |
import java.io.Reader; |
26 | |
import java.io.StringReader; |
27 | |
import java.io.StringWriter; |
28 | |
import java.io.Writer; |
29 | |
import java.util.EventObject; |
30 | |
import java.util.Iterator; |
31 | |
import java.util.List; |
32 | |
|
33 | |
import javax.swing.JCheckBoxMenuItem; |
34 | |
import javax.swing.JFileChooser; |
35 | |
import javax.swing.JLabel; |
36 | |
import javax.swing.JMenu; |
37 | |
import javax.swing.JMenuBar; |
38 | |
import javax.swing.JMenuItem; |
39 | |
import javax.swing.JOptionPane; |
40 | |
import javax.swing.JProgressBar; |
41 | |
import javax.swing.JToolBar; |
42 | |
import javax.swing.UIManager; |
43 | |
|
44 | |
import org.dom4j.Document; |
45 | |
import org.dom4j.DocumentException; |
46 | |
import org.dom4j.Element; |
47 | |
import org.dom4j.io.SAXReader; |
48 | |
import org.jdesktop.application.Action; |
49 | |
import org.jdesktop.application.ApplicationContext; |
50 | |
import org.jdesktop.application.FrameView; |
51 | |
import org.jdesktop.application.Application.ExitListener; |
52 | |
import org.jdesktop.swingx.JXErrorPane; |
53 | |
import org.jdesktop.swingx.JXFrame; |
54 | |
import org.jdesktop.swingx.JXStatusBar; |
55 | |
import org.jdesktop.swingx.error.ErrorInfo; |
56 | |
import org.picocontainer.MutablePicoContainer; |
57 | |
import org.picocontainer.PicoBuilder; |
58 | |
import org.picocontainer.PicoContainer; |
59 | |
import org.slf4j.Logger; |
60 | |
import org.slf4j.LoggerFactory; |
61 | |
|
62 | |
import org.openpermis.cert.AttributeCertificateExtractorUtility; |
63 | |
import org.openpermis.editor.policy.Application; |
64 | |
import org.openpermis.editor.policy.PolicyFileFilter; |
65 | |
import org.openpermis.editor.policy.adapter.AdapterTrader; |
66 | |
import org.openpermis.editor.policy.beans.PropertyChange; |
67 | |
import org.openpermis.editor.policy.beans.PropertyChangeDispatcher; |
68 | |
import org.openpermis.editor.policy.command.CommandDispatcher; |
69 | |
import org.openpermis.editor.policy.command.CommandManager; |
70 | |
import org.openpermis.editor.policy.gui.EmptyIcon; |
71 | |
import org.openpermis.editor.policy.gui.ErrorStatusUpdater; |
72 | |
import org.openpermis.editor.policy.gui.MenuBarFactory; |
73 | |
import org.openpermis.editor.policy.gui.PolicyIconRegistry; |
74 | |
import org.openpermis.editor.policy.gui.ToolBarFactory; |
75 | |
import org.openpermis.editor.policy.presenter.ActionPresenter; |
76 | |
import org.openpermis.editor.policy.presenter.AuthorityPresenter; |
77 | |
import org.openpermis.editor.policy.presenter.DomainPresenter; |
78 | |
import org.openpermis.editor.policy.presenter.ObligationPresenter; |
79 | |
import org.openpermis.editor.policy.presenter.PolicyContext; |
80 | |
import org.openpermis.editor.policy.presenter.PolicyPresenter; |
81 | |
import org.openpermis.editor.policy.presenter.Presenter; |
82 | |
import org.openpermis.editor.policy.presenter.RecentFilesPresenter; |
83 | |
import org.openpermis.editor.policy.presenter.RoleAssignmentRulePresenter; |
84 | |
import org.openpermis.editor.policy.presenter.RoleHierarchyPresenter; |
85 | |
import org.openpermis.editor.policy.presenter.TargetAccessRulePresenter; |
86 | |
import org.openpermis.editor.policy.presenter.TargetPresenter; |
87 | |
import org.openpermis.policy.ParameterList; |
88 | |
import org.openpermis.policy.bean.ActionBean; |
89 | |
import org.openpermis.policy.bean.AuthorityBean; |
90 | |
import org.openpermis.policy.bean.DomainBean; |
91 | |
import org.openpermis.policy.bean.ObligationBean; |
92 | |
import org.openpermis.policy.bean.PartBean; |
93 | |
import org.openpermis.policy.bean.PartBeanFactory; |
94 | |
import org.openpermis.policy.bean.PolicyBean; |
95 | |
import org.openpermis.policy.bean.RoleAssignmentRuleBean; |
96 | |
import org.openpermis.policy.bean.RoleHierarchyBean; |
97 | |
import org.openpermis.policy.bean.SerialNumber; |
98 | |
import org.openpermis.policy.bean.TargetAccessRuleBean; |
99 | |
import org.openpermis.policy.bean.TargetBean; |
100 | |
import org.openpermis.policy.bean.basic.BasicPartBeanFactory; |
101 | |
import org.openpermis.policy.io.xml.PermisXmlReader; |
102 | |
import org.openpermis.policy.io.xml.PermisXmlWriter; |
103 | |
import org.openpermis.policy.io.xmlchecking.W3CXMLSchemaValidator; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | 0 | public class PolicyView |
114 | |
extends ContextView |
115 | |
implements PolicyLoader, PolicySaver |
116 | |
{ |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | 0 | private static final Logger LOGGER = |
125 | |
LoggerFactory.getLogger(PolicyView.class); |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
private static final String VIEW_MENUBAR = "View.menubar"; |
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
private static final String VIEW_TOOLBAR = "View.toolbar"; |
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
|
143 | |
|
144 | |
private static final String TOOLS_MENU = "<Tools>"; |
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
private static final int STATUS_PROGRESS_BAR_WIDTH = 100; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | |
private final JXFrame frame; |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
private JToolBar toolBar; |
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
private JMenuBar menuBar; |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
private JXStatusBar statusBar; |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
private ErrorStatusUpdater errorStatusUpdater; |
186 | |
|
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
private final MutablePicoContainer factory; |
193 | |
|
194 | |
|
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
private final PicoContainer container; |
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
private PropertyChangeDispatcher commandManagerDispatcher; |
206 | |
|
207 | |
|
208 | |
|
209 | |
|
210 | |
|
211 | |
private PolicyPresenter presenter; |
212 | |
|
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
public PolicyView ( |
224 | |
final Application application, |
225 | |
JXFrame frame, |
226 | |
PolicyIconRegistry iconRegistry, |
227 | |
AdapterTrader trader |
228 | |
) { |
229 | 0 | super(application.getContext(), trader, frame); |
230 | 0 | this.factory = new PicoBuilder().build(); |
231 | 0 | this.container = createContainer(this.factory, application, iconRegistry, trader); |
232 | 0 | this.frame = frame; |
233 | 0 | final ExitListener exitListener = new ExitListener() { |
234 | |
public boolean canExit (EventObject event) { |
235 | 0 | return canClose(); |
236 | |
} |
237 | 0 | public void willExit (EventObject event) { |
238 | |
|
239 | 0 | } |
240 | |
}; |
241 | 0 | application.addExitListener(exitListener); |
242 | 0 | this.frame.addWindowListener( |
243 | |
new WindowAdapter() { |
244 | |
@Override |
245 | 0 | public void windowClosed (WindowEvent e) { |
246 | 0 | if (PolicyView.this.errorStatusUpdater != null) { |
247 | 0 | PolicyView.this.errorStatusUpdater.dispose(); |
248 | |
} |
249 | 0 | application.removeExitListener(exitListener); |
250 | 0 | } |
251 | |
} |
252 | |
); |
253 | 0 | this.frame.setStatusBar(getStatusBar()); |
254 | 0 | } |
255 | |
|
256 | |
|
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
private String editorType (Class<? extends PartBean> type) { |
265 | 0 | return new StringBuilder(Editor.class.getName()). |
266 | |
append("<").append(type.getName()).append(">").toString(); |
267 | |
} |
268 | |
|
269 | |
|
270 | |
|
271 | |
|
272 | |
|
273 | |
|
274 | |
|
275 | |
private String presenterType (Class<? extends PartBean> type) { |
276 | 0 | return new StringBuilder(Presenter.class.getName()). |
277 | |
append("<").append(type.getName()).append(">").toString(); |
278 | |
} |
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
|
286 | |
|
287 | |
|
288 | |
@SuppressWarnings("unchecked") |
289 | |
private final <M> M createTypedComponent (String type, Object parameter) { |
290 | 0 | if (type == null || type.length() == 0 || parameter == null) { |
291 | 0 | return null; |
292 | |
} |
293 | 0 | final Class<?> parameterClass = parameter.getClass(); |
294 | 0 | this.factory.addComponent(parameterClass, parameter); |
295 | 0 | if (this.presenter != null) { |
296 | 0 | this.factory.addComponent( |
297 | |
PolicyContext.class, |
298 | |
this.presenter |
299 | |
); |
300 | 0 | this.factory.addComponent( |
301 | |
CommandDispatcher.class, |
302 | |
this.presenter.getCommandManager() |
303 | |
); |
304 | 0 | this.factory.addComponent( |
305 | |
PartBeanFactory.class, |
306 | |
this.presenter.getPartBeanFactory() |
307 | |
); |
308 | |
} |
309 | |
try { |
310 | 0 | return (M) this.container.getComponent(type); |
311 | |
} finally { |
312 | 0 | if (this.presenter != null) { |
313 | 0 | this.factory.removeComponent(PolicyContext.class); |
314 | 0 | this.factory.removeComponent(CommandDispatcher.class); |
315 | 0 | this.factory.removeComponent(PartBeanFactory.class); |
316 | |
} |
317 | 0 | this.factory.removeComponent(parameterClass); |
318 | |
} |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
|
325 | |
|
326 | |
|
327 | |
|
328 | |
private final boolean canCreateTypedComponent (String type) { |
329 | 0 | return this.container.getComponentAdapter(type) != null; |
330 | |
} |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
|
342 | |
private final MutablePicoContainer createContainer ( |
343 | |
PicoContainer parent, |
344 | |
Application application, |
345 | |
PolicyIconRegistry iconRegistry, |
346 | |
AdapterTrader trader |
347 | |
) { |
348 | 0 | final MutablePicoContainer pico = new PicoBuilder(parent).withCaching().build(); |
349 | 0 | pico.change(NO_CACHE); |
350 | 0 | pico.addComponent(this); |
351 | 0 | pico.addComponent(application.getApplicationState()); |
352 | 0 | pico.addComponent(application.getContext()); |
353 | 0 | pico.addComponent(iconRegistry); |
354 | 0 | pico.addComponent(trader); |
355 | 0 | pico.addComponent(LoadProblemRecorder.class); |
356 | 0 | pico.addComponent(PolicySigningWizard.class); |
357 | |
|
358 | 0 | pico.addComponent( |
359 | |
presenterType(PolicyBean.class), |
360 | |
PolicyPresenter.class |
361 | |
); |
362 | 0 | pico.addComponent( |
363 | |
presenterType(TargetAccessRuleBean.class), |
364 | |
TargetAccessRulePresenter.class |
365 | |
); |
366 | 0 | pico.addComponent( |
367 | |
presenterType(RoleAssignmentRuleBean.class), |
368 | |
RoleAssignmentRulePresenter.class |
369 | |
); |
370 | 0 | pico.addComponent( |
371 | |
presenterType(TargetBean.class), |
372 | |
TargetPresenter.class |
373 | |
); |
374 | 0 | pico.addComponent( |
375 | |
presenterType(DomainBean.class), |
376 | |
DomainPresenter.class |
377 | |
); |
378 | 0 | pico.addComponent( |
379 | |
presenterType(AuthorityBean.class), |
380 | |
AuthorityPresenter.class |
381 | |
); |
382 | 0 | pico.addComponent( |
383 | |
presenterType(ActionBean.class), |
384 | |
ActionPresenter.class |
385 | |
); |
386 | 0 | pico.addComponent( |
387 | |
presenterType(ObligationBean.class), |
388 | |
ObligationPresenter.class |
389 | |
); |
390 | 0 | pico.addComponent( |
391 | |
presenterType(RoleHierarchyBean.class), |
392 | |
RoleHierarchyPresenter.class |
393 | |
); |
394 | |
|
395 | 0 | pico.addComponent( |
396 | |
editorType(TargetAccessRuleBean.class), |
397 | |
TargetAccessRuleEditor.class |
398 | |
); |
399 | 0 | pico.addComponent( |
400 | |
editorType(RoleAssignmentRuleBean.class), |
401 | |
RoleAssignmentRuleEditor.class |
402 | |
); |
403 | 0 | pico.addComponent( |
404 | |
editorType(TargetBean.class), |
405 | |
TargetEditor.class |
406 | |
); |
407 | 0 | pico.addComponent( |
408 | |
editorType(DomainBean.class), |
409 | |
DomainEditor.class |
410 | |
); |
411 | 0 | pico.addComponent( |
412 | |
editorType(AuthorityBean.class), |
413 | |
AuthorityEditor.class |
414 | |
); |
415 | 0 | pico.addComponent( |
416 | |
editorType(ActionBean.class), |
417 | |
ActionEditor.class |
418 | |
); |
419 | 0 | pico.addComponent( |
420 | |
editorType(ObligationBean.class), |
421 | |
ObligationEditor.class |
422 | |
); |
423 | 0 | pico.addComponent( |
424 | |
editorType(RoleHierarchyBean.class), |
425 | |
RoleHierarchyEditor.class |
426 | |
); |
427 | |
|
428 | 0 | pico.change(CACHE); |
429 | 0 | pico.addComponent(ProblemListTool.class); |
430 | 0 | pico.addComponent(TargetAccessRuleListTool.class); |
431 | 0 | pico.addComponent(RoleHierarchyListTool.class); |
432 | 0 | pico.addComponent(RoleAssignmentRuleListTool.class); |
433 | 0 | pico.addComponent(RecentFilesPresenter.class); |
434 | 0 | pico.addComponent(RecentFilesTool.class); |
435 | 0 | pico.addComponent(DecisionTool.class); |
436 | 0 | return pico; |
437 | |
} |
438 | |
|
439 | |
|
440 | |
|
441 | |
|
442 | |
|
443 | |
|
444 | |
|
445 | |
public FrameView configure (FrameView frameView) { |
446 | 0 | frameView.setFrame(this.frame); |
447 | 0 | frameView.setMenuBar(getMenuBar()); |
448 | 0 | frameView.setToolBar(getToolBar()); |
449 | 0 | frameView.setComponent(getContentPane()); |
450 | 0 | openView(this.container.getComponent(ProblemListTool.class)); |
451 | 0 | openView(this.container.getComponent(TargetAccessRuleListTool.class)); |
452 | 0 | openView(this.container.getComponent(RoleHierarchyListTool.class)); |
453 | 0 | openView(this.container.getComponent(RoleAssignmentRuleListTool.class)); |
454 | 0 | openView(this.container.getComponent(RecentFilesTool.class)); |
455 | 0 | openView(this.container.getComponent(DecisionTool.class)); |
456 | 0 | return frameView; |
457 | |
} |
458 | |
|
459 | |
|
460 | |
|
461 | |
|
462 | |
|
463 | |
|
464 | |
private void configureToolsMenu (JMenuBar toolsMenuBar) { |
465 | 0 | JMenu toolsMenu = null; |
466 | 0 | int toolsLocation = -1; |
467 | 0 | for (int i = 0; i < toolsMenuBar.getMenuCount(); i++) { |
468 | 0 | final JMenu menu = toolsMenuBar.getMenu(i); |
469 | 0 | if (menu == null) { |
470 | 0 | continue; |
471 | |
} |
472 | 0 | final Component[] components = menu.getMenuComponents(); |
473 | 0 | for (int k = 0; k < components.length; k++) { |
474 | 0 | if (components[k] instanceof JMenuItem) { |
475 | 0 | final JMenuItem menuItem = (JMenuItem) components[k]; |
476 | 0 | if (TOOLS_MENU.equals(menuItem.getText())) { |
477 | 0 | toolsMenu = menu; |
478 | 0 | toolsLocation = k; |
479 | 0 | menu.remove(menuItem); |
480 | |
} |
481 | |
} |
482 | |
} |
483 | |
} |
484 | 0 | if (toolsMenu == null) { |
485 | 0 | LOGGER.debug("Menu bar does not feature a tools menu."); |
486 | |
} else { |
487 | 0 | LOGGER.debug( |
488 | |
"Adding tool views to menu [{}] at location [{}].", |
489 | |
toolsMenu.getText(), Integer.valueOf(toolsLocation) |
490 | |
); |
491 | 0 | for (final Tool tool : this.container.getComponents(Tool.class)) { |
492 | 0 | final ToolTrackerAction action = new ToolTrackerAction(tool, this); |
493 | 0 | final JCheckBoxMenuItem menuItem = action.createCheckBoxMenuItem(); |
494 | 0 | toolsMenu.add(menuItem, toolsLocation++); |
495 | 0 | } |
496 | |
} |
497 | 0 | } |
498 | |
|
499 | |
|
500 | |
|
501 | |
|
502 | |
|
503 | |
|
504 | |
private JMenuBar getMenuBar () { |
505 | 0 | if (this.menuBar == null) { |
506 | 0 | this.menuBar = MenuBarFactory.createMenuBar( |
507 | |
getActionMap(), getResourceMap(), VIEW_MENUBAR |
508 | |
); |
509 | 0 | configureToolsMenu(this.menuBar); |
510 | |
} |
511 | 0 | return this.menuBar; |
512 | |
} |
513 | |
|
514 | |
|
515 | |
|
516 | |
|
517 | |
|
518 | |
|
519 | |
private JToolBar getToolBar () { |
520 | 0 | if (this.toolBar == null) { |
521 | 0 | this.toolBar = ToolBarFactory.createToolBar( |
522 | |
getActionMap(), getResourceMap(), VIEW_TOOLBAR |
523 | |
); |
524 | |
} |
525 | 0 | return this.toolBar; |
526 | |
} |
527 | |
|
528 | |
|
529 | |
|
530 | |
|
531 | |
|
532 | |
|
533 | |
private JXStatusBar getStatusBar () { |
534 | 0 | if (this.statusBar == null) { |
535 | 0 | this.statusBar = new JXStatusBar(); |
536 | 0 | this.statusBar.setBackground(UIManager.getColor("Menu.background")); |
537 | 0 | final JLabel statusLabel = new JLabel("", EmptyIcon.getIcon(16, 16), JLabel.LEADING); |
538 | 0 | this.errorStatusUpdater = new ErrorStatusUpdater( |
539 | |
getResourceMap(), this.frame, statusLabel |
540 | |
); |
541 | 0 | this.statusBar.add( |
542 | |
statusLabel, |
543 | |
new JXStatusBar.Constraint(JXStatusBar.Constraint.ResizeBehavior.FILL) |
544 | |
); |
545 | 0 | final JProgressBar progressBar = new JProgressBar(); |
546 | 0 | this.statusBar.add( |
547 | |
progressBar, |
548 | |
new JXStatusBar.Constraint(STATUS_PROGRESS_BAR_WIDTH) |
549 | |
); |
550 | |
} |
551 | 0 | return this.statusBar; |
552 | |
} |
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
|
559 | |
public void setPresenter (PolicyPresenter presenter) { |
560 | 0 | for (final Editor editor : getEditorViews()) { |
561 | 0 | LOGGER.debug("Closing editor [{}].", editor.getTitle()); |
562 | 0 | closeView(editor, true); |
563 | |
} |
564 | 0 | if (this.presenter != null) { |
565 | 0 | this.commandManagerDispatcher.dispose(); |
566 | 0 | this.commandManagerDispatcher = null; |
567 | |
} |
568 | 0 | this.presenter = presenter; |
569 | 0 | getActionMap().get("editUndo").setEnabled(false); |
570 | 0 | getActionMap().get("editRedo").setEnabled(false); |
571 | |
|
572 | 0 | LOGGER.debug("Updating policy presenter at tool views."); |
573 | 0 | if (presenter == null) { |
574 | 0 | refresh(null, null); |
575 | |
} else { |
576 | 0 | this.commandManagerDispatcher = |
577 | |
new PropertyChangeDispatcher(this.presenter.getCommandManager(), this); |
578 | 0 | refresh(presenter.getPolicy(), this.presenter); |
579 | |
} |
580 | 0 | } |
581 | |
|
582 | |
|
583 | |
|
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
|
590 | |
private String mapString (String msg) { |
591 | |
String msgMapped; |
592 | 0 | msgMapped = this.getResourceMap().getString(msg); |
593 | 0 | return msgMapped == null ? msg : msgMapped; |
594 | |
} |
595 | |
|
596 | |
|
597 | |
|
598 | |
|
599 | |
|
600 | |
@Action |
601 | |
public void fileValidate () { |
602 | |
String validationResult; |
603 | |
String title; |
604 | |
String validMessage; |
605 | |
|
606 | 0 | title = this.getResourceMap().getString("policyValidationTitle"); |
607 | 0 | if (this.presenter != null) { |
608 | 0 | validMessage = mapString("policyValidationOk"); |
609 | 0 | if (this.presenter.policyIsValid()) { |
610 | 0 | validationResult = validMessage; |
611 | |
} else { |
612 | 0 | validationResult = this.presenter.getPolicyProblems(getResourceMap()); |
613 | |
} |
614 | |
} else { |
615 | 0 | validationResult = mapString("policyValidationNoPolicy"); |
616 | |
} |
617 | 0 | JOptionPane.showMessageDialog( |
618 | |
null, validationResult, title, JOptionPane.INFORMATION_MESSAGE); |
619 | 0 | } |
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
@Action |
626 | |
public void editRedo () { |
627 | 0 | if (this.presenter != null) { |
628 | 0 | this.presenter.getCommandManager().redo(); |
629 | |
} |
630 | 0 | } |
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
@Action |
637 | |
public void editUndo () { |
638 | 0 | if (this.presenter != null) { |
639 | 0 | this.presenter.getCommandManager().undo(); |
640 | |
} |
641 | 0 | } |
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
@Action |
648 | |
public void fileClose () { |
649 | 0 | LOGGER.debug("fileClose"); |
650 | 0 | setPresenter(null); |
651 | 0 | } |
652 | |
|
653 | |
|
654 | |
|
655 | |
|
656 | |
|
657 | |
@Action |
658 | |
public void fileOpen () { |
659 | 0 | loadPolicy(); |
660 | 0 | } |
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | |
|
666 | |
@Action |
667 | |
public void fileQuit () { |
668 | 0 | Application.getInstance().quit(); |
669 | 0 | } |
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
@Action |
676 | |
public void fileSave () { |
677 | 0 | LOGGER.debug("fileSave"); |
678 | 0 | savePolicy(); |
679 | 0 | } |
680 | |
|
681 | |
|
682 | |
|
683 | |
|
684 | |
|
685 | |
@Action |
686 | |
public void fileSaveAs () { |
687 | 0 | LOGGER.debug("fileSaveAs"); |
688 | 0 | savePolicyAs(); |
689 | 0 | } |
690 | |
|
691 | |
|
692 | |
|
693 | |
|
694 | |
|
695 | |
@Action |
696 | |
public void fileSignedImport () { |
697 | 0 | LOGGER.debug("fileSignedImport"); |
698 | 0 | loadSignedPolicy(); |
699 | 0 | } |
700 | |
|
701 | |
|
702 | |
|
703 | |
|
704 | |
|
705 | |
@Action |
706 | |
public void fileSignedExport () { |
707 | 0 | LOGGER.debug("fileSignedExport"); |
708 | 0 | if (this.presenter == null) { |
709 | 0 | return; |
710 | |
} |
711 | 0 | final PolicySigningWizard wizard = new PolicySigningWizard( |
712 | |
this.container.getComponent(ApplicationContext.class), |
713 | |
this.presenter.getPolicy() |
714 | |
); |
715 | 0 | wizard.show(getContentPane()); |
716 | 0 | } |
717 | |
|
718 | |
|
719 | |
|
720 | |
|
721 | |
|
722 | |
@Action |
723 | |
public void fileRoleAssignment () { |
724 | 0 | LOGGER.debug("fileRoleAssignment"); |
725 | 0 | if (this.presenter == null) { |
726 | 0 | return; |
727 | |
} |
728 | 0 | final RoleAssignmentWizard wizard = new RoleAssignmentWizard( |
729 | |
this.container.getComponent(ApplicationContext.class), |
730 | |
this.presenter.getPolicy() |
731 | |
); |
732 | 0 | wizard.show(getContentPane()); |
733 | 0 | } |
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
|
739 | |
@Action |
740 | |
public void actionsFromWsdlImport () { |
741 | 0 | LOGGER.debug("actionsFromWsdlImport"); |
742 | 0 | File file = Application.getInstance().chooseFile( |
743 | |
JFileChooser.OPEN_DIALOG, true, PolicyFileFilter.WSDL_FILE_FILTER |
744 | |
); |
745 | 0 | if (file == null) { |
746 | 0 | return; |
747 | |
} |
748 | 0 | SAXReader reader = new SAXReader(); |
749 | |
try { |
750 | 0 | Document document = reader.read(file); |
751 | 0 | List<?> list = document.selectNodes("//wsdl:definitions/wsdl:portType/*"); |
752 | 0 | for (Iterator<?> iter = list.iterator(); iter.hasNext();) { |
753 | 0 | Element operationElement = (Element) iter.next(); |
754 | 0 | final String operationName = operationElement.attributeValue("name"); |
755 | 0 | LOGGER.debug(operationName); |
756 | 0 | final Element inputElement = |
757 | |
(Element) operationElement.selectSingleNode("wsdl:input"); |
758 | 0 | final String inputMessage = inputElement.attributeValue("message"); |
759 | 0 | LOGGER.debug(inputMessage); |
760 | 0 | ParameterList parameterList = new ParameterList(); |
761 | 0 | parameterList.add(inputMessage, Object.class); |
762 | 0 | this.presenter.getActionPool().getPoolList().add( |
763 | |
this.presenter.getPartBeanFactory().createAction( |
764 | |
operationName, parameterList |
765 | |
) |
766 | |
); |
767 | 0 | } |
768 | 0 | } catch (DocumentException e) { |
769 | 0 | LOGGER.warn(e.getMessage()); |
770 | 0 | } |
771 | 0 | } |
772 | |
|
773 | |
|
774 | |
|
775 | |
|
776 | |
|
777 | |
|
778 | |
|
779 | |
@Action |
780 | |
public void fileNew () { |
781 | 0 | if (!canClose()) { |
782 | 0 | return; |
783 | |
} |
784 | 0 | final PartBeanFactory policyFactory = new BasicPartBeanFactory(); |
785 | 0 | final PolicyBean policy = policyFactory.createPolicy(); |
786 | 0 | LOGGER.info("New policy created"); |
787 | 0 | final PolicyPresenter policyPresenter = new PolicyPresenter(policy, policyFactory); |
788 | 0 | setPresenter(policyPresenter); |
789 | 0 | openView(this.container.getComponent(TargetAccessRuleListTool.class)); |
790 | 0 | openView(this.container.getComponent(RoleHierarchyListTool.class)); |
791 | 0 | openView(this.container.getComponent(RoleAssignmentRuleListTool.class)); |
792 | 0 | } |
793 | |
|
794 | |
|
795 | |
|
796 | |
|
797 | |
@Override |
798 | |
public Editor editPart (PartBean part) { |
799 | 0 | if (part == null) { |
800 | 0 | return null; |
801 | |
} |
802 | 0 | final SerialNumber serial = part.getSerialNumber(); |
803 | 0 | for (final Editor editor : getEditorViews()) { |
804 | 0 | if (serial.equals(editor.getModelSerialNumber())) { |
805 | 0 | LOGGER.debug("Activating editor for part [{}].", part); |
806 | 0 | activateEditor(editor); |
807 | 0 | return editor; |
808 | |
} |
809 | |
} |
810 | 0 | LOGGER.debug("Creating editor for part [{}].", part); |
811 | 0 | final Class<? extends PartBean> type = part.getPartBeanType(); |
812 | 0 | final Presenter<?> partPresenter = createTypedComponent(presenterType(type), part); |
813 | 0 | final Editor editor = createTypedComponent(editorType(type), partPresenter); |
814 | 0 | openView(editor); |
815 | 0 | return editor; |
816 | |
} |
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
@Override |
822 | |
public boolean canEditPart (PartBean part) { |
823 | 0 | if (part == null) { |
824 | 0 | return false; |
825 | |
} |
826 | 0 | final Class<? extends PartBean> type = part.getPartBeanType(); |
827 | 0 | return |
828 | |
canCreateTypedComponent(presenterType(type)) && |
829 | |
canCreateTypedComponent(editorType(type)); |
830 | |
} |
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
|
836 | |
|
837 | |
|
838 | |
|
839 | |
|
840 | |
@Override |
841 | |
protected void refresh (PolicyBean policy, PolicyContext context) { |
842 | 0 | for (Tool tool : this.container.getComponents(Tool.class)) { |
843 | 0 | tool.refresh(policy, context); |
844 | |
} |
845 | 0 | } |
846 | |
|
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | |
|
852 | |
@Override |
853 | |
public void showStatusError (String message) { |
854 | 0 | if (this.errorStatusUpdater != null) { |
855 | 0 | this.errorStatusUpdater.showError(message); |
856 | |
} |
857 | 0 | } |
858 | |
|
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
@Override |
865 | |
public boolean canClose () { |
866 | 0 | return true; |
867 | |
} |
868 | |
|
869 | |
|
870 | |
|
871 | |
|
872 | |
|
873 | |
|
874 | |
public void loadPolicy (File file) { |
875 | |
|
876 | |
|
877 | 0 | if (!canClose()) { |
878 | 0 | return; |
879 | |
} |
880 | |
|
881 | |
|
882 | 0 | String message = W3CXMLSchemaValidator.validate(file); |
883 | 0 | if (message != null) { |
884 | 0 | JOptionPane.showMessageDialog( |
885 | |
null, message, |
886 | |
getResourceMap().getString("loadError.title"), JOptionPane.WARNING_MESSAGE); |
887 | |
} |
888 | |
|
889 | |
|
890 | |
Reader reader; |
891 | |
try { |
892 | 0 | reader = new BufferedReader(new FileReader(file)); |
893 | 0 | } catch (FileNotFoundException e) { |
894 | 0 | JOptionPane.showMessageDialog( |
895 | |
null, |
896 | |
getResourceMap().getString( |
897 | |
"loadError.message", file.getName(), e.getMessage()), |
898 | |
getResourceMap().getString("loadError.title"), JOptionPane.ERROR_MESSAGE); |
899 | 0 | return; |
900 | 0 | } |
901 | |
|
902 | |
|
903 | 0 | loadPolicy(reader, file, true); |
904 | 0 | } |
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
public void loadPolicy () { |
911 | 0 | File file = Application.getInstance().chooseFile( |
912 | |
JFileChooser.OPEN_DIALOG, true, PolicyFileFilter.XML_FILE_FILTER); |
913 | 0 | if (file == null) { |
914 | 0 | return; |
915 | |
} |
916 | 0 | loadPolicy(file); |
917 | 0 | } |
918 | |
|
919 | |
|
920 | |
|
921 | |
|
922 | |
public void loadSignedPolicy () { |
923 | |
|
924 | |
|
925 | 0 | if (!canClose()) { |
926 | 0 | return; |
927 | |
} |
928 | |
|
929 | |
|
930 | 0 | File file = Application.getInstance().chooseFile( |
931 | |
JFileChooser.OPEN_DIALOG, true, PolicyFileFilter.ACE_FILE_FILTER); |
932 | 0 | if (file == null) { |
933 | 0 | return; |
934 | |
} |
935 | |
|
936 | |
|
937 | |
String policy; |
938 | |
try { |
939 | 0 | policy = AttributeCertificateExtractorUtility.readPolicy(file.toURI().toURL()); |
940 | 0 | } catch (Exception e) { |
941 | 0 | LOGGER.warn("Could not read policy [" + file + "].", e); |
942 | 0 | final StringWriter wr = new StringWriter(); |
943 | 0 | e.printStackTrace(new PrintWriter(wr)); |
944 | 0 | JXErrorPane.showDialog( |
945 | |
null, |
946 | |
new ErrorInfo( |
947 | |
getResourceMap().getString("loadError.title"), |
948 | |
getResourceMap().getString( |
949 | |
"loadError.message", file.getName(), e.getMessage() |
950 | |
), |
951 | |
"<pre>" + wr.toString() + "</pre>", |
952 | |
null, |
953 | |
null, |
954 | |
null, |
955 | |
null |
956 | |
) |
957 | |
); |
958 | 0 | return; |
959 | 0 | } |
960 | |
|
961 | |
|
962 | 0 | Reader reader = new StringReader(policy); |
963 | |
|
964 | |
|
965 | 0 | loadPolicy(reader, file, false); |
966 | 0 | } |
967 | |
|
968 | |
|
969 | |
|
970 | |
|
971 | |
private void loadPolicy (Reader reader, File file, boolean setLastFilename) { |
972 | |
try { |
973 | |
try { |
974 | 0 | final PartBeanFactory policyFactory = new BasicPartBeanFactory(); |
975 | 0 | final LoadProblemRecorder problemRecorder = |
976 | |
this.container.getComponent(LoadProblemRecorder.class); |
977 | 0 | final PolicyBean policy = (PolicyBean) |
978 | |
new PermisXmlReader(reader, policyFactory, problemRecorder).readPolicy(); |
979 | 0 | if (problemRecorder.hasWarnings()) { |
980 | 0 | problemRecorder.showDialog(getContentPane(), file); |
981 | |
} |
982 | 0 | LOGGER.info("Policy loaded from [{}].", file); |
983 | 0 | final PolicyPresenter policyPresenter = |
984 | |
new PolicyPresenter(policy, policyFactory); |
985 | 0 | setPresenter(policyPresenter); |
986 | 0 | openView(this.container.getComponent(TargetAccessRuleListTool.class)); |
987 | 0 | openView(this.container.getComponent(RoleHierarchyListTool.class)); |
988 | 0 | openView(this.container.getComponent(RoleAssignmentRuleListTool.class)); |
989 | 0 | if (setLastFilename) { |
990 | 0 | policyPresenter.setFilename(file.getAbsolutePath()); |
991 | |
} |
992 | |
} finally { |
993 | 0 | reader.close(); |
994 | 0 | } |
995 | 0 | } catch (final Exception e) { |
996 | 0 | LOGGER.warn("Could not read policy [" + file + "].", e); |
997 | 0 | final StringWriter wr = new StringWriter(); |
998 | 0 | e.printStackTrace(new PrintWriter(wr)); |
999 | 0 | JXErrorPane.showDialog( |
1000 | |
null, |
1001 | |
new ErrorInfo( |
1002 | |
getResourceMap().getString("loadError.title"), |
1003 | |
getResourceMap().getString( |
1004 | |
"loadError.message", file.getName(), e.getMessage() |
1005 | |
), |
1006 | |
"<pre>" + wr.toString() + "</pre>", |
1007 | |
null, |
1008 | |
null, |
1009 | |
null, |
1010 | |
null |
1011 | |
) |
1012 | |
); |
1013 | 0 | } |
1014 | 0 | } |
1015 | |
|
1016 | |
|
1017 | |
|
1018 | |
|
1019 | |
|
1020 | |
|
1021 | |
|
1022 | |
public void savePolicy () { |
1023 | 0 | doSavePolicy(true); |
1024 | 0 | } |
1025 | |
|
1026 | |
|
1027 | |
|
1028 | |
|
1029 | |
|
1030 | |
public void savePolicyAs () { |
1031 | 0 | doSavePolicy(false); |
1032 | 0 | } |
1033 | |
|
1034 | |
|
1035 | |
|
1036 | |
|
1037 | |
|
1038 | |
|
1039 | |
private void doSavePolicy (boolean withCurrentFilename) { |
1040 | |
|
1041 | |
File file; |
1042 | |
String filename; |
1043 | |
|
1044 | 0 | LOGGER.debug("doSavePolicy"); |
1045 | |
|
1046 | |
|
1047 | 0 | if ( this.presenter == null |
1048 | |
|| this.presenter.getPolicy() == null ) { |
1049 | 0 | LOGGER.debug("no policy to save"); |
1050 | 0 | return; |
1051 | |
} |
1052 | |
|
1053 | |
|
1054 | |
|
1055 | |
|
1056 | |
|
1057 | 0 | if (withCurrentFilename) { |
1058 | 0 | filename = this.presenter.getFilename(); |
1059 | 0 | if (filename == null || "".equals(filename)) { |
1060 | 0 | filename = null; |
1061 | |
} |
1062 | |
} else { |
1063 | 0 | filename = null; |
1064 | |
} |
1065 | |
|
1066 | |
|
1067 | |
|
1068 | |
|
1069 | |
|
1070 | 0 | if (filename == null) { |
1071 | 0 | file = Application.getInstance().chooseFile( |
1072 | |
JFileChooser.SAVE_DIALOG, true, PolicyFileFilter.XML_FILE_FILTER); |
1073 | 0 | if (file == null) { |
1074 | 0 | LOGGER.debug("aborted by user"); |
1075 | 0 | return; |
1076 | |
} |
1077 | 0 | filename = file.getAbsolutePath(); |
1078 | |
} |
1079 | |
|
1080 | |
|
1081 | |
|
1082 | |
|
1083 | |
|
1084 | 0 | if (!filename.toLowerCase().endsWith(".xml")) { |
1085 | 0 | filename = filename + ".xml"; |
1086 | |
} |
1087 | |
|
1088 | |
|
1089 | |
|
1090 | |
|
1091 | |
|
1092 | |
|
1093 | 0 | file = new File(filename); |
1094 | 0 | if (file.exists()) { |
1095 | 0 | final int response = JOptionPane.showConfirmDialog( |
1096 | |
null, "Overwrite existing file '" + filename + "' ?", "Confirm Overwrite", |
1097 | |
JOptionPane.OK_CANCEL_OPTION, |
1098 | |
JOptionPane.QUESTION_MESSAGE); |
1099 | 0 | if (response == JOptionPane.CANCEL_OPTION) { |
1100 | 0 | LOGGER.debug("Saving aborted by user"); |
1101 | 0 | return; |
1102 | |
} |
1103 | |
} |
1104 | |
|
1105 | |
|
1106 | |
|
1107 | |
|
1108 | |
|
1109 | 0 | savePolicy(file); |
1110 | |
|
1111 | |
|
1112 | 0 | Application.getInstance().getApplicationState().addRecentFiles(filename); |
1113 | |
|
1114 | |
|
1115 | 0 | String message = W3CXMLSchemaValidator.validate(file); |
1116 | 0 | if (message != null) { |
1117 | 0 | JOptionPane.showMessageDialog( |
1118 | |
null, message, |
1119 | |
getResourceMap().getString("saveError.title"), JOptionPane.WARNING_MESSAGE); |
1120 | |
} |
1121 | |
|
1122 | |
|
1123 | 0 | this.presenter.setFilename(filename); |
1124 | 0 | } |
1125 | |
|
1126 | |
|
1127 | |
|
1128 | |
|
1129 | |
public void savePolicy (File file) { |
1130 | |
|
1131 | 0 | if (file == null) { |
1132 | 0 | LOGGER.debug("Saving aborted by user"); |
1133 | 0 | return; |
1134 | |
} |
1135 | |
|
1136 | |
|
1137 | |
try { |
1138 | 0 | final Writer wr = new BufferedWriter(new FileWriter(file.getAbsolutePath())); |
1139 | |
try { |
1140 | 0 | final PolicyBean policy = this.presenter.getPolicy(); |
1141 | 0 | new PermisXmlWriter(wr).writePolicy(policy); |
1142 | 0 | LOGGER.info("Policy saved to [{}].", file.getAbsolutePath()); |
1143 | |
} finally { |
1144 | 0 | wr.close(); |
1145 | 0 | } |
1146 | 0 | } catch (final Exception e) { |
1147 | 0 | LOGGER.warn("Could not save policy [" + file.getAbsolutePath() + "].", e); |
1148 | 0 | } |
1149 | 0 | } |
1150 | |
|
1151 | |
|
1152 | |
|
1153 | |
|
1154 | |
|
1155 | |
|
1156 | |
|
1157 | |
@PropertyChange( |
1158 | |
bean = CommandManager.class, |
1159 | |
property = "undoAvailable", |
1160 | |
parameter = boolean.class |
1161 | |
) |
1162 | |
public void undoChanged ( |
1163 | |
CommandManager commandManager, String property, boolean oldValue, boolean newValue |
1164 | |
) { |
1165 | 0 | final javax.swing.Action action = getActionMap().get("editUndo"); |
1166 | 0 | action.setEnabled(newValue); |
1167 | 0 | action.putValue(javax.swing.Action.SHORT_DESCRIPTION, commandManager.getUndoName()); |
1168 | 0 | } |
1169 | |
|
1170 | |
|
1171 | |
|
1172 | |
|
1173 | |
|
1174 | |
@PropertyChange( |
1175 | |
bean = CommandManager.class, |
1176 | |
property = "redoAvailable", |
1177 | |
parameter = boolean.class |
1178 | |
) |
1179 | |
public void redoChanged ( |
1180 | |
CommandManager commandManager, String property, boolean oldValue, boolean newValue |
1181 | |
) { |
1182 | 0 | final javax.swing.Action action = getActionMap().get("editRedo"); |
1183 | 0 | action.setEnabled(newValue); |
1184 | 0 | action.putValue(javax.swing.Action.SHORT_DESCRIPTION, commandManager.getRedoName()); |
1185 | 0 | } |
1186 | |
|
1187 | |
} |