]> git.argeo.org Git - lgpl/argeo-commons.git/blobdiff - security/eclipse/plugins/org.argeo.security.ui.application/src/main/java/org/argeo/security/ui/application/AbstractSecureApplication.java
First working GIS
[lgpl/argeo-commons.git] / security / eclipse / plugins / org.argeo.security.ui.application / src / main / java / org / argeo / security / ui / application / AbstractSecureApplication.java
index c3bf6b1131adf9adf933ec3e03c5f4c69e191e48..a0a2f922bbe31bc16384c087a80cf64c613582ff 100644 (file)
@@ -6,7 +6,6 @@ import javax.security.auth.Subject;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
-import org.argeo.security.equinox.CurrentUser;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
 import org.eclipse.equinox.app.IApplication;
@@ -23,6 +22,7 @@ public abstract class AbstractSecureApplication implements IApplication {
 
        protected abstract WorkbenchAdvisor createWorkbenchAdvisor();
 
+       @SuppressWarnings("unchecked")
        public Object start(IApplicationContext context) throws Exception {
 
                Integer returnCode = null;
@@ -33,12 +33,18 @@ public abstract class AbstractSecureApplication implements IApplication {
                try {
                        String username = null;
                        Exception loginException = null;
+                       Subject subject = null;
                        try {
-                               username = CurrentUser.getUsername();
+                               SecureApplicationActivator.getLoginContext().login();
+                               subject = SecureApplicationActivator.getLoginContext()
+                                               .getSubject();
+
+                               // username = CurrentUser.getUsername();
                        } catch (Exception e) {
                                loginException = e;
+                               e.printStackTrace();
                        }
-                       if (username == null) {
+                       if (subject == null) {
                                IStatus status = new Status(IStatus.ERROR,
                                                "org.argeo.security.application", "Login is mandatory",
                                                loginException);
@@ -47,11 +53,8 @@ public abstract class AbstractSecureApplication implements IApplication {
                        }
                        if (log.isDebugEnabled())
                                log.debug("Logged in as " + username);
-                       returnCode = (Integer) Subject.doAs(CurrentUser.getSubject(),
-                                       getRunAction(display));
-                       if (log.isDebugEnabled())
-                               log.debug("secure action completed");
-                       CurrentUser.logout();
+                       returnCode = (Integer) Subject.doAs(subject, getRunAction(display));
+                       SecureApplicationActivator.getLoginContext().logout();
                        return processReturnCode(returnCode);
                } catch (Exception e) {
                        // e.printStackTrace();
@@ -105,9 +108,9 @@ public abstract class AbstractSecureApplication implements IApplication {
 
                if (log.isDebugEnabled())
                        log.debug("workbench stopped");
-               String username = CurrentUser.getUsername();
-               if (log.isDebugEnabled())
-                       log.debug("workbench stopped, logged in as " + username);
+               // String username = CurrentUser.getUsername();
+               // if (log.isDebugEnabled())
+               // log.debug("workbench stopped, logged in as " + username);
 
        }