X-Git-Url: http://git.argeo.org/?a=blobdiff_plain;f=org.argeo.cms%2Fsrc%2Forg%2Fargeo%2Fcms%2FAbstractCmsEntryPoint.java;h=951e177b2473f0d5b81b03b1e2532ed2837a2b85;hb=cf02d7afd63e6bbef9f7a88ee9674c27ff843d79;hp=9a7f6412e862a5b219df558932fe5b6952606f92;hpb=ba85380c1db977b0d9ea3182d1383956a8b80679;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java index 9a7f6412e..951e177b2 100644 --- a/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java +++ b/org.argeo.cms/src/org/argeo/cms/AbstractCmsEntryPoint.java @@ -1,5 +1,6 @@ package org.argeo.cms; +import java.security.PrivilegedAction; import java.util.HashMap; import java.util.Locale; import java.util.Map; @@ -67,8 +68,8 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_USER, subject) .login(); } catch (LoginException e) { - if (log.isTraceEnabled()) - log.trace("Cannot authenticate user", e); + // if (log.isTraceEnabled()) + // log.trace("Cannot authenticate user", e); try { new ArgeoLoginContext(KernelHeader.LOGIN_CONTEXT_ANONYMOUS, subject).login(); @@ -103,14 +104,20 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint } @Override - protected final void createContents(Composite parent) { - try { - getShell().getDisplay().setData(CmsSession.KEY, this); - - createUi(parent); - } catch (Exception e) { - throw new CmsException("Cannot create entrypoint contents", e); - } + protected final void createContents(final Composite parent) { + getShell().getDisplay().setData(CmsSession.KEY, this); + Subject.doAs(subject, new PrivilegedAction() { + @Override + public Void run() { + try { + createUi(parent); + } catch (Exception e) { + throw new CmsException("Cannot create entrypoint contents", + e); + } + return null; + } + }); } /** Create UI */ @@ -140,7 +147,7 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint public void navigateTo(String state) { exception = null; String title = setState(state); - refresh(); + doRefresh(); if (browserNavigation != null) browserNavigation.pushState(state, title); } @@ -152,29 +159,66 @@ public abstract class AbstractCmsEntryPoint extends AbstractEntryPoint @Override public void authChange() { - try { - String currentPath = null; - if (node != null) - currentPath = node.getPath(); - JcrUtils.logoutQuietly(session); + Subject.doAs(subject, new PrivilegedAction() { - session = repository.login(workspace); - if (currentPath != null) - node = session.getNode(currentPath); + @Override + public Void run() { + try { + String currentPath = null; + if (node != null) + currentPath = node.getPath(); + JcrUtils.logoutQuietly(session); + + session = repository.login(workspace); + if (currentPath != null) + try { + node = session.getNode(currentPath); + } catch (Exception e) { + try { + // TODO find a less hacky way to log out + new ArgeoLoginContext( + KernelHeader.LOGIN_CONTEXT_ANONYMOUS, + subject).logout(); + new ArgeoLoginContext( + KernelHeader.LOGIN_CONTEXT_ANONYMOUS, + subject).login(); + } catch (LoginException eAnonymous) { + throw new ArgeoException( + "Cannot reset to anonymous", eAnonymous); + } + JcrUtils.logoutQuietly(session); + session = repository.login(workspace); + navigateTo("~"); + throw e; + } + + // refresh UI + doRefresh(); + } catch (RepositoryException e) { + throw new CmsException("Cannot perform auth change", e); + } + return null; + } - // refresh UI - refresh(); - } catch (RepositoryException e) { - throw new CmsException("Cannot perform auth change", e); - } + }); } @Override - public void exception(Throwable e) { - this.exception = e; + public void exception(final Throwable e) { + AbstractCmsEntryPoint.this.exception = e; log.error("Unexpected exception in CMS", e); - refresh(); + doRefresh(); + } + + protected void doRefresh() { + Subject.doAs(subject, new PrivilegedAction() { + @Override + public Void run() { + refresh(); + return null; + } + }); } @Override