Search in sources :

Example 16 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.

the class BwSysIntfImpl method getCalPrincipalInfo.

private CalPrincipalInfo getCalPrincipalInfo(final BwPrincipalInfo pi) throws WebdavException {
    try {
        // SCHEDULE - just get home path and get default cal from user prefs.
        String userHomePath = Util.buildPath(false, "/", basicSysProperties.getUserCalendarRoot());
        if (pi.getPrincipalHref() == null) {
            return new CalPrincipalInfo(null, pi.getCard(), pi.getCardStr(), // userHomePath,
            null, // defaultCalendarPath,
            null, // inboxPath,
            null, // outboxPath,
            null, // notificationsPath,
            null, 0);
        }
        final BwPrincipal p = getSvci().getDirectories().getPrincipal(pi.getPrincipalHref());
        if (pi.getPrincipalHref().startsWith(BwPrincipal.userPrincipalRoot)) {
            userHomePath = Util.buildPath(true, userHomePath, pi.getPrincipalHref().substring(BwPrincipal.userPrincipalRoot.length()));
        } else {
            userHomePath = Util.buildPath(true, userHomePath, pi.getPrincipalHref());
        }
        final String defaultCalendarPath = Util.buildPath(true, userHomePath + basicSysProperties.getUserDefaultCalendar());
        final String inboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserInbox());
        final String outboxPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getUserOutbox());
        final String notificationsPath = Util.buildPath(true, userHomePath, "/", basicSysProperties.getDefaultNotificationsName());
        return new CalPrincipalInfo(p, pi.getCard(), pi.getCardStr(), userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, 0);
    } catch (final Throwable t) {
        throw new WebdavException(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) WebdavException(org.bedework.webdav.servlet.shared.WebdavException) CalPrincipalInfo(org.bedework.caldav.server.sysinterface.CalPrincipalInfo)

Example 17 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.

the class Notifier method adminGroupOwners.

private void adminGroupOwners(final Set<String> hrefs, final Collection<? extends BwPrincipal> prs) throws CalFacadeException {
    if (Util.isEmpty(prs)) {
        return;
    }
    for (final BwPrincipal pr : prs) {
        if (pr instanceof BwAdminGroup) {
            final BwAdminGroup adGrp = (BwAdminGroup) pr;
            hrefs.add(adGrp.getOwnerHref());
            adminGroupOwners(hrefs, adGrp.getGroupMembers());
        }
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 18 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.

the class AccessUtil method getAclChars.

/* ====================================================================
   *                   Private methods
   * ==================================================================== */
/* If the entity is not a collection we merge the access in with the container
   * access then return the merged aces. We do this because we call getPathInfo
   * with a collection entity. That method will recurse up to the root.
   *
   * For a calendar we just use the access for the calendar.
   *
   * The calendar/container access might be cached in the pathInfoTable.
   */
private char[] getAclChars(final BwShareableDbentity<?> ent) throws CalFacadeException {
    if ((!(ent instanceof BwEventProperty)) && (ent instanceof BwShareableContainedDbentity)) {
        BwCalendar container;
        if (ent instanceof BwCalendar) {
            container = (BwCalendar) ent;
        } else {
            container = getParent((BwShareableContainedDbentity<?>) ent);
        }
        if (container == null) {
            return null;
        }
        final String path = container.getPath();
        CalendarWrapper wcol = (CalendarWrapper) container;
        String aclStr;
        char[] aclChars = null;
        /* Get access for the parent first if we have one */
        BwCalendar parent = getParent(wcol);
        if (parent != null) {
            aclStr = new String(merged(getAclChars(parent), parent.getPath(), wcol.getAccess()));
        } else if (wcol.getAccess() != null) {
            aclStr = wcol.getAccess();
        } else {
            // At root
            throw new CalFacadeException("Collections must have default access set at root");
        }
        if (aclStr != null) {
            aclChars = aclStr.toCharArray();
        }
        if (ent instanceof BwCalendar) {
            return aclChars;
        }
        return merged(aclChars, path, ent.getAccess());
    }
    /* This is a way of making other objects sort of shareable.
     * The objects are locations, sponsors and categories.
     * (also calsuite)
     *
     * We store the default access in the owner principal and manipulate that to give
     * us some degree of sharing.
     *
     * In effect, the owner becomes the container for the object.
     */
    String aclString = null;
    String entAccess = ent.getAccess();
    BwPrincipal owner = (BwPrincipal) cb.getPrincipal(ent.getOwnerHref());
    if (ent instanceof BwCategory) {
        aclString = owner.getCategoryAccess();
    } else if (ent instanceof BwLocation) {
        aclString = owner.getLocationAccess();
    } else if (ent instanceof BwContact) {
        aclString = owner.getContactAccess();
    }
    if (aclString == null) {
        if (entAccess == null) {
            if (ent.getPublick()) {
                return Access.getDefaultPublicAccess().toCharArray();
            }
            return Access.getDefaultPersonalAccess().toCharArray();
        }
        return entAccess.toCharArray();
    }
    if (entAccess == null) {
        return aclString.toCharArray();
    }
    try {
        Acl acl = Acl.decode(entAccess.toCharArray());
        acl = acl.merge(aclString.toCharArray(), "/owner");
        return acl.getEncoded();
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwLocation(org.bedework.calfacade.BwLocation) BwShareableContainedDbentity(org.bedework.calfacade.base.BwShareableContainedDbentity) BwCategory(org.bedework.calfacade.BwCategory) BwEventProperty(org.bedework.calfacade.BwEventProperty) BwCalendar(org.bedework.calfacade.BwCalendar) BwContact(org.bedework.calfacade.BwContact) Acl(org.bedework.access.Acl) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) BwPrincipal(org.bedework.calfacade.BwPrincipal) CalendarWrapper(org.bedework.calfacade.wrappers.CalendarWrapper)

Example 19 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.

the class RestorePublic method doRestore.

/**
 * Restore everything owned by this principal
 *
 * @throws CalFacadeException on error
 */
public boolean doRestore() throws CalFacadeException {
    try {
        final String prPath = topPath();
        final File pdir = Utils.directory(prPath);
        if (pdir == null) {
            addInfo("No user data found at " + prPath);
            return false;
        }
        restoreCategories();
        restoreContacts();
        restoreLocations();
        restoreCollections();
        /* Restore all the admin groups
       */
        final Path agDirPath = openDir(Defs.adminGroupsDirName);
        if (agDirPath == null) {
            info("No admin groups data");
            return false;
        }
        final File agDir = agDirPath.toFile();
        if ((agDir == null) || !agDir.exists() || !agDir.isDirectory()) {
            info("No admin groups data");
            return false;
        }
        final String[] agDirs = agDir.list();
        if ((agDirs == null) || (agDirs.length == 0)) {
            info("No admin groups data");
            return false;
        }
        for (final String agp : agDirs) {
            final BwPrincipal userPr = BwPrincipal.makeUserPrincipal();
            userPr.setAccount(agp);
            userPr.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, RestoreGlobals.getUserPrincipalRoot(), "/", agp));
            globals.setPrincipalHref(userPr);
            try (RestorePrincipal restorer = new RestorePrincipal(globals)) {
                restorer.open(userPr);
                restorer.doRestore();
            }
        }
    } catch (final CalFacadeException ce) {
        throw ce;
    } catch (final Throwable t) {
        throw new CalFacadeException(t);
    }
    return true;
}
Also used : Path(java.nio.file.Path) BwPrincipal(org.bedework.calfacade.BwPrincipal) File(java.io.File) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Example 20 with BwPrincipal

use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.

the class Restore method restoreUser.

/**
 * Restore a single user from a new style dump.
 *
 * @param account of user
 * @param merge don't replace entities - add new ones.
 * @param info - to track status
 * @return true if restored - otherwise there's a message
 * @throws CalFacadeException on error
 */
public boolean restoreUser(final String account, final boolean merge, final boolean dryRun, final InfoLines info) throws CalFacadeException {
    globals.setRoots(getSvci());
    final BwPrincipal userPr = BwPrincipal.makeUserPrincipal();
    userPr.setAccount(account);
    userPr.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, RestoreGlobals.getUserPrincipalRoot(), "/", account));
    globals.info = info;
    globals.setPrincipalHref(userPr);
    globals.setMerging(merge);
    globals.setDryRun(dryRun);
    try (RestorePrincipal restorer = new RestorePrincipal(globals)) {
        restorer.open(userPr);
        restorer.doRestore();
    }
    return true;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) RestorePrincipal(org.bedework.dumprestore.nrestore.RestorePrincipal)

Aggregations

BwPrincipal (org.bedework.calfacade.BwPrincipal)59 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)22 BwCalendar (org.bedework.calfacade.BwCalendar)16 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)10 EventInfo (org.bedework.calfacade.svc.EventInfo)9 BwEvent (org.bedework.calfacade.BwEvent)7 ArrayList (java.util.ArrayList)6 BwPreferences (org.bedework.calfacade.svc.BwPreferences)6 Acl (org.bedework.access.Acl)5 BwGroup (org.bedework.calfacade.BwGroup)4 Component (net.fortuna.ical4j.model.Component)3 AccessException (org.bedework.access.AccessException)3 Ace (org.bedework.access.Ace)3 Privilege (org.bedework.access.Privilege)3 BwOrganizer (org.bedework.calfacade.BwOrganizer)3 WebdavException (org.bedework.webdav.servlet.shared.WebdavException)3 File (java.io.File)2 Collection (java.util.Collection)2 NamingEnumeration (javax.naming.NamingEnumeration)2 Attribute (javax.naming.directory.Attribute)2