]> git.argeo.org Git - lgpl/argeo-commons.git/blob - rap/SecureActionBarAdvisor.java
Prepare next development cycle
[lgpl/argeo-commons.git] / rap / SecureActionBarAdvisor.java
1 package org.argeo.security.ui.rap;
2
3 import java.security.AccessController;
4
5 import javax.security.auth.Subject;
6
7 import org.eclipse.jface.action.Action;
8 import org.eclipse.jface.action.GroupMarker;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.action.ICoolBarManager;
11 import org.eclipse.jface.action.IMenuManager;
12 import org.eclipse.jface.action.IToolBarManager;
13 import org.eclipse.jface.action.MenuManager;
14 import org.eclipse.jface.action.Separator;
15 import org.eclipse.jface.action.ToolBarManager;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.ui.IWorkbenchActionConstants;
18 import org.eclipse.ui.IWorkbenchWindow;
19 import org.eclipse.ui.actions.ActionFactory;
20 import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
21 import org.eclipse.ui.application.ActionBarAdvisor;
22 import org.eclipse.ui.application.IActionBarConfigurer;
23
24 public class SecureActionBarAdvisor extends ActionBarAdvisor {
25 // private final static Log log = LogFactory
26 // .getLog(SecureActionBarAdvisor.class);
27
28 private IAction logoutAction;
29 private IWorkbenchAction openPerspectiveDialogAction;
30 private IWorkbenchAction showViewMenuAction;
31 private IWorkbenchAction preferences;
32 private IWorkbenchAction saveAction;
33 private IWorkbenchAction saveAllAction;
34 private IWorkbenchAction closeAllAction;
35
36 public SecureActionBarAdvisor(IActionBarConfigurer configurer, Boolean isRcp) {
37 super(configurer);
38 }
39
40 protected void makeActions(IWorkbenchWindow window) {
41 preferences = ActionFactory.PREFERENCES.create(window);
42 register(preferences);
43 openPerspectiveDialogAction = ActionFactory.OPEN_PERSPECTIVE_DIALOG
44 .create(window);
45 register(openPerspectiveDialogAction);
46 showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
47 register(showViewMenuAction);
48
49 // logout
50 logoutAction = ActionFactory.QUIT.create(window);
51 //logoutAction = createLogoutAction();
52 register(logoutAction);
53
54 // Save semantics
55 saveAction = ActionFactory.SAVE.create(window);
56 register(saveAction);
57 saveAllAction = ActionFactory.SAVE_ALL.create(window);
58 register(saveAllAction);
59 closeAllAction = ActionFactory.CLOSE_ALL.create(window);
60 register(closeAllAction);
61
62 }
63
64 protected IAction createLogoutAction() {
65 Subject subject = Subject.getSubject(AccessController.getContext());
66 final String username = subject.getPrincipals().iterator().next()
67 .getName();
68
69 IAction logoutAction = new Action() {
70 public String getId() {
71 return SecureRapActivator.ID + ".logoutAction";
72 }
73
74 public String getText() {
75 return "Logout " + username;
76 }
77
78 public void run() {
79 // try {
80 // Subject subject = SecureRapActivator.getLoginContext()
81 // .getSubject();
82 // String subjectStr = subject.toString();
83 // subject.getPrincipals().clear();
84 // SecureRapActivator.getLoginContext().logout();
85 // log.info(subjectStr + " logged out");
86 // } catch (LoginException e) {
87 // log.error("Error when logging out", e);
88 // }
89 // SecureEntryPoint.logout(username);
90 // PlatformUI.getWorkbench().close();
91 // try {
92 // RWT.getRequest().getSession().setMaxInactiveInterval(1);
93 // } catch (Exception e) {
94 // if (log.isTraceEnabled())
95 // log.trace("Error when invalidating session", e);
96 // }
97 }
98
99 };
100 return logoutAction;
101 }
102
103 protected void fillMenuBar(IMenuManager menuBar) {
104 MenuManager fileMenu = new MenuManager("&File",
105 IWorkbenchActionConstants.M_FILE);
106 MenuManager editMenu = new MenuManager("&Edit",
107 IWorkbenchActionConstants.M_EDIT);
108 MenuManager windowMenu = new MenuManager("&Window",
109 IWorkbenchActionConstants.M_WINDOW);
110
111 menuBar.add(fileMenu);
112 menuBar.add(editMenu);
113 menuBar.add(windowMenu);
114 // Add a group marker indicating where action set menus will appear.
115 menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
116
117 // File
118 fileMenu.add(saveAction);
119 fileMenu.add(saveAllAction);
120 fileMenu.add(closeAllAction);
121 fileMenu.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
122 fileMenu.add(new Separator());
123 fileMenu.add(logoutAction);
124
125 // Edit
126 editMenu.add(preferences);
127
128 // Window
129 windowMenu.add(openPerspectiveDialogAction);
130 windowMenu.add(showViewMenuAction);
131 }
132
133 @Override
134 protected void fillCoolBar(ICoolBarManager coolBar) {
135 IToolBarManager saveToolbar = new ToolBarManager(SWT.FLAT | SWT.RIGHT);
136 saveToolbar.add(saveAction);
137 saveToolbar.add(saveAllAction);
138 coolBar.add(saveToolbar);
139 }
140
141 }