1 package org
.argeo
.security
.ui
.application
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.eclipse
.core
.runtime
.IStatus
;
10 import org
.eclipse
.core
.runtime
.Status
;
11 import org
.eclipse
.equinox
.app
.IApplication
;
12 import org
.eclipse
.equinox
.app
.IApplicationContext
;
13 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.ui
.IWorkbench
;
16 import org
.eclipse
.ui
.PlatformUI
;
17 import org
.eclipse
.ui
.application
.WorkbenchAdvisor
;
20 * Common base class for authenticated access to the Eclipse UI framework (RAP and
23 public abstract class AbstractSecureApplication
implements IApplication
{
24 private static final Log log
= LogFactory
25 .getLog(AbstractSecureApplication
.class);
27 protected abstract WorkbenchAdvisor
createWorkbenchAdvisor();
29 public Object
start(IApplicationContext context
) throws Exception
{
31 Integer returnCode
= null;
32 Display display
= PlatformUI
.createDisplay();
37 String username
= null;
38 Exception loginException
= null;
39 Subject subject
= null;
41 SecureApplicationActivator
.getLoginContext().login();
42 subject
= SecureApplicationActivator
.getLoginContext()
45 // username = CurrentUser.getUsername();
46 } catch (Exception e
) {
50 if (subject
== null) {
51 IStatus status
= new Status(IStatus
.ERROR
,
52 "org.argeo.security.application", "Login is mandatory",
54 ErrorDialog
.openError(null, "Error", "Shutdown...", status
);
55 return status
.getSeverity();
58 returnCode
= (Integer
) Subject
.doAs(subject
, getRunAction(display
));
59 SecureApplicationActivator
.getLoginContext().logout();
60 return processReturnCode(returnCode
);
61 } catch (Exception e
) {
62 // e.printStackTrace();
63 IStatus status
= new Status(IStatus
.ERROR
,
64 "org.argeo.security.rcp", "Login failed", e
);
65 ErrorDialog
.openError(null, "Error", "Shutdown...", status
);
72 protected Integer
processReturnCode(Integer returnCode
) {
76 @SuppressWarnings("rawtypes")
77 private PrivilegedAction
getRunAction(final Display display
) {
78 return new PrivilegedAction() {
81 int result
= createAndRunWorkbench(display
);
82 return new Integer(result
);
87 protected Integer
createAndRunWorkbench(Display display
) {
88 return PlatformUI
.createAndRunWorkbench(display
,
89 createWorkbenchAdvisor());
93 final IWorkbench workbench
;
95 workbench
= PlatformUI
.getWorkbench();
96 } catch (Exception e
) {
99 if (workbench
== null)
101 final Display display
= workbench
.getDisplay();
102 if (display
!= null && !display
.isDisposed())
103 display
.syncExec(new Runnable() {
106 if (!display
.isDisposed())
111 if (log
.isDebugEnabled())
112 log
.debug("workbench stopped");
113 // String username = CurrentUser.getUsername();
114 // if (log.isDebugEnabled())
115 // log.debug("workbench stopped, logged in as " + username);