1 package org
.argeo
.security
.ui
.rap
;
3 import java
.security
.AccessController
;
5 import javax
.security
.auth
.Subject
;
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
;
24 public class SecureActionBarAdvisor
extends ActionBarAdvisor
{
25 // private final static Log log = LogFactory
26 // .getLog(SecureActionBarAdvisor.class);
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
;
36 public SecureActionBarAdvisor(IActionBarConfigurer configurer
, Boolean isRcp
) {
40 protected void makeActions(IWorkbenchWindow window
) {
41 preferences
= ActionFactory
.PREFERENCES
.create(window
);
42 register(preferences
);
43 openPerspectiveDialogAction
= ActionFactory
.OPEN_PERSPECTIVE_DIALOG
45 register(openPerspectiveDialogAction
);
46 showViewMenuAction
= ActionFactory
.SHOW_VIEW_MENU
.create(window
);
47 register(showViewMenuAction
);
50 logoutAction
= ActionFactory
.QUIT
.create(window
);
51 //logoutAction = createLogoutAction();
52 register(logoutAction
);
55 saveAction
= ActionFactory
.SAVE
.create(window
);
57 saveAllAction
= ActionFactory
.SAVE_ALL
.create(window
);
58 register(saveAllAction
);
59 closeAllAction
= ActionFactory
.CLOSE_ALL
.create(window
);
60 register(closeAllAction
);
64 protected IAction
createLogoutAction() {
65 Subject subject
= Subject
.getSubject(AccessController
.getContext());
66 final String username
= subject
.getPrincipals().iterator().next()
69 IAction logoutAction
= new Action() {
70 public String
getId() {
71 return SecureRapActivator
.ID
+ ".logoutAction";
74 public String
getText() {
75 return "Logout " + username
;
80 // Subject subject = SecureRapActivator.getLoginContext()
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);
89 // SecureEntryPoint.logout(username);
90 // PlatformUI.getWorkbench().close();
92 // RWT.getRequest().getSession().setMaxInactiveInterval(1);
93 // } catch (Exception e) {
94 // if (log.isTraceEnabled())
95 // log.trace("Error when invalidating session", e);
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
);
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
));
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
);
126 editMenu
.add(preferences
);
129 windowMenu
.add(openPerspectiveDialogAction
);
130 windowMenu
.add(showViewMenuAction
);
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
);