1 package org
.argeo
.security
.ui
.rap
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginException
;
8 import org
.argeo
.eclipse
.ui
.dialogs
.Error
;
9 import org
.eclipse
.core
.runtime
.IStatus
;
10 import org
.eclipse
.core
.runtime
.Status
;
11 import org
.eclipse
.jface
.dialogs
.ErrorDialog
;
12 import org
.eclipse
.rwt
.lifecycle
.IEntryPoint
;
13 import org
.eclipse
.swt
.widgets
.Display
;
14 import org
.eclipse
.ui
.PlatformUI
;
15 import org
.eclipse
.ui
.application
.IWorkbenchWindowConfigurer
;
16 import org
.eclipse
.ui
.application
.WorkbenchAdvisor
;
17 import org
.eclipse
.ui
.application
.WorkbenchWindowAdvisor
;
19 public class SecureEntryPoint
implements IEntryPoint
{
22 public int createUI() {
23 Integer returnCode
= null;
24 Display display
= PlatformUI
.createDisplay();
26 Subject subject
= null;
30 SecureRapActivator
.getLoginContext().login();
31 subject
= SecureRapActivator
.getLoginContext()
34 } catch (LoginException e
) {
35 Error
.show("Cannot login", e
);
37 } catch (Exception e
) {
38 Error
.show("Unexpected exception while trying to login", e
);
43 if (subject
== null) {
44 // IStatus status = new Status(IStatus.ERROR,
45 // "org.argeo.security.application", "Login is mandatory",
47 // ErrorDialog.openError(null, "Error", "Shutdown...", status);
48 // return status.getSeverity();
50 // TODO: log as anonymous
53 if (subject
!= null) {
54 returnCode
= (Integer
) Subject
.doAs(subject
,
55 getRunAction(display
));
56 SecureRapActivator
.getLoginContext().logout();
57 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 @SuppressWarnings("rawtypes")
73 private PrivilegedAction
getRunAction(final Display display
) {
74 return new PrivilegedAction() {
77 int result
= createAndRunWorkbench(display
);
78 return new Integer(result
);
83 protected Integer
createAndRunWorkbench(Display display
) {
84 return PlatformUI
.createAndRunWorkbench(display
,
85 createWorkbenchAdvisor());
88 protected Integer
processReturnCode(Integer returnCode
) {
92 protected WorkbenchAdvisor
createWorkbenchAdvisor() {
93 return new SecureWorkbenchAdvisor() {
94 public WorkbenchWindowAdvisor
createWorkbenchWindowAdvisor(
95 IWorkbenchWindowConfigurer configurer
) {
96 return new RapSecureWorkbenchWindowAdvisor(configurer
);