From: Mathieu Baudier Date: Mon, 14 May 2018 13:20:57 +0000 (+0200) Subject: Make sure home has been created X-Git-Tag: argeo-suite-2.1.13~34 X-Git-Url: https://git.argeo.org/?p=gpl%2Fargeo-suite.git;a=commitdiff_plain;h=95acdff32f2404dca9ee34c9a3978cb38a8d07d4 Make sure home has been created --- diff --git a/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java b/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java index 3262311..0b2d152 100644 --- a/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java +++ b/org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java @@ -4,6 +4,7 @@ import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; import javax.inject.Inject; +import javax.inject.Named; import javax.jcr.Node; import javax.jcr.Repository; import javax.jcr.RepositoryException; @@ -22,6 +23,7 @@ public class ArgeoSuiteLoginLifecycle extends CmsLoginLifecycle { SystemWorkbenchService systemWorkbenchService; @Inject + @Named("(cn=home)") Repository repository; @Override @@ -36,31 +38,33 @@ public class ArgeoSuiteLoginLifecycle extends CmsLoginLifecycle { private void loadState() { String state = getState(); - if (state != null && state.startsWith("/")) { - Session session = null; - try { - Subject subject = getSubject(); - session = Subject.doAs(subject, new PrivilegedExceptionAction() { + // for the time being we systematically open a session, in order to make sure + // that home is initialised + Session session = null; + try { + Subject subject = getSubject(); + session = Subject.doAs(subject, new PrivilegedExceptionAction() { - @Override - public Session run() throws PrivilegedActionException { - try { - return repository.login(); - } catch (RepositoryException e) { - throw new PrivilegedActionException(e); - } + @Override + public Session run() throws PrivilegedActionException { + try { + return repository.login(); + } catch (RepositoryException e) { + throw new PrivilegedActionException(e); } + } - }); + }); + if (state != null && state.startsWith("/")) { if (state.startsWith("/")) { Node node = session.getNode(state); systemWorkbenchService.openEntityEditor(node); } - } catch (RepositoryException | PrivilegedActionException e) { - log.error("Cannot load state " + state, e); - } finally { - JcrUtils.logoutQuietly(session); } + } catch (RepositoryException | PrivilegedActionException e) { + log.error("Cannot load state " + state, e); + } finally { + JcrUtils.logoutQuietly(session); } } }