1 package org
.argeo
.security
.ui
.rap
;
3 import java
.security
.Principal
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginException
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.ArgeoException
;
11 import org
.eclipse
.jface
.action
.Action
;
12 import org
.eclipse
.jface
.action
.GroupMarker
;
13 import org
.eclipse
.jface
.action
.IAction
;
14 import org
.eclipse
.jface
.action
.ICoolBarManager
;
15 import org
.eclipse
.jface
.action
.IMenuManager
;
16 import org
.eclipse
.jface
.action
.IToolBarManager
;
17 import org
.eclipse
.jface
.action
.MenuManager
;
18 import org
.eclipse
.jface
.action
.Separator
;
19 import org
.eclipse
.jface
.action
.ToolBarManager
;
20 import org
.eclipse
.rwt
.RWT
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.ui
.IWorkbenchActionConstants
;
23 import org
.eclipse
.ui
.IWorkbenchWindow
;
24 import org
.eclipse
.ui
.PlatformUI
;
25 import org
.eclipse
.ui
.actions
.ActionFactory
;
26 import org
.eclipse
.ui
.actions
.ActionFactory
.IWorkbenchAction
;
27 import org
.eclipse
.ui
.application
.ActionBarAdvisor
;
28 import org
.eclipse
.ui
.application
.IActionBarConfigurer
;
30 public class SecureActionBarAdvisor
extends ActionBarAdvisor
{
31 private final static Log log
= LogFactory
32 .getLog(SecureActionBarAdvisor
.class);
34 private IAction logoutAction
;
35 private IWorkbenchAction openPerspectiveDialogAction
;
36 private IWorkbenchAction showViewMenuAction
;
37 private IWorkbenchAction preferences
;
38 private IWorkbenchAction saveAction
;
39 private IWorkbenchAction saveAllAction
;
40 private IWorkbenchAction closeAllAction
;
42 public SecureActionBarAdvisor(IActionBarConfigurer configurer
, Boolean isRcp
) {
46 protected void makeActions(IWorkbenchWindow window
) {
47 preferences
= ActionFactory
.PREFERENCES
.create(window
);
48 register(preferences
);
49 openPerspectiveDialogAction
= ActionFactory
.OPEN_PERSPECTIVE_DIALOG
51 register(openPerspectiveDialogAction
);
52 showViewMenuAction
= ActionFactory
.SHOW_VIEW_MENU
.create(window
);
53 register(showViewMenuAction
);
55 // logoutAction = ActionFactory.QUIT.create(window);
57 Subject subject
= null;
59 subject
= SecureRapActivator
.getLoginContext().getSubject();
60 } catch (LoginException e1
) {
61 throw new ArgeoException("Cannot retrieve subject", e1
);
63 final Principal principal
= subject
.getPrincipals().iterator().next();
65 logoutAction
= new Action() {
66 public String
getId() {
67 return SecureRapActivator
.ID
+ ".logoutAction";
70 public String
getText() {
71 return "Logout " + principal
.getName();
76 Subject subject
= SecureRapActivator
.getLoginContext()
78 String subjectStr
= subject
.toString();
79 SecureRapActivator
.getLoginContext().logout();
80 log
.info(subjectStr
+ " logged out");
81 } catch (LoginException e
) {
82 log
.error("Error when logging out", e
);
85 RWT
.getRequest().getSession().setMaxInactiveInterval(1);
86 PlatformUI
.getWorkbench().close();
87 } catch (Exception e
) {
88 if (log
.isTraceEnabled())
89 log
.trace("Error when invalidating session", e
);
94 register(logoutAction
);
97 saveAction
= ActionFactory
.SAVE
.create(window
);
99 saveAllAction
= ActionFactory
.SAVE_ALL
.create(window
);
100 register(saveAllAction
);
101 closeAllAction
= ActionFactory
.CLOSE_ALL
.create(window
);
102 register(closeAllAction
);
106 protected void fillMenuBar(IMenuManager menuBar
) {
107 MenuManager fileMenu
= new MenuManager("&File",
108 IWorkbenchActionConstants
.M_FILE
);
109 MenuManager editMenu
= new MenuManager("&Edit",
110 IWorkbenchActionConstants
.M_EDIT
);
111 MenuManager windowMenu
= new MenuManager("&Window",
112 IWorkbenchActionConstants
.M_WINDOW
);
114 menuBar
.add(fileMenu
);
115 menuBar
.add(editMenu
);
116 menuBar
.add(windowMenu
);
117 // Add a group marker indicating where action set menus will appear.
118 menuBar
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
121 fileMenu
.add(saveAction
);
122 fileMenu
.add(saveAllAction
);
123 fileMenu
.add(closeAllAction
);
124 fileMenu
.add(new GroupMarker(IWorkbenchActionConstants
.MB_ADDITIONS
));
125 fileMenu
.add(new Separator());
126 fileMenu
.add(logoutAction
);
129 editMenu
.add(preferences
);
132 windowMenu
.add(openPerspectiveDialogAction
);
133 windowMenu
.add(showViewMenuAction
);
137 protected void fillCoolBar(ICoolBarManager coolBar
) {
138 IToolBarManager saveToolbar
= new ToolBarManager(SWT
.FLAT
| SWT
.RIGHT
);
139 saveToolbar
.add(saveAction
);
140 saveToolbar
.add(saveAllAction
);
141 coolBar
.add(saveToolbar
);