]> git.argeo.org Git - gpl/argeo-suite.git/blob - org.argeo.suite.e4.rap/src/org/argeo/suite/e4/rap/ArgeoSuiteLoginLifecycle.java
Mark bundle as singleton
[gpl/argeo-suite.git] / org.argeo.suite.e4.rap / src / org / argeo / suite / e4 / rap / ArgeoSuiteLoginLifecycle.java
1 package org.argeo.suite.e4.rap;
2
3 import java.security.PrivilegedActionException;
4 import java.security.PrivilegedExceptionAction;
5
6 import javax.inject.Inject;
7 import javax.inject.Named;
8 import javax.jcr.Node;
9 import javax.jcr.Repository;
10 import javax.jcr.RepositoryException;
11 import javax.jcr.Session;
12 import javax.security.auth.Subject;
13
14 import org.apache.commons.logging.Log;
15 import org.apache.commons.logging.LogFactory;
16 import org.argeo.cms.e4.rap.CmsLoginLifecycle;
17 import org.argeo.connect.ui.SystemWorkbenchService;
18 import org.argeo.jcr.JcrUtils;
19
20 public class ArgeoSuiteLoginLifecycle extends CmsLoginLifecycle {
21 private final static Log log = LogFactory.getLog(ArgeoSuiteLoginLifecycle.class);
22 @Inject
23 SystemWorkbenchService systemWorkbenchService;
24
25 @Inject
26 @Named("(cn=home)")
27 Repository repository;
28
29 @Override
30 protected void startupComplete() {
31 loadState();
32 }
33
34 @Override
35 protected void stateChanged() {
36 loadState();
37 }
38
39 private void loadState() {
40 String state = getState();
41 // for the time being we systematically open a session, in order to make sure
42 // that home is initialised
43 Session session = null;
44 try {
45 Subject subject = getSubject();
46 session = Subject.doAs(subject, new PrivilegedExceptionAction<Session>() {
47
48 @Override
49 public Session run() throws PrivilegedActionException {
50 try {
51 return repository.login();
52 } catch (RepositoryException e) {
53 throw new PrivilegedActionException(e);
54 }
55 }
56
57 });
58 if (state != null && state.startsWith("/")) {
59 if (state.startsWith("/")) {
60 Node node = session.getNode(state);
61 systemWorkbenchService.openEntityEditor(node);
62 }
63 }
64 } catch (RepositoryException | PrivilegedActionException e) {
65 log.error("Cannot load state " + state, e);
66 getBrowserNavigation().pushState("~", null);
67 } finally {
68 JcrUtils.logoutQuietly(session);
69 }
70 }
71 }