Beispiel #1
0
  /**
   * * Creates an entry into the ODocument-Collection and create a new Class named "collectionName"
   *
   * @param collectionName
   * @return
   * @throws Throwable
   */
  public ODocument create(String collectionName) throws Throwable {
    Logger.trace("Method Start");
    try {
      if (existsCollection(collectionName))
        throw new InvalidCollectionException("Collection " + collectionName + " already exists");
    } catch (SqlInjectionException e) {
      throw new InvalidCollectionException(e);
    }
    ODocument doc = super.create();
    doc.field("name", collectionName);
    save(doc);

    // create new class
    OClass documentClass = db.getMetadata().getSchema().getClass(CLASS_NODE_NAME);
    db.getMetadata().getSchema().createClass(collectionName, documentClass);

    // grants to the new class
    ORole registeredRole = RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString());
    ORole anonymousRole = RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString());
    registeredRole.addRule(
        ODatabaseSecurityResources.CLASS + "." + collectionName, ORole.PERMISSION_ALL);
    registeredRole.addRule(
        ODatabaseSecurityResources.CLUSTER + "." + collectionName, ORole.PERMISSION_ALL);
    anonymousRole.addRule(
        ODatabaseSecurityResources.CLASS + "." + collectionName, ORole.PERMISSION_READ);
    anonymousRole.addRule(
        ODatabaseSecurityResources.CLUSTER + "." + collectionName, ORole.PERMISSION_READ);
    PermissionsHelper.grantRead(doc, registeredRole);
    PermissionsHelper.grantRead(doc, anonymousRole);
    Logger.trace("Method End");
    return doc;
  } // getNewModelInstance(String collectionName)
Beispiel #2
0
  @Override
  public void onRequestPermissionsResult(
      int requestCode, String[] permissions, int[] grantResults) {

    PermissionsHelper.onRequestPermissionsResult(
        granted -> showContacts(), expectedCode, requestCode, permissions, grantResults);

    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
  }
Beispiel #3
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Timber.plant(new Timber.DebugTree());
    ButterKnife.bind(this);

    expectedCode = PermissionsHelper.requestPermission(this, Manifest.permission.READ_CONTACTS);
    if (expectedCode == null) {
      showContacts();
    }
  }
Beispiel #4
0
  /**
   * Obtains all the players currently on the server with additional information.
   *
   * @return A <code>List</code> of <code>Map</code>s of players along with their info.
   */
  private static List<Map<String, Object>> getExtendedPlayerList() {
    Player[] players = minequery.getServer().getOnlinePlayers();
    List<Map<String, Object>> playerList = new ArrayList<Map<String, Object>>();

    for (Player player : players) {
      Map<String, Object> playerMap = new HashMap<String, Object>();
      playerMap.put("name", player.getName());
      playerMap.put("displayName", player.getDisplayName());
      playerMap.put("health", player.getHealth());

      Map<String, Object> locationMap = new HashMap<String, Object>();
      locationMap.put("blockX", player.getLocation().getBlockX());
      locationMap.put("blockY", player.getLocation().getBlockY());
      locationMap.put("blockZ", player.getLocation().getBlockZ());
      locationMap.put("pitch", player.getLocation().getPitch());
      locationMap.put("x", player.getLocation().getX());
      locationMap.put("y", player.getLocation().getY());
      locationMap.put("z", player.getLocation().getZ());
      locationMap.put("world", player.getLocation().getWorld().getName());

      playerMap.put("location", locationMap);
      playerMap.put("isDead", player.isDead());
      playerMap.put("isSleeping", player.isSleeping());
      playerMap.put("isOp", player.isOp());

      // Permissions specific values.
      if (PermissionsHelper.isPermissionsAvailable()) {
        Map<String, Object> permissionsMap = new HashMap<String, Object>();
        PermissionHandler permissionHandler = PermissionsHelper.getPermissionHandler();
        permissionsMap.put(
            "groups", permissionHandler.getGroups(player.getWorld().getName(), player.getName()));

        playerMap.put("permissions", permissionsMap);
      }

      playerList.add(playerMap);
    }

    return playerList;
  }
Beispiel #5
0
  /**
   * * Creates an entry into the ODocument-Collection and create a new Class named "collectionName"
   *
   * @param collectionName
   * @return an ODocument instance representing the collection
   * @throws CollectionAlreadyExistsException
   * @throws OpenTransactionException, CollectionAlreadyExistsException, InvalidCollectionException,
   *     InvalidModelException, Throwable
   */
  public ODocument create(String collectionName)
      throws OpenTransactionException, CollectionAlreadyExistsException, InvalidCollectionException,
          InvalidModelException, Throwable {
    if (DbHelper.isInTransaction())
      throw new OpenTransactionException("Cannot create a collection within an open transaction");
    if (Logger.isTraceEnabled()) Logger.trace("Method Start");

    if (Character.isDigit(collectionName.charAt(0))) {
      throw new InvalidCollectionException("Collection names cannot start by a digit");
    }
    if (collectionName.contains(";")) {
      throw new InvalidCollectionException("Collection cannot contain ;");
    }
    if (collectionName.contains(":")) {
      throw new InvalidCollectionException("Collection cannot contain :");
    }
    if (collectionName.contains(".")) {
      throw new InvalidCollectionException("Collection cannot contain .");
    }
    if (collectionName.contains("@")) {
      throw new InvalidCollectionException("Collection cannot contain @");
    }
    if (collectionName.startsWith("_")) {
      throw new InvalidCollectionException("Collection cannot start with _");
    }
    if (!collectionName.matches(COLLECTION_NAME_REGEX)) {
      throw new InvalidCollectionException(
          "Collection name must be complaint with the regular expression: "
              + COLLECTION_NAME_REGEX);
    }
    if (collectionName.toUpperCase().startsWith("_BB_")) {
      throw new InvalidCollectionException(
          "Collection name is not valid: it can't be prefixed with _BB_");
    }
    try {
      if (existsCollection(collectionName))
        throw new CollectionAlreadyExistsException(
            "Collection " + collectionName + " already exists");
    } catch (SqlInjectionException e) {
      throw new InvalidCollectionException(e);
    }
    ODocument doc = super.create();
    doc.field("name", collectionName);

    save(doc);

    // create new class
    OClass documentClass = db.getMetadata().getSchema().getClass(CLASS_NODE_NAME);
    db.getMetadata().getSchema().createClass(collectionName, documentClass);

    // grants to the new class
    ORole registeredRole = RoleDao.getRole(DefaultRoles.REGISTERED_USER.toString());
    ORole anonymousRole = RoleDao.getRole(DefaultRoles.ANONYMOUS_USER.toString());
    registeredRole.addRule(
        ODatabaseSecurityResources.CLASS + "." + collectionName, ORole.PERMISSION_ALL);
    registeredRole.addRule(
        ODatabaseSecurityResources.CLUSTER + "." + collectionName, ORole.PERMISSION_ALL);
    anonymousRole.addRule(
        ODatabaseSecurityResources.CLASS + "." + collectionName, ORole.PERMISSION_READ);
    anonymousRole.addRule(
        ODatabaseSecurityResources.CLUSTER + "." + collectionName, ORole.PERMISSION_READ);
    PermissionsHelper.grantRead(doc, registeredRole);
    PermissionsHelper.grantRead(doc, anonymousRole);
    if (Logger.isTraceEnabled()) Logger.trace("Method End");
    return doc;
  } // getNewModelInstance(String collectionName)