66cabc4922ad92335896b805625ac7973c28f070
[gpl/argeo-suite.git] / org.argeo.suite.core / src / org / argeo / suite / core / SuiteMaintenanceService.java
1 package org.argeo.suite.core;
2
3 import java.io.IOException;
4
5 import javax.jcr.Node;
6 import javax.jcr.RepositoryException;
7 import javax.jcr.Session;
8 import javax.jcr.nodetype.NodeType;
9 import javax.jcr.security.Privilege;
10
11 import org.argeo.api.NodeConstants;
12 import org.argeo.entity.EntityType;
13 import org.argeo.jcr.JcrUtils;
14 import org.argeo.maintenance.AbstractMaintenanceService;
15 import org.argeo.suite.SuiteRole;
16
17 /** Initialises an Argeo Suite backend. */
18 public class SuiteMaintenanceService extends AbstractMaintenanceService {
19
20         @Override
21         public boolean prepareJcrTree(Session adminSession) throws RepositoryException, IOException {
22                 boolean modified = false;
23                 Node rootNode = adminSession.getRootNode();
24                 if (!rootNode.hasNode(EntityType.user.name())) {
25                         rootNode.addNode(EntityType.user.name(), NodeType.NT_UNSTRUCTURED);
26                         modified = true;
27                 }
28                 if (modified)
29                         adminSession.save();
30                 return modified;
31         }
32
33         @Override
34         public void configurePrivileges(Session adminSession) throws RepositoryException {
35                 JcrUtils.addPrivilege(adminSession, EntityType.user.basePath(), NodeConstants.ROLE_USER_ADMIN,
36                                 Privilege.JCR_ALL);
37                 //JcrUtils.addPrivilege(adminSession, "/", SuiteRole.coworker.dn(), Privilege.JCR_READ);
38         }
39
40 }