Search in sources :

Example 21 with BwPrincipal

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

the class Restore method createNewSystem.

private void createNewSystem() throws Throwable {
    // Create the public user.
    final BwPrincipal pu = BwPrincipal.makeUserPrincipal();
    pu.setAccount(BwPrincipal.publicUser);
    globals.setPrincipalHref(pu);
    globals.rintf.restorePrincipal(pu);
    // Create the root user.
    final BwPrincipal rootUser = BwPrincipal.makeUserPrincipal();
    rootUser.setAccount(rootId);
    globals.setPrincipalHref(rootUser);
    globals.rintf.restorePrincipal(rootUser);
    // Create the an authuser entry for the root user.
    final BwAuthUser au = new BwAuthUser();
    au.setUserHref(rootUser.getPrincipalRef());
    au.setUsertype(UserAuth.allAuth);
    au.setPrefs(BwAuthUserPrefs.makeAuthUserPrefs());
    globals.rintf.restoreAuthUser(au);
    // Create a group for all public admin groups
    final BwAdminGroup g = new BwAdminGroup();
    final String publicAdminGroupsAccount = // XXX Put into config
    "publicAdminGroups";
    g.setAccount(publicAdminGroupsAccount);
    g.setGroupOwnerHref(pu.getPrincipalRef());
    g.setOwnerHref(pu.getPrincipalRef());
    if (!globals.onlyUsersMap.check(g.getGroupOwnerHref())) {
        g.setGroupOwnerHref(globals.getPublicUser().getPrincipalRef());
    }
    globals.rintf.restoreAdminGroup(g);
    // Create the public root.
    final Collection<Privilege> privs = new ArrayList<>();
    privs.add(Privileges.makePriv(PrivilegeDefs.privRead));
    final Collection<Ace> aces = new ArrayList<>();
    aces.add(Ace.makeAce(AceWho.other, privs, null));
    privs.clear();
    privs.add(Privileges.makePriv(PrivilegeDefs.privRead));
    privs.add(Privileges.makePriv(PrivilegeDefs.privWriteContent));
    final AceWho who = AceWho.getAceWho(publicAdminGroupsAccount, WhoDefs.whoTypeGroup, false);
    aces.add(Ace.makeAce(who, privs, null));
    makeCal(null, pu, BwCalendar.calTypeFolder, RestoreGlobals.getBasicSyspars().getPublicCalendarRoot(), new String(new Acl(aces).encode()));
    // Create the user root.
    privs.clear();
    privs.add(Privileges.makePriv(PrivilegeDefs.privAll));
    aces.clear();
    aces.add(Ace.makeAce(AceWho.owner, privs, null));
    final BwCalendar userRoot = makeCal(null, pu, BwCalendar.calTypeFolder, RestoreGlobals.getBasicSyspars().getUserCalendarRoot(), new String(new Acl(aces).encode()));
    makeUserHome(userRoot, pu);
    makeUserHome(userRoot, rootUser);
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) Ace(org.bedework.access.Ace) BwPrincipal(org.bedework.calfacade.BwPrincipal) AceWho(org.bedework.access.AceWho) ArrayList(java.util.ArrayList) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) Acl(org.bedework.access.Acl) BwCalendar(org.bedework.calfacade.BwCalendar) Privilege(org.bedework.access.Privilege)

Example 22 with BwPrincipal

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

the class AdminGroupRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    final BwAdminGroup entity = (BwAdminGroup) pop();
    try {
        if (entity.getGroupOwnerHref() == null) {
            error("Missing group owner for admin group " + entity);
            return;
        }
        if (entity.getOwnerHref() == null) {
            error("Missing owner for admin group " + entity);
            return;
        }
        if (entity.getPrincipalRef() == null) {
            // Pre 3.5?
            globals.setPrincipalHref(entity);
        }
        globals.counts[globals.adminGroups]++;
        globals.principalsTbl.put(entity);
        if (globals.rintf != null) {
            globals.rintf.restoreAdminGroup(entity);
            /* Save members. */
            final Collection<BwPrincipal> c = entity.getGroupMembers();
            if (c == null) {
                return;
            }
            for (final BwPrincipal pr : c) {
                globals.rintf.addAdminGroupMember(entity, pr);
            }
        }
    } catch (final Throwable t) {
        error("Unable to restore admin group " + entity);
        throw new Exception(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 23 with BwPrincipal

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

the class BwDumpRestore method deleteUser.

@Override
public String deleteUser(final String account) {
    try {
        final CalSvcI svci = getSvci(getConfig().getAccount(), true);
        final BwPrincipal pr = svci.getUsersHandler().getUser(account);
        if (pr == null) {
            return "No principal for " + account;
        }
        svci.getUsersHandler().remove(pr);
        return "ok";
    } catch (final Throwable t) {
        error(t);
        return "Exception: " + t.getLocalizedMessage();
    } finally {
        try {
            closeSvci();
        } catch (final Throwable t) {
            error(t);
        }
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CalSvcI(org.bedework.calsvci.CalSvcI)

Example 24 with BwPrincipal

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

the class Dump method doDump.

/**
 * @throws Throwable on error
 */
public void doDump() throws Throwable {
    if (newDumpFormat) {
        // TODO - start a separate thread for public
        final DumpPublic dumpPub = new DumpPublic(globals);
        if (dumpPub.open()) {
            dumpPub.doDump();
            dumpPub.close();
        }
        final DumpSystem dumpSys = new DumpSystem(globals);
        if (dumpSys.open()) {
            dumpSys.doDump();
            dumpSys.close();
        }
        final DumpPrincipal dumpPr = new DumpPrincipal(globals);
        final Iterator<BwPrincipal> it = globals.di.getAllPrincipals();
        while (it.hasNext()) {
            final BwPrincipal pr = it.next();
            final String account = pr.getAccount().toLowerCase().trim();
            if (!account.equals(pr.getAccount())) {
                globals.info.addLn("WARNING: Principal " + pr + " has possible invalid account");
            }
            boolean open = false;
            try {
                if (dumpPr.open(pr)) {
                    open = true;
                    dumpPr.doDump();
                }
            } catch (final CalFacadeException cfe) {
                error(cfe);
            } finally {
                if (open) {
                    try {
                        dumpPr.close();
                    } catch (final CalFacadeException cfe) {
                        error(cfe);
                    }
                }
            }
        }
    } else {
        new DumpAll(globals).dumpSection(null);
        new DumpAliases(globals).dumpSection(null);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) DumpAliases(org.bedework.dumprestore.dump.dumpling.DumpAliases) DumpSystem(org.bedework.dumprestore.prdump.DumpSystem) DumpPublic(org.bedework.dumprestore.prdump.DumpPublic) DumpPrincipal(org.bedework.dumprestore.prdump.DumpPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException) DumpAll(org.bedework.dumprestore.dump.dumpling.DumpAll)

Example 25 with BwPrincipal

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

the class AbstractDirImpl method caladdrToPrincipal.

/* (non-Javadoc)
   * @see org.bedework.calfacade.ifs.Directories#caladdrToPrincipal(java.lang.String)
   */
@Override
public BwPrincipal caladdrToPrincipal(final String caladdr) throws CalFacadeException {
    try {
        if (caladdr == null) {
            throw new CalFacadeException(CalFacadeException.nullCalendarUserAddr);
        }
        BwPrincipal p = calAddrToPrincipalMap.get(caladdr);
        if (p != null) {
            return p;
        }
        // Ensure all set up
        getProps();
        if (isPrincipal(caladdr)) {
            p = getPrincipal(caladdr);
            calAddrToPrincipalMap.put(caladdr, p);
            return p;
        }
        String acc = null;
        String ca = caladdr;
        final int atPos = ca.indexOf("@");
        if (atPos > 0) {
            ca = ca.toLowerCase();
        }
        if (onlyDomain != null) {
            if (atPos < 0) {
                acc = ca;
            }
            if (onlyDomain.matches(ca, atPos)) {
                acc = ca.substring(0, atPos);
            }
        } else if (atPos < 0) {
            // Assume default domain?
            acc = ca;
        } else if (anyDomain) {
            acc = ca;
        } else {
            for (final DomainMatcher dm : domains) {
                if (dm.matches(ca, atPos)) {
                    acc = ca;
                    break;
                }
            }
        }
        if (acc == null) {
            // Not ours
            return null;
        }
        if (acc.toLowerCase().startsWith("mailto:")) {
            acc = acc.substring("mailto:".length());
        }
        // XXX -at this point we should validate the account
        int whoType = WhoDefs.whoTypeUser;
        for (CAPrefixInfo c : getCaPrefixInfo()) {
            if (acc.startsWith(c.getPrefix())) {
                whoType = c.getType();
                break;
            }
        }
        p = getPrincipal(makePrincipalUri(acc, whoType));
        calAddrToPrincipalMap.put(caladdr, p);
        return p;
    } catch (CalFacadeException cfe) {
        throw cfe;
    } catch (Throwable t) {
        throw new CalFacadeException(t);
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

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