1 package org
.argeo
.suite
.core
;
5 import javax
.jcr
.Repository
;
6 import javax
.jcr
.RepositoryException
;
7 import javax
.jcr
.Session
;
8 import javax
.jcr
.nodetype
.NodeType
;
9 import javax
.jcr
.security
.Privilege
;
11 import org
.apache
.commons
.logging
.Log
;
12 import org
.apache
.commons
.logging
.LogFactory
;
13 import org
.argeo
.connect
.AppMaintenanceService
;
14 import org
.argeo
.jcr
.JcrUtils
;
15 import org
.argeo
.node
.NodeConstants
;
16 import org
.argeo
.suite
.ArgeoSuiteRole
;
17 import org
.argeo
.suite
.SuiteException
;
19 /** Make the DJay-ing to provide a full running Suite platform */
20 public class DefaultSuiteMaintenanceService
implements AppMaintenanceService
{
21 private final static Log log
= LogFactory
.getLog(DefaultSuiteMaintenanceService
.class);
23 /* DEPENDENCY INJECTION */
24 private Repository repository
;
25 private String workspaceName
;
26 private List
<AppMaintenanceService
> maintenanceServices
;
29 Session adminSession
= null;
31 adminSession
= repository
.login(workspaceName
);
32 if (prepareJcrTree(adminSession
)) {
33 configurePrivileges(adminSession
);
35 } catch (Exception e
) {
36 throw new SuiteException("Cannot initialise model", e
);
38 JcrUtils
.logoutQuietly(adminSession
);
42 // TODO Hard-coded model initialisation
43 // To be cleaned once first init and config mechanisms have been implemented
44 private final static String publicPath
= "/public";
45 // FIXME Users must have read access on the jcr:system/jcr:versionStorage
46 // node under JackRabbit to be able to manage versions
47 private final static String jackRabbitVersionSystemPath
= "/jcr:system";
50 public boolean prepareJcrTree(Session session
) {
51 boolean hasCHanged
= false;
53 JcrUtils
.mkdirs(session
, publicPath
, NodeType
.NT_UNSTRUCTURED
);
54 if (session
.hasPendingChanges()) {
58 } catch (RepositoryException e
) {
59 throw new SuiteException("Cannot build model", e
);
61 for (AppMaintenanceService service
: maintenanceServices
)
62 hasCHanged
|= service
.prepareJcrTree(session
);
64 log
.info("Repository has been initialised with Argeo Suite model");
69 public void configurePrivileges(Session session
) {
71 // Remove unused default JCR rights
72 JcrUtils
.clearAccessControList(session
, "/", "everyone");
74 JcrUtils
.addPrivilege(session
, jackRabbitVersionSystemPath
, ArgeoSuiteRole
.coworker
.dn(),
76 // Default configuration of the workspace
77 JcrUtils
.addPrivilege(session
, "/", NodeConstants
.ROLE_ADMIN
, Privilege
.JCR_ALL
);
78 JcrUtils
.addPrivilege(session
, publicPath
, NodeConstants
.ROLE_USER
, Privilege
.JCR_READ
);
79 JcrUtils
.addPrivilege(session
, publicPath
, "anonymous", Privilege
.JCR_READ
);
80 JcrUtils
.addPrivilege(session
, publicPath
, NodeConstants
.ROLE_ANONYMOUS
, Privilege
.JCR_READ
);
83 } catch (RepositoryException e
) {
84 throw new SuiteException("Cannot build model", e
);
86 for (AppMaintenanceService service
: maintenanceServices
)
87 service
.configurePrivileges(session
);
88 log
.info("Access control configured");
91 public void destroy() {
94 /* DEPENDENCY INJECTION */
95 public void setRepository(Repository repository
) {
96 this.repository
= repository
;
99 public void setWorkspaceName(String workspaceName
) {
100 this.workspaceName
= workspaceName
;
103 public void setMaintenanceServices(List
<AppMaintenanceService
> maintenanceServices
) {
104 this.maintenanceServices
= maintenanceServices
;