Search in sources :

Example 6 with BwAdminGroup

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

the class MemberRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    /* Top should be the principal info, underneath is the actual entity -
     */
    PrincipalHref oi = (PrincipalHref) pop();
    try {
        if (oi.prefix == null) {
            error("Unable to handle principal type " + oi.getKind());
        }
        oi.href = Util.buildPath(false, oi.prefix, "/", oi.account);
    } catch (Throwable t) {
        error("Unable to get user principal root", t);
        return;
    }
    BwPrincipal pr = globals.principalsTbl.get(oi);
    if (top() instanceof BwGroup) {
        BwGroup gr = (BwGroup) top();
        if (pr == null) {
            if (gr instanceof BwAdminGroup) {
                ArrayList<PrincipalHref> m = globals.adminGroupMembers.get(gr.getAccount());
                if (m == null) {
                    m = new ArrayList<PrincipalHref>();
                    globals.adminGroupMembers.put(gr.getAccount(), m);
                }
                m.add(oi);
            } else {
                error("Cannot handle group " + gr);
            }
            return;
        }
        gr.addGroupMember(pr);
        return;
    }
    error("Unknown class for member " + top());
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwGroup(org.bedework.calfacade.BwGroup) PrincipalHref(org.bedework.dumprestore.restore.PrincipalHref) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 7 with BwAdminGroup

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

the class OwnerRule method end.

@Override
public void end(final String ns, final String name) throws Exception {
    error("OwnerRule called");
    BwPrincipal p = doPrincipal();
    if (top() instanceof OwnerUidKey) {
        OwnerUidKey key = (OwnerUidKey) top();
        key.setOwnerHref(p.getPrincipalRef());
        globals.inOwnerKey = false;
        return;
    }
    if (top() instanceof BwAdminGroup) {
        BwAdminGroup ag = (BwAdminGroup) top();
        if (name.equals("owner")) {
            ag.setOwnerHref(p.getPrincipalRef());
        } else if (name.equals("owner-key")) {
            // PRE3.5
            ag.setOwnerHref(p.getPrincipalRef());
        } else {
            ag.setGroupOwnerHref(p.getPrincipalRef());
        }
        globals.inOwnerKey = false;
        return;
    }
    BwOwnedDbentity o = null;
    if (top() == null) {
        error("Null stack top when setting owner.  Match: " + getDigester().getMatch());
        return;
    }
    if (top() instanceof EventInfo) {
        o = ((EventInfo) top()).getEvent();
    } else if (!(top() instanceof BwOwnedDbentity)) {
        if (top() instanceof BwOrganizer) {
        // No owner now
        } else if (top() instanceof BwView) {
        // No owner now
        } else if (top() instanceof SkipThis) {
        } else {
            // We expect organizer in old data
            warn("top() is not BwOwnedDbentity:" + top().getClass().getCanonicalName());
            warn("  match: " + getDigester().getMatch());
        }
        globals.inOwnerKey = false;
        return;
    } else {
        o = (BwOwnedDbentity) top();
    }
    o.setOwnerHref(p.getPrincipalRef());
    globals.inOwnerKey = false;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) EventInfo(org.bedework.calfacade.svc.EventInfo) BwOwnedDbentity(org.bedework.calfacade.base.BwOwnedDbentity) SkipThis(org.bedework.icalendar.IcalTranslator.SkipThis) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) OwnerUidKey(org.bedework.dumprestore.restore.OwnerUidKey) BwOrganizer(org.bedework.calfacade.BwOrganizer) BwView(org.bedework.calfacade.svc.BwView)

Example 8 with BwAdminGroup

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

the class CalSuites method wrap.

private BwCalSuiteWrapper wrap(final BwCalSuite cs, final boolean alwaysReturn) throws CalFacadeException {
    final CurrentAccess ca = checkAccess(cs, PrivilegeDefs.privAny, alwaysReturn);
    if ((ca == null) || !ca.getAccessAllowed()) {
        return null;
    }
    final BwCalSuiteWrapper w = new BwCalSuiteWrapper(cs, ca);
    final BwAdminGroup agrp = cs.getGroup();
    if (agrp == null) {
        return w;
    }
    final BwPrincipal eventsOwner = getSvc().getUsersHandler().getPrincipal(agrp.getOwnerHref());
    if (eventsOwner == null) {
        return w;
    }
    final BwCalendar home = getCols().getHome(eventsOwner, false);
    if (home == null) {
        return w;
    }
    w.setResourcesHome(home.getPath());
    return w;
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) CurrentAccess(org.bedework.access.Acl.CurrentAccess) BwCalSuiteWrapper(org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup) BwCalendar(org.bedework.calfacade.BwCalendar)

Example 9 with BwAdminGroup

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

the class ProcessAdd method addToAdminGroup.

private boolean addToAdminGroup(final String account) throws Throwable {
    if (debug) {
        debug("About to add member " + account + " to a group");
    }
    if (account == null) {
        pstate.addError("Must supply account");
        return false;
    }
    final String kind = word();
    final boolean group;
    if ("group".equals(kind)) {
        group = true;
    } else if ("user".equals(kind)) {
        group = false;
    } else {
        pstate.addError("Invalid kind: " + kind);
        return false;
    }
    if (!"to".equals(word())) {
        pstate.addError("Invalid syntax - expected 'to'");
        return false;
    }
    final String toGrp = wordOrQuotedVal();
    try {
        open();
        final BwAdminGroup grp = (BwAdminGroup) getSvci().getAdminDirectories().findGroup(toGrp);
        if (grp == null) {
            pstate.addError("Unknown group " + toGrp);
            return false;
        }
        if (grp.isMember(account, "group".equals(kind))) {
            pstate.addError("Already a member: " + account);
            return false;
        }
        final BwPrincipal nmbr = newMember(account, !group);
        getSvci().getAdminDirectories().addMember(grp, nmbr);
        getSvci().getAdminDirectories().updateGroup(grp);
        return true;
    } finally {
        close();
    }
}
Also used : BwPrincipal(org.bedework.calfacade.BwPrincipal) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Example 10 with BwAdminGroup

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

the class ProcessCalsuite method process.

@Override
boolean process() throws Throwable {
    final String wd = word();
    if (wd == null) {
        return false;
    }
    if ("help".equals(wd)) {
        pstate.addInfo("calsuite <name>\n" + "   switch to event owner for calsuite\n" + "calsuite <name> addapprover <account>\n" + "   add an approver\n" + "calsuite <name> remapprover <account>\n" + "   remove an approver");
        return true;
    }
    final String account;
    try {
        open();
        final BwCalSuite cs = getSvci().getCalSuitesHandler().get(wd);
        if (cs == null) {
            error("No calsuite with name " + wd);
            return true;
        }
        final BwAdminGroup adminGrp = cs.getGroup();
        if (adminGrp == null) {
            error("No admin group for calsuite " + wd);
            return true;
        }
        final String ownerHref = adminGrp.getOwnerHref();
        if (ownerHref == null) {
            error("No owner href in admin group " + adminGrp + " for calsuite " + wd);
            return true;
        }
        final BwPrincipal ownerPr = getSvci().getPrincipal(ownerHref);
        if (ownerPr == null) {
            error("No user with owner href " + ownerHref + " in admin group " + adminGrp + " for calsuite " + wd);
            return true;
        }
        final String action = word();
        account = ownerPr.getAccount();
        if (action == null) {
            pstate.setCalsuite(cs);
            return true;
        }
        final boolean addAppprover = "addapprover".equals(action);
        if (!addAppprover && !"remapprover".equals(action)) {
            error("Expected addapprover or remapprover");
            return false;
        }
        final String appAccount = word();
        if (appAccount == null) {
            error("Expected an account");
        }
        final BwPreferences prefs = getSvci().getPrefsHandler().get(ownerPr);
        final List<String> approvers = prefs.getCalsuiteApproversList();
        if (Util.isEmpty(approvers)) {
            if (addAppprover) {
                prefs.setCalsuiteApprovers(appAccount);
            }
        } else {
            if (addAppprover) {
                if (!approvers.contains(appAccount)) {
                    approvers.add(appAccount);
                }
            } else {
                approvers.remove(appAccount);
            }
            prefs.setCalsuiteApprovers(String.join(",", approvers));
        }
        getSvci().getPrefsHandler().update(prefs);
    } finally {
        close();
    }
    setUser(account, false);
    return true;
}
Also used : BwCalSuite(org.bedework.calfacade.svc.BwCalSuite) BwPrincipal(org.bedework.calfacade.BwPrincipal) BwPreferences(org.bedework.calfacade.svc.BwPreferences) BwAdminGroup(org.bedework.calfacade.svc.BwAdminGroup)

Aggregations

BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)11 BwPrincipal (org.bedework.calfacade.BwPrincipal)10 BwCalendar (org.bedework.calfacade.BwCalendar)3 ArrayList (java.util.ArrayList)2 Ace (org.bedework.access.Ace)2 Acl (org.bedework.access.Acl)2 Privilege (org.bedework.access.Privilege)2 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)2 BwCalSuiteWrapper (org.bedework.calfacade.svc.wrappers.BwCalSuiteWrapper)2 URI (java.net.URI)1 AccessException (org.bedework.access.AccessException)1 AceWho (org.bedework.access.AceWho)1 CurrentAccess (org.bedework.access.Acl.CurrentAccess)1 BwGroup (org.bedework.calfacade.BwGroup)1 BwOrganizer (org.bedework.calfacade.BwOrganizer)1 DirectoryInfo (org.bedework.calfacade.DirectoryInfo)1 BwOwnedDbentity (org.bedework.calfacade.base.BwOwnedDbentity)1 BwAuthUser (org.bedework.calfacade.svc.BwAuthUser)1 BwCalSuite (org.bedework.calfacade.svc.BwCalSuite)1 BwPreferences (org.bedework.calfacade.svc.BwPreferences)1