private void createDefaultPages(User managedUser) { // Create profile page pageRepository.createPageForUser( managedUser, pageTemplateRepository.getDefaultPage(PageType.PERSON_PROFILE)); // Create default page set try { JSONArray obj = new JSONArray(messages.getMessage("user.pages.json", null, null, null)); for (int i = 0; i < obj.length(); i++) { JSONObject o = obj.getJSONObject(i); Page page = pageRepository.createPageForUser( managedUser, pageTemplateRepository.getDefaultPage(PageType.USER)); page.setName(o.getString("pName")); page.setPageLayout(pageLayoutRepository.getByPageLayoutCode(o.getString("layout"))); pageRepository.save(page); } } catch (JSONException ex) { LOG.log(Level.SEVERE, null, ex); } String storageUrl = cmisBaseUrl + "/_" + HttpUtils.generateId(managedUser.getUsername()); PersonPropertyImpl pp = new PersonPropertyImpl(); pp.setType("urls"); pp.setValue("storageUrl: " + storageUrl); managedUser.getProperties().add(pp); }
protected void createUserHome(String userId) { LOG.log(Level.FINE, "Checking home folders for {0}", userId); try { if (repo == null) { LOG.log(Level.FINE, "Repo is null. Exiting"); return; } Session sess = this.repo.login(new SimpleCredentials("admin", new char[0])); String userRoot = "/users/_" + HttpUtils.generateId(userId); String[] folders = new String[] { userRoot + "/Inbox", userRoot + "/Drafts", userRoot + "/Trash", userRoot + "/Sent", userRoot + "/Archive" }; boolean needCreate = false; for (String fld : folders) { if (!sess.nodeExists(fld)) { needCreate = true; break; } } if (!needCreate) { sess.logout(); return; } for (String fld : folders) { if (!sess.nodeExists(fld)) { JcrUtils.getOrCreateByPath(fld, NodeType.NT_FOLDER, sess); } } sess.save(); AccessControlManager aMgr = sess.getAccessControlManager(); // create a privilege set with jcr:all Privilege[] privileges = new Privilege[] {aMgr.privilegeFromName(Privilege.JCR_ALL)}; AccessControlList acl; try { // get first applicable policy (for nodes w/o a policy) acl = (AccessControlList) aMgr.getApplicablePolicies(userRoot).nextAccessControlPolicy(); } catch (NoSuchElementException e) { // else node already has a policy, get that one acl = (AccessControlList) aMgr.getPolicies(userRoot)[0]; } // remove all existing entries for (AccessControlEntry e : acl.getAccessControlEntries()) { acl.removeAccessControlEntry(e); } // add a new one for a principal acl.addAccessControlEntry(new PrincipalImpl(userId), privileges); // the policy must be re-set aMgr.setPolicy(userRoot, acl); sess.save(); sess.logout(); LOG.log(Level.FINE, "Home folders created for {0}", userId); } catch (Exception e) { LOG.log(Level.FINE, null, e); } }