1 package org
.argeo
.suite
.e4
.rap
;
3 import java
.security
.PrivilegedActionException
;
4 import java
.security
.PrivilegedExceptionAction
;
6 import javax
.inject
.Inject
;
8 import javax
.jcr
.Repository
;
9 import javax
.jcr
.RepositoryException
;
10 import javax
.jcr
.Session
;
11 import javax
.security
.auth
.Subject
;
13 import org
.apache
.commons
.logging
.Log
;
14 import org
.apache
.commons
.logging
.LogFactory
;
15 import org
.argeo
.cms
.e4
.rap
.CmsLoginLifecycle
;
16 import org
.argeo
.connect
.ui
.SystemWorkbenchService
;
17 import org
.argeo
.jcr
.JcrUtils
;
19 /** Extends the CMS login lifecycle by managing the state of the current context. */
20 public class ArgeoSuiteLoginLifecycle
extends CmsLoginLifecycle
{
21 private final static Log log
= LogFactory
.getLog(ArgeoSuiteLoginLifecycle
.class);
23 SystemWorkbenchService systemWorkbenchService
;
26 Repository repository
;
29 protected void startupComplete() {
34 protected void stateChanged() {
38 private void loadState() {
39 String state
= getState();
40 // for the time being we systematically open a session, in order to make sure
41 // that home is initialised
42 Session session
= null;
44 if (state
!= null && state
.startsWith("/")) {
45 String path
= state
.substring(1);
47 if (path
.equals("")) {
51 int index
= path
.indexOf('/');
53 log
.error("Cannot interpret // " + state
);
54 getBrowserNavigation().pushState("~", null);
56 } else if (index
> 0) {
57 workspace
= path
.substring(0, index
);
58 path
= path
.substring(index
);
59 } else {// index<0, assuming root node
64 Subject subject
= getSubject();
65 session
= Subject
.doAs(subject
, new PrivilegedExceptionAction
<Session
>() {
68 public Session
run() throws PrivilegedActionException
{
70 return repository
.login(workspace
);
71 } catch (RepositoryException e
) {
72 throw new PrivilegedActionException(e
);
77 Node node
= session
.getNode(path
);
78 systemWorkbenchService
.openEntityEditor(node
);
80 } catch (RepositoryException
| PrivilegedActionException e
) {
81 log
.error("Cannot load state " + state
, e
);
82 getBrowserNavigation().pushState("~", null);
84 JcrUtils
.logoutQuietly(session
);