Search in sources :

Example 1 with BwAuthUser

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

the class Preferences method updateAdminPrefs.

/* (non-Javadoc)
   * @see org.bedework.calsvci.PreferencesI#updateAdminPrefs(boolean, org.bedework.calfacade.BwCalendar, org.bedework.calfacade.BwCategory, org.bedework.calfacade.BwLocation, org.bedework.calfacade.BwContact)
   */
public void updateAdminPrefs(final boolean remove, final BwCalendar cal, final Collection<BwCategory> cats, final BwLocation loc, final BwContact ctct) throws CalFacadeException {
    BwCommonUserPrefs prefs = null;
    boolean update = false;
    BwAuthUser au = null;
    if (getPars().getPublicAdmin()) {
        au = getSvc().getUserAuth().getUser(getPars().getAuthUser());
        if (au != null) {
            prefs = au.getPrefs();
        }
    }
    if (prefs == null) {
        // XXX until we get non admin user preferred calendars etc
        return;
    }
    if (cal != null) {
        if (!remove) {
            if (cal.getCalendarCollection()) {
                CalendarPref p = prefs.getCalendarPrefs();
                if (p.getAutoAdd() && p.add(cal)) {
                    update = true;
                }
            }
        } else {
            getSvc().removeFromAllPrefs(cal);
        }
    }
    if (!Util.isEmpty(cats)) {
        for (final BwCategory cat : cats) {
            if (!remove) {
                CategoryPref p = prefs.getCategoryPrefs();
                if (p.getAutoAdd() && p.add(cat)) {
                    update = true;
                }
            } else {
                getSvc().removeFromAllPrefs(cat);
            }
        }
    }
    if (loc != null) {
        if (!remove) {
            LocationPref p = prefs.getLocationPrefs();
            if (p.getAutoAdd() && p.add(loc)) {
                update = true;
            }
        } else {
            getSvc().removeFromAllPrefs(loc);
        }
    }
    if (ctct != null) {
        if (!remove) {
            ContactPref p = prefs.getContactPrefs();
            if (p.getAutoAdd() && p.add(ctct)) {
                update = true;
            }
        } else {
            getSvc().removeFromAllPrefs(ctct);
        }
    }
    if (update) {
        if (getPars().getPublicAdmin()) {
            getSvc().getUserAuth().updateUser(au);
        }
    }
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) CategoryPref(org.bedework.calfacade.svc.prefs.CategoryPref) ContactPref(org.bedework.calfacade.svc.prefs.ContactPref) BwCommonUserPrefs(org.bedework.calfacade.svc.prefs.BwCommonUserPrefs) CalendarPref(org.bedework.calfacade.svc.prefs.CalendarPref) BwCategory(org.bedework.calfacade.BwCategory) LocationPref(org.bedework.calfacade.svc.prefs.LocationPref)

Example 2 with BwAuthUser

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

the class CalintfImpl method getAuthUser.

@Override
public BwAuthUser getAuthUser(final String href) throws CalFacadeException {
    final BwAuthUser au = principalsAndPrefs.getAuthUser(href);
    if (au == null) {
        // Not an authorised user
        return null;
    }
    BwAuthUserPrefs prefs = au.getPrefs();
    if (prefs == null) {
        prefs = BwAuthUserPrefs.makeAuthUserPrefs();
        au.setPrefs(prefs);
    }
    return au;
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) BwAuthUserPrefs(org.bedework.calfacade.svc.prefs.BwAuthUserPrefs)

Example 3 with BwAuthUser

use of org.bedework.calfacade.svc.BwAuthUser 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 4 with BwAuthUser

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

the class CmdUtilHelper method newMember.

public BwPrincipal newMember(final String account, final boolean user) throws Throwable {
    if (user) {
        BwPrincipal p = getSvci().getUsersHandler().getUser(account);
        if (p == null) {
            p = addUser(account);
        }
        /* Ensure the authorised user exists - create an entry if not
       *
       * @param val      BwUser account
       */
        BwAuthUser au = getSvci().getUserAuth().getUser(p.getAccount());
        if ((au != null) && au.isUnauthorized()) {
            pstate.addError("Unauthorised user " + account);
            return null;
        }
        if (au == null) {
            au = BwAuthUser.makeAuthUser(p.getPrincipalRef(), UserAuth.publicEventUser);
            getSvci().getUserAuth().addUser(au);
        }
        return p;
    }
    // group
    final BwPrincipal p = findGroup(account);
    if (p == null) {
        pstate.addError("Unknown group " + account);
    }
    return p;
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) BwPrincipal(org.bedework.calfacade.BwPrincipal)

Example 5 with BwAuthUser

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

the class CalintfImpl method addAuthUser.

/* ====================================================================
   *                       user auth
   * ==================================================================== */
@Override
public void addAuthUser(final BwAuthUser val) throws CalFacadeException {
    final BwAuthUser ck = getAuthUser(val.getUserHref());
    if (ck != null) {
        throw new CalFacadeException(CalFacadeException.targetExists);
    }
    entityDao.save(val);
}
Also used : BwAuthUser(org.bedework.calfacade.svc.BwAuthUser) CalFacadeException(org.bedework.calfacade.exc.CalFacadeException)

Aggregations

BwAuthUser (org.bedework.calfacade.svc.BwAuthUser)11 BwCalendar (org.bedework.calfacade.BwCalendar)2 BwCategory (org.bedework.calfacade.BwCategory)2 BwPrincipal (org.bedework.calfacade.BwPrincipal)2 BwAuthUserPrefs (org.bedework.calfacade.svc.prefs.BwAuthUserPrefs)2 CalendarPref (org.bedework.calfacade.svc.prefs.CalendarPref)2 CategoryPref (org.bedework.calfacade.svc.prefs.CategoryPref)2 ContactPref (org.bedework.calfacade.svc.prefs.ContactPref)2 LocationPref (org.bedework.calfacade.svc.prefs.LocationPref)2 ArrayList (java.util.ArrayList)1 Ace (org.bedework.access.Ace)1 AceWho (org.bedework.access.AceWho)1 Acl (org.bedework.access.Acl)1 Privilege (org.bedework.access.Privilege)1 HibSession (org.bedework.calcorei.HibSession)1 BwContact (org.bedework.calfacade.BwContact)1 BwEventProperty (org.bedework.calfacade.BwEventProperty)1 CalFacadeException (org.bedework.calfacade.exc.CalFacadeException)1 BwAdminGroup (org.bedework.calfacade.svc.BwAdminGroup)1 UserAuth (org.bedework.calfacade.svc.UserAuth)1