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