static void createSystemUsers(UserManager userManager,
SystemSession session,
String adminId,
String anonymousId) throws RepositoryException {
Authorizable admin = null;
if (adminId != null) {
admin = userManager.getAuthorizable(adminId);
if (admin == null) {
admin = userManager.createUser(adminId, adminId);
if (!userManager.isAutoSave()) {
session.save();
}
log.info("... created admin-user with id \'" + adminId + "\' ...");
}
}
// assume administrators groupID and principalName are the same.
// and avoid retrieving group by principal.
Group admins = (Group) userManager.getAuthorizable(SecurityConstants.ADMINISTRATORS_NAME);
if (admins == null) {
admins = userManager.createGroup(new PrincipalImpl(SecurityConstants.ADMINISTRATORS_NAME));
if (!userManager.isAutoSave()) {
session.save();
}
log.info("... created administrators group with name '"+SecurityConstants.ADMINISTRATORS_NAME+"'");
}
try {
if (admins != null && admins.addMember(admin)) {
if (!userManager.isAutoSave()) {
session.save();
}
log.info("... added admin '" + adminId + "' as member of the administrators group.");
}
} catch (RepositoryException e) {
// administrator has full permissions anyway. just log a
// warning and ignore the error.
log.warn("Unexpected error while adding admin to the administrators group", e);
}
if (anonymousId != null) {
Authorizable anonymous = userManager.getAuthorizable(anonymousId);
if (anonymous == null) {
userManager.createUser(anonymousId, "");
if (!userManager.isAutoSave()) {
session.save();
}