X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=security%2Fplugins%2Forg.argeo.security.ui.rap%2Fsrc%2Fmain%2Fjava%2Forg%2Fargeo%2Fsecurity%2Fui%2Frap%2FSecureEntryPoint.java;h=f30f0059bd825516bdc77cff250d9bb6d5ed14f1;hb=fb4f7c451ea7d9025f7cf7fe032020f229df794a;hp=50f74e9c72fe6a06f7227f04b524577e14288b59;hpb=2f510fb09e18bc3d3e902c8131d0037763c5f279;p=lgpl%2Fargeo-commons.git diff --git a/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureEntryPoint.java b/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureEntryPoint.java index 50f74e9c7..f30f0059b 100644 --- a/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureEntryPoint.java +++ b/security/plugins/org.argeo.security.ui.rap/src/main/java/org/argeo/security/ui/rap/SecureEntryPoint.java @@ -1,7 +1,6 @@ package org.argeo.security.ui.rap; import java.security.PrivilegedAction; -import java.util.Set; import javax.security.auth.Subject; import javax.security.auth.login.LoginException; @@ -9,10 +8,6 @@ import javax.security.auth.login.LoginException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.argeo.eclipse.ui.dialogs.Error; -import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.ErrorDialog; -import org.eclipse.rwt.RWT; import org.eclipse.rwt.lifecycle.IEntryPoint; import org.eclipse.rwt.service.SessionStoreEvent; import org.eclipse.rwt.service.SessionStoreListener; @@ -21,24 +16,15 @@ import org.eclipse.ui.PlatformUI; import org.eclipse.ui.application.IWorkbenchWindowConfigurer; import org.eclipse.ui.application.WorkbenchAdvisor; import org.eclipse.ui.application.WorkbenchWindowAdvisor; -import org.springframework.security.Authentication; -import org.springframework.security.context.SecurityContextHolder; public class SecureEntryPoint implements IEntryPoint, SessionStoreListener { private Log log = LogFactory.getLog(SecureEntryPoint.class); - private final static String SECURITY_CONTEXT_ATTRIBUTE = "securityContextAttribute"; - @Override public int createUI() { -// log.debug("THREAD=" + Thread.currentThread().getId() -// + ", RWT.getSessionStore().getId()=" -// + RWT.getSessionStore().getId()); - - Authentication authen = (Authentication) RWT.getSessionStore() - .getAttribute(SECURITY_CONTEXT_ATTRIBUTE); - if (authen != null) - SecurityContextHolder.getContext().setAuthentication(authen); + // log.debug("THREAD=" + Thread.currentThread().getId() + // + ", RWT.getSessionStore().getId()=" + // + RWT.getSessionStore().getId()); Integer returnCode = null; Display display = PlatformUI.createDisplay(); @@ -47,18 +33,10 @@ public class SecureEntryPoint implements IEntryPoint, SessionStoreListener { Boolean retry = true; while (retry) { try { - // if (authen == null) - // SecureRapActivator.getLoginContext().login(); + // force login in order to give Spring Security a chance to + // load + SecureRapActivator.getLoginContext().login(); subject = SecureRapActivator.getLoginContext().getSubject(); - Set auths = subject - .getPrincipals(Authentication.class); - if (auths.size() > 0) - SecurityContextHolder.getContext().setAuthentication( - auths.iterator().next()); - // authen = SecurityContextHolder.getContext() - // .getAuthentication(); - // RWT.getSessionStore().setAttribute( - // SECURITY_CONTEXT_ATTRIBUTE, authen); retry = false; } catch (LoginException e) { Error.show("Cannot login", e); @@ -69,16 +47,6 @@ public class SecureEntryPoint implements IEntryPoint, SessionStoreListener { } } - if (subject == null) { - // IStatus status = new Status(IStatus.ERROR, - // "org.argeo.security.application", "Login is mandatory", - // loginException); - // ErrorDialog.openError(null, "Error", "Shutdown...", status); - // return status.getSeverity(); - - // TODO: log as anonymous - } - if (subject != null) { returnCode = (Integer) Subject.doAs(subject, getRunAction(display)); @@ -88,20 +56,17 @@ public class SecureEntryPoint implements IEntryPoint, SessionStoreListener { return -1; } } catch (Exception e) { - // e.printStackTrace(); - IStatus status = new Status(IStatus.ERROR, - "org.argeo.security.rcp", "Login failed", e); - ErrorDialog.openError(null, "Error", "Shutdown...", status); - return returnCode; - } finally { - display.dispose(); - } + log.error("Unexpected error",e); + return -1; + } +// finally { +// display.dispose(); +// } } @SuppressWarnings("rawtypes") private PrivilegedAction getRunAction(final Display display) { return new PrivilegedAction() { - public Object run() { int result = createAndRunWorkbench(display); return new Integer(result);