Example #1
0
 /**
  * Used to get the groups of a user or a group as a String[] array
  *
  * @param world
  * @param type
  * @param name
  * @return String[]
  */
 public static String[] getGroups(String world, CalculableType type, String name) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   Set<String> g = c.getGroupsAsString();
   String[] groups = g.toArray(new String[g.size()]);
   return groups;
 }
Example #2
0
 /**
  * Used to get the permissions of a user or a group as a Permission[] array Remember, Permission
  * can be true or false
  *
  * @param world
  * @param type
  * @param name
  * @return Permission[]
  */
 public static Permission[] getPermissions(String world, CalculableType type, String name) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   Set<Permission> p = c.getPermissions();
   Permission[] permissions = p.toArray(new Permission[p.size()]);
   return permissions;
 }
Example #3
0
 /**
  * Used to set the group of a user or a group
  *
  * @param world
  * @param type
  * @param name
  * @param groupToAdd
  */
 public static void setGroup(String world, CalculableType type, String name, String groupToAdd) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.getGroupsAsString().clear();
   c.addGroup(groupToAdd);
 }
Example #4
0
 /**
  * Used to return the metadata value for a user or a group. Will never return null but may return
  * ""
  *
  * @param world
  * @param type
  * @param name
  * @param key
  * @return String
  */
 public static String getValue(String world, CalculableType type, String name, String key) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   return c.getEffectiveValue(key);
 }
Example #5
0
 /**
  * Returns wether the user or group has the permission node
  *
  * @param world
  * @param type
  * @param name
  * @param node
  * @return boolean
  */
 public static boolean hasPermission(String world, CalculableType type, String name, String node) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   return c.hasPermission(node);
 }
Example #6
0
 /**
  * Used to set the metadata value for a user or a group
  *
  * @param world
  * @param type
  * @param name
  * @param key
  * @param value
  */
 public static void setValue(
     String world, CalculableType type, String name, String key, String value) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.setValue(key, value);
 }
Example #7
0
 /**
  * Removes a single permission (String, Boolean) from a user or a group The permission object is
  * instead a String, the boolean does not matter here.
  *
  * @param world
  * @param type
  * @param name
  * @param permissionToRemove
  */
 public static void removePermission(
     String world, CalculableType type, String name, String permissionToRemove) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.removePermission(permissionToRemove);
 }
Example #8
0
 /**
  * Adds a single permission (String, Boolean) to a user or a group
  *
  * @param world
  * @param type
  * @param name
  * @param permissionToAdd
  */
 public static void addPermission(
     String world, CalculableType type, String name, Permission permissionToAdd) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.addPermission(permissionToAdd.name(), permissionToAdd.isTrue());
 }
Example #9
0
 /**
  * Returns true if the user or group or any inherited groups carry the named group as a child
  * group
  *
  * @param world
  * @param type
  * @param name
  * @param group
  * @return boolean
  */
 public static boolean hasGroupRecursive(
     String world, CalculableType type, String name, String group) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   return c.hasGroupRecursive(group);
 }
Example #10
0
 /**
  * Used to remove a single group from a user or a group
  *
  * @param world
  * @param type
  * @param name
  * @param groupToRemove
  */
 public static void removeGroup(
     String world, CalculableType type, String name, String groupToRemove) {
   World w = wm.getWorld(world);
   Calculable c = w.get(name, type);
   c.removeGroup(groupToRemove);
 }
  /**
   * TODO deprecate strings in favour of certificates XXX currently we only support a single player
   * per connection.
   *
   * @param player the player trying to connect
   * @return true if the connection was successfully identified with the specified player
   */
  public synchronized boolean addConnection(ConnectionToServer c, Player player, byte[] signature) {
    logger.log(Level.INFO, "Authenticating player " + player.getName());

    /* determine whether this identity already exists */
    NonNullElements i =
        new NonNullElements(KEY.PLAYERS, serverGameEngine.getWorld(), Player.AUTHORITATIVE);

    while (i.next()) {
      Player p = (Player) i.getElement();

      if (p.getName().equals(player.getName())) {
        /* this player already exists */
        /* is this identity already connected ? */
        if (principals.containsValue(p)) {
          logger.log(Level.INFO, "Player " + p.getName() + " is already" + " connected");

          return false;
        }

        /* is this player the same as the one which previously
         * connected under the same name? */
        logger.log(Level.FINE, "Verifying player " + p + " with " + player);

        if (!p.verify(player, signature)) {
          logger.log(Level.WARNING, "Couldn't verify signature of player " + p.getName());

          return false;
        }

        principals.put(c, p);

        /* set the connection world */
        if (c instanceof LocalConnection) {
          // don't create a WorldView, since the local client needs
          // to synchronize against the world object itself.
          c.setWorld(serverGameEngine.getWorld());
        } else {
          c.setWorld(new WorldView(serverGameEngine.getWorld(), p.getPrincipal()));
        }

        return true;
      }
    }

    /* this player does not already exist */
    logger.log(
        Level.INFO, "Adding player " + player.getName() + " to " + serverGameEngine.getWorld());

    MoveConfirmer mc =
        new MoveConfirmer(serverGameEngine.getMoveExecuter(), serverGameEngine.getMoveChainFork());
    AddPlayerMove m = new AddPlayerMove(serverGameEngine.getWorld(), player);
    MoveStatus ms = mc.confirmMove(m, null);

    assert ms == MoveStatus.MOVE_OK;

    /*
     * get the newly created player-with-principal
     */
    World w = serverGameEngine.getWorld();
    assert (w != null);
    player =
        (Player)
            w.get(KEY.PLAYERS, w.size(KEY.PLAYERS, Player.AUTHORITATIVE) - 1, Player.AUTHORITATIVE);

    principals.put(c, player);

    /* Perform any moves necessary for adding a new player */
    serverGameEngine
        .getMoveExecuter()
        .processMove(statGatherer.generateNewPlayerMove(player.getPrincipal()), c);
    serverGameEngine
        .getMoveExecuter()
        .processMove(scenario.getSetupMoves(serverGameEngine.getWorld(), player.getPrincipal()), c);

    /* set the connection world */
    c.setWorld(new WorldView(serverGameEngine.getWorld(), player.getPrincipal()));
    return true;
  }