public Role getRoleByName(String name) { try { return (Role) DB.exec((db) -> { RoleManager mgr = new RoleManager(db); return mgr.getRoleByName(name); }); } catch (Exception e) { getApp().getLog().error(e); return null; } } }
int i=0; for (String s : roles) { Role r = rm.getRoleByName(s); if (r == null) { cli.println ("Role '" + s + "' does not exist - aborting");
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length != 2) { cli.println("Usage: rmrole <role>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role r = rm.getRoleByName(args[1]); if (r != null) db.session().delete(r); db.commit(); cli.println (r != null ? "Role " + r + " has been deleted" : "Role not found"); } catch (Exception e) { cli.println (e.getMessage()); } } }
int i=0; for (String s : roles) { Role r = rm.getRoleByName(s); if (r == null) { cli.println ("Role '" + s + "' does not exist - aborting");
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: addrole <role> <permission 1> <permission 2> ... <permission n>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role role = null; if (rm.getRoleByName(args[1]) == null) { role = new Role(args[1]); Set<Permission> perms = role.getPermissions(); for (int i = 2; i < args.length; i++) perms.add(Permission.valueOf(args[i])); db.save(role); } db.commit(); cli.println (role != null ? "Role created " + role.getName() : " Role already exists"); } catch (Exception e) { cli.println (e.getMessage()); } } }
@Override public void exec(CLIContext cli, String[] args) throws Exception { if (args.length < 2) { cli.println("Usage: addpermission <role> <permission 1> <permission 2> ... <permission n>"); return; } try (DB db = new DB()) { db.open(); db.beginTransaction(); RoleManager rm = new RoleManager(db); Role role = null; if (rm.getRoleByName(args[1]) == null) { role = new Role(args[1]); Set<Permission> perms = role.getPermissions(); for (int i = 2; i < args.length; i++) perms.add(Permission.valueOf(args[i])); db.save(role); } db.commit(); cli.println (role != null ? "Role created " + role.getName() : " Role already exists"); } catch (Exception e) { cli.println (e.getMessage()); } } }