Improve Eclipse security
[lgpl/argeo-commons.git] / security / eclipse / plugins / org.argeo.security.ui.rcp / src / main / java / org / argeo / security / ui / rcp / SecureRcp.java
index 47a53598488156dedee1945c5ed232ab6cd308d2..cd1d518b4382a31ee9ffff6e7f2bcab6ce2009d1 100644 (file)
@@ -1,70 +1,21 @@
 package org.argeo.security.ui.rcp;
 
-import java.security.PrivilegedAction;
-
-import javax.security.auth.Subject;
-
-import org.argeo.security.equinox.CurrentUser;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Status;
 import org.eclipse.equinox.app.IApplication;
-import org.eclipse.equinox.app.IApplicationContext;
-import org.eclipse.jface.dialogs.ErrorDialog;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.application.WorkbenchAdvisor;
 
-public class SecureRcp implements IApplication {
-       public Object start(IApplicationContext context) throws Exception {
-               String username = CurrentUser.getUsername();
-               Integer returnCode = null;
-               Display display = PlatformUI.createDisplay();
-               try {
-                       returnCode = (Integer) Subject.doAs(CurrentUser.getSubject(),
-                                       getRunAction(display));
-                       if (returnCode == PlatformUI.RETURN_RESTART)
-                               return IApplication.EXIT_RESTART;
-                       else
-                               return IApplication.EXIT_OK;
-               } catch (Exception e) {
-                       // e.printStackTrace();
-                       IStatus status = new Status(IStatus.ERROR,
-                                       "org.eclipse.rap.security.demo", "Login failed", e);
-                       ErrorDialog.openError(null, "Error", "Login failed", status);
-               } finally {
-                       display.dispose();
-               }
-               return returnCode;
-       }
+public class SecureRcp extends AbstractSecureApplication {
 
-       private PrivilegedAction getRunAction(final Display display) {
-               return new PrivilegedAction() {
-
-                       public Object run() {
-                               int result = PlatformUI.createAndRunWorkbench(display,
-                                               new SecureWorkbenchAdvisor());
-                               return new Integer(result);
-                       }
-               };
+       @Override
+       protected WorkbenchAdvisor createWorkbenchAdvisor() {
+               return new SecureWorkbenchAdvisor();
        }
 
-       public void stop() {
-               final IWorkbench workbench;
-               try {
-                       workbench = PlatformUI.getWorkbench();
-               } catch (Exception e) {
-                       return;
-               }
-               if (workbench == null)
-                       return;
-               final Display display = workbench.getDisplay();
-               display.syncExec(new Runnable() {
-
-                       public void run() {
-                               if (!display.isDisposed())
-                                       workbench.close();
-                       }
-               });
+       protected Integer processReturnCode(Integer returnCode) {
+               if (returnCode == PlatformUI.RETURN_RESTART)
+                       return IApplication.EXIT_RESTART;
+               else
+                       return IApplication.EXIT_OK;
        }
 
 }