use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Users method initUserObject.
BwPrincipal initUserObject(final String val) throws CalFacadeException {
String account = val;
if (account.endsWith("/")) {
account = account.substring(0, account.length() - 1);
}
if (getSvc().getDirectories().isPrincipal(val)) {
account = getSvc().getDirectories().accountFromPrincipal(val);
}
if (account == null) {
throw new CalFacadeException("Bad user account " + val);
}
setRoots(getSvc());
final BwPrincipal user = BwPrincipal.makeUserPrincipal();
user.setAccount(account);
user.setCategoryAccess(Access.getDefaultPersonalAccess());
user.setLocationAccess(Access.getDefaultPersonalAccess());
user.setContactAccess(Access.getDefaultPersonalAccess());
user.setQuota(getSvc().getAuthProperties().getDefaultUserQuota());
user.setPrincipalRef(Util.buildPath(colPathEndsWithSlash, userPrincipalRoot, "/", account));
return user;
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Users method getPrincipal.
@Override
public BwPrincipal getPrincipal(final String val) throws CalFacadeException {
if (val == null) {
return null;
}
final String href;
if (val.endsWith("/")) {
href = val.substring(0, val.length() - 1);
} else {
href = val;
}
final BwPrincipal p = mappedPrincipal(href);
if (p != null) {
return p;
}
setRoots(getSvc());
if (!href.startsWith(principalRoot)) {
return null;
}
if (href.startsWith(userPrincipalRoot)) {
final BwPrincipal u = getSvc().getPrincipal(href);
if (u != null) {
principalMap.put(href, u);
}
return u;
}
if (href.startsWith(groupPrincipalRoot)) {
final BwGroup g = getSvc().getDirectories().findGroup(href.substring(groupPrincipalRootLen));
if (g != null) {
principalMap.put(href, g);
}
return g;
}
return null;
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Views method find.
@Override
public BwView find(String val) throws CalFacadeException {
if (val == null) {
BwPreferences prefs = getSvc().getPrefsHandler().get();
val = prefs.getPreferredView();
if (val == null) {
return null;
}
}
/* val may be a name in which case it's for the current user or it
* may be a fully qualified path referencing another users views.
*/
if (!val.startsWith("/")) {
// This user
Collection<BwView> views = getAll();
for (BwView view : views) {
if (view.getName().equals(val)) {
return view;
}
}
return null;
}
/* Other user - we expect a path of th eform
* /user/<id>/<bedework-resource-name>/views/<view-name>
*/
String[] pathEls = val.split("/");
BasicSystemProperties bsp = getBasicSyspars();
if ((pathEls.length != 5) || !bsp.getBedeworkResourceDirectory().equals(pathEls[2]) || !"views".equals(pathEls[3])) {
return null;
}
StringBuilder sb = new StringBuilder();
if (bsp.getUserCalendarRoot().equals(pathEls[0])) {
sb.append(BwPrincipal.userPrincipalRoot);
} else {
return null;
}
// user id
sb.append(pathEls[1]);
BwPrincipal pr = getPrincipal(sb.toString());
if (pr == null) {
return null;
}
Collection<BwView> views = getAll(pr);
String viewName = pathEls[4];
for (BwView view : views) {
if (view.getName().equals(viewName)) {
return view;
}
}
return null;
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method updateQuota.
boolean updateQuota(final AccessPrincipal principal, final long inc) throws WebdavException {
try {
BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
if (p == null) {
// No quota - fail
return false;
}
if (p.getKind() != WhoDefs.whoTypeUser) {
// No quota - fail
return false;
}
BwPreferences prefs = getPrefs();
long used = prefs.getQuotaUsed() + inc;
prefs.setQuotaUsed(used);
getSvci().getUsersHandler().update(p);
return // Decreasing usage - let it pass
(inc < 0) || (used <= p.getQuota());
} catch (CalFacadeException cfe) {
throw new WebdavException(cfe);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class BwSysIntfImpl method getCalPrincipalInfo.
@Override
public CalPrincipalInfo getCalPrincipalInfo(final AccessPrincipal principal) throws WebdavException {
try {
if (principal == null) {
return null;
}
final boolean thisPrincipal = principal.equals(getSvci().getPrincipal());
if (thisPrincipal && (principalInfo != null)) {
return principalInfo;
}
final BwPrincipal p = getSvci().getUsersHandler().getPrincipal(principal.getPrincipalRef());
if (p == null) {
return null;
}
if (p.getKind() != WhoDefs.whoTypeUser) {
// XXX Cannot handle this yet
return null;
}
// SCHEDULE - just get home path and get default cal from user prefs.
final String userHomePath = Util.buildPath(true, getSvci().getPrincipalInfo().getCalendarHomePath(p));
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());
final CalPrincipalInfo pi = new CalPrincipalInfo(p, null, null, userHomePath, defaultCalendarPath, inboxPath, outboxPath, notificationsPath, p.getQuota());
if (thisPrincipal) {
principalInfo = pi;
}
return pi;
} catch (final Throwable t) {
throw new WebdavException(t);
}
}
Aggregations