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
.connect
.SystemMaintenanceService
;
15 import org
.argeo
.jcr
.JcrUtils
;
16 import org
.argeo
.node
.NodeConstants
;
17 import org
.argeo
.suite
.ArgeoSuiteRole
;
18 import org
.argeo
.suite
.SuiteException
;
20 /** Make the DJay-ing to provide a full running Suite platform */
21 public class DefaultSuiteMaintenanceService
implements SystemMaintenanceService
{
22 private final static Log log
= LogFactory
.getLog(DefaultSuiteMaintenanceService
.class);
24 /* DEPENDENCY INJECTION */
25 private Repository repository
;
26 private String workspaceName
;
27 private List
<AppMaintenanceService
> maintenanceServices
;
30 Session adminSession
= null;
32 adminSession
= repository
.login(workspaceName
);
33 if (prepareJcrTree(adminSession
)) {
34 configurePrivileges(adminSession
);
36 } catch (Exception e
) {
37 throw new SuiteException("Cannot initialise model", e
);
39 JcrUtils
.logoutQuietly(adminSession
);
43 // TODO Hard-coded model initialisation
44 // To be cleaned once first init and config mechanisms have been implemented
45 private final static String publicPath
= "/public";
46 // FIXME Users must have read access on the jcr:system/jcr:versionStorage
47 // node under JackRabbit to be able to manage versions
48 private final static String jackRabbitVersionSystemPath
= "/jcr:system";
51 public boolean prepareJcrTree(Session session
) {
52 boolean hasCHanged
= false;
54 JcrUtils
.mkdirs(session
, publicPath
, NodeType
.NT_UNSTRUCTURED
);
55 if (session
.hasPendingChanges()) {
59 } catch (RepositoryException e
) {
60 throw new SuiteException("Cannot build model", e
);
62 for (AppMaintenanceService service
: maintenanceServices
)
63 hasCHanged
|= service
.prepareJcrTree(session
);
65 log
.info("Repository has been initialised with Argeo Suite model");
70 public void configurePrivileges(Session session
) {
72 // Remove unused default JCR rights
73 JcrUtils
.clearAccessControList(session
, "/", "everyone");
75 JcrUtils
.addPrivilege(session
, jackRabbitVersionSystemPath
, ArgeoSuiteRole
.coworker
.dn(),
77 // Default configuration of the workspace
78 JcrUtils
.addPrivilege(session
, "/", NodeConstants
.ROLE_ADMIN
, Privilege
.JCR_ALL
);
79 JcrUtils
.addPrivilege(session
, publicPath
, NodeConstants
.ROLE_USER
, Privilege
.JCR_READ
);
80 JcrUtils
.addPrivilege(session
, publicPath
, "anonymous", Privilege
.JCR_READ
);
81 JcrUtils
.addPrivilege(session
, publicPath
, NodeConstants
.ROLE_ANONYMOUS
, Privilege
.JCR_READ
);
84 } catch (RepositoryException e
) {
85 throw new SuiteException("Cannot build model", e
);
87 for (AppMaintenanceService service
: maintenanceServices
)
88 service
.configurePrivileges(session
);
89 log
.info("Access control configured");
92 public void destroy() {
95 /* DEPENDENCY INJECTION */
96 public void setRepository(Repository repository
) {
97 this.repository
= repository
;
100 public void setWorkspaceName(String workspaceName
) {
101 this.workspaceName
= workspaceName
;
104 public void setMaintenanceServices(List
<AppMaintenanceService
> maintenanceServices
) {
105 this.maintenanceServices
= maintenanceServices
;