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);
}
}
}
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;
}
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);
}
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;
}
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);
}
Aggregations