});
}
static void createPermissions ()
{
ObjectContext ctx = ObjectContext.get();
// Permissions for every Entity
Map<String, Set<Permission>> permissionsByPackage = MapUtil.map();
for (String className : PersistenceMeta.getEntityClasses()) {
// get list for package
String pkg = AWUtil.stripLastComponent(className, '.');
Set<Permission> permissionsForClass = permissionsByPackage.get(pkg);
if (permissionsForClass == null) {
permissionsForClass = SetUtil.set();
permissionsByPackage.put(pkg,permissionsForClass);
}
for (Permission.ClassOperation op : Permission.ClassOperation.values()) {
String permName = Permission.nameForClassOp(className, op);
Permission permission = ctx.create(Permission.class);
permission.setName(permName);
permissionsForClass.add(permission);
}
ctx.save();
}
// Groups for every package
List<Group>pkgGroups = ListUtil.list();
for (Map.Entry<String, Set<Permission>> e : permissionsByPackage.entrySet()) {
Group group = ctx.create(Group.class);
group.setName(Fmt.S("%s:ALL", e.getKey()));
group.setPermissions(e.getValue());
pkgGroups.add(group);
}
// Superuser group
createGroup(ctx, Group.DefaultGroup.AdminUsers.name(), pkgGroups);
// Anonymous -> *no* permissions by default -- should be overridden by app
Group anon = createGroup(ctx, Group.DefaultGroup.AnonymousUsers.name(), null);
// DefaultUser -> *no* permissions by default -- should be overridden by app
createGroup(ctx, Group.DefaultGroup.DefaultUsers.name(), AWUtil.list(anon));
ctx.save();
}