use of org.bedework.calfacade.BwPrincipal 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.BwPrincipal in project bw-calendar-engine by Bedework.
the class AdminGroupRule method end.
@Override
public void end(final String ns, final String name) throws Exception {
final BwAdminGroup entity = (BwAdminGroup) pop();
try {
if (entity.getGroupOwnerHref() == null) {
error("Missing group owner for admin group " + entity);
return;
}
if (entity.getOwnerHref() == null) {
error("Missing owner for admin group " + entity);
return;
}
if (entity.getPrincipalRef() == null) {
// Pre 3.5?
globals.setPrincipalHref(entity);
}
globals.counts[globals.adminGroups]++;
globals.principalsTbl.put(entity);
if (globals.rintf != null) {
globals.rintf.restoreAdminGroup(entity);
/* Save members. */
final Collection<BwPrincipal> c = entity.getGroupMembers();
if (c == null) {
return;
}
for (final BwPrincipal pr : c) {
globals.rintf.addAdminGroupMember(entity, pr);
}
}
} catch (final Throwable t) {
error("Unable to restore admin group " + entity);
throw new Exception(t);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class BwDumpRestore method deleteUser.
@Override
public String deleteUser(final String account) {
try {
final CalSvcI svci = getSvci(getConfig().getAccount(), true);
final BwPrincipal pr = svci.getUsersHandler().getUser(account);
if (pr == null) {
return "No principal for " + account;
}
svci.getUsersHandler().remove(pr);
return "ok";
} catch (final Throwable t) {
error(t);
return "Exception: " + t.getLocalizedMessage();
} finally {
try {
closeSvci();
} catch (final Throwable t) {
error(t);
}
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class Dump method doDump.
/**
* @throws Throwable on error
*/
public void doDump() throws Throwable {
if (newDumpFormat) {
// TODO - start a separate thread for public
final DumpPublic dumpPub = new DumpPublic(globals);
if (dumpPub.open()) {
dumpPub.doDump();
dumpPub.close();
}
final DumpSystem dumpSys = new DumpSystem(globals);
if (dumpSys.open()) {
dumpSys.doDump();
dumpSys.close();
}
final DumpPrincipal dumpPr = new DumpPrincipal(globals);
final Iterator<BwPrincipal> it = globals.di.getAllPrincipals();
while (it.hasNext()) {
final BwPrincipal pr = it.next();
final String account = pr.getAccount().toLowerCase().trim();
if (!account.equals(pr.getAccount())) {
globals.info.addLn("WARNING: Principal " + pr + " has possible invalid account");
}
boolean open = false;
try {
if (dumpPr.open(pr)) {
open = true;
dumpPr.doDump();
}
} catch (final CalFacadeException cfe) {
error(cfe);
} finally {
if (open) {
try {
dumpPr.close();
} catch (final CalFacadeException cfe) {
error(cfe);
}
}
}
}
} else {
new DumpAll(globals).dumpSection(null);
new DumpAliases(globals).dumpSection(null);
}
}
use of org.bedework.calfacade.BwPrincipal in project bw-calendar-engine by Bedework.
the class AbstractDirImpl method caladdrToPrincipal.
/* (non-Javadoc)
* @see org.bedework.calfacade.ifs.Directories#caladdrToPrincipal(java.lang.String)
*/
@Override
public BwPrincipal caladdrToPrincipal(final String caladdr) throws CalFacadeException {
try {
if (caladdr == null) {
throw new CalFacadeException(CalFacadeException.nullCalendarUserAddr);
}
BwPrincipal p = calAddrToPrincipalMap.get(caladdr);
if (p != null) {
return p;
}
// Ensure all set up
getProps();
if (isPrincipal(caladdr)) {
p = getPrincipal(caladdr);
calAddrToPrincipalMap.put(caladdr, p);
return p;
}
String acc = null;
String ca = caladdr;
final int atPos = ca.indexOf("@");
if (atPos > 0) {
ca = ca.toLowerCase();
}
if (onlyDomain != null) {
if (atPos < 0) {
acc = ca;
}
if (onlyDomain.matches(ca, atPos)) {
acc = ca.substring(0, atPos);
}
} else if (atPos < 0) {
// Assume default domain?
acc = ca;
} else if (anyDomain) {
acc = ca;
} else {
for (final DomainMatcher dm : domains) {
if (dm.matches(ca, atPos)) {
acc = ca;
break;
}
}
}
if (acc == null) {
// Not ours
return null;
}
if (acc.toLowerCase().startsWith("mailto:")) {
acc = acc.substring("mailto:".length());
}
// XXX -at this point we should validate the account
int whoType = WhoDefs.whoTypeUser;
for (CAPrefixInfo c : getCaPrefixInfo()) {
if (acc.startsWith(c.getPrefix())) {
whoType = c.getType();
break;
}
}
p = getPrincipal(makePrincipalUri(acc, whoType));
calAddrToPrincipalMap.put(caladdr, p);
return p;
} catch (CalFacadeException cfe) {
throw cfe;
} catch (Throwable t) {
throw new CalFacadeException(t);
}
}
Aggregations