1 package org
.argeo
.security
.ui
.rcp
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
7 import org
.argeo
.security
.equinox
.CurrentUser
;
8 import org
.eclipse
.core
.runtime
.IStatus
;
9 import org
.eclipse
.core
.runtime
.Status
;
10 import org
.eclipse
.equinox
.app
.IApplication
;
11 import org
.eclipse
.equinox
.app
.IApplicationContext
;
12 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
13 import org
.eclipse
.swt
.widgets
.Display
;
14 import org
.eclipse
.ui
.IWorkbench
;
15 import org
.eclipse
.ui
.PlatformUI
;
17 public class SecureRcp
implements IApplication
{
18 public Object
start(IApplicationContext context
) throws Exception
{
19 String username
= CurrentUser
.getUsername();
20 Integer returnCode
= null;
21 Display display
= PlatformUI
.createDisplay();
23 returnCode
= (Integer
) Subject
.doAs(CurrentUser
.getSubject(),
24 getRunAction(display
));
25 if (returnCode
== PlatformUI
.RETURN_RESTART
)
26 return IApplication
.EXIT_RESTART
;
28 return IApplication
.EXIT_OK
;
29 } catch (Exception e
) {
30 // e.printStackTrace();
31 IStatus status
= new Status(IStatus
.ERROR
,
32 "org.eclipse.rap.security.demo", "Login failed", e
);
33 ErrorDialog
.openError(null, "Error", "Login failed", status
);
40 private PrivilegedAction
getRunAction(final Display display
) {
41 return new PrivilegedAction() {
44 int result
= PlatformUI
.createAndRunWorkbench(display
,
45 new SecureWorkbenchAdvisor());
46 return new Integer(result
);
52 final IWorkbench workbench
;
54 workbench
= PlatformUI
.getWorkbench();
55 } catch (Exception e
) {
58 if (workbench
== null)
60 final Display display
= workbench
.getDisplay();
61 display
.syncExec(new Runnable() {
64 if (!display
.isDisposed())