Package com.orientechnologies.orient.core.exception

Examples of com.orientechnologies.orient.core.exception.OSecurityAccessException


      }

      OLogManager.instance().error(this, "Authentication error of remote client %s:%d: shutdown is aborted.",
          channel.socket.getInetAddress(), channel.socket.getPort());

      sendError(lastClientTxId, new OSecurityAccessException("Invalid user/password to shutdown the server"));
      break;
    }

    case OChannelBinaryProtocol.REQUEST_CONNECT: {
      data.commandInfo = "Connect";

      serverLogin(channel.readString(), channel.readString());

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeInt(connection.id);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DB_OPEN: {
      data.commandInfo = "Open database";

      String dbURL = channel.readString();

      user = channel.readString();
      passwd = channel.readString();

      openDatabase(dbURL, user, passwd);

      if (!(connection.database.getStorage() instanceof OStorageEmbedded) && !loadUserFromSchema(user, passwd)) {
        sendError(lastClientTxId, new OSecurityAccessException(connection.database.getName(),
            "User or password not valid for database: '" + connection.database.getName() + "'"));
      } else {

        channel.acquireExclusiveLock();
        try {
          sendOk(lastClientTxId);
          channel.writeInt(connection.id);

          sendDatabaseInformation();

          if (getClass().equals(ONetworkProtocolBinary.class))
            // NO EXTENSIONS (CLUSTER): SEND NULL DOCUMENT
            channel.writeBytes(null);

        } finally {
          channel.releaseExclusiveLock();
        }
      }

      break;
    }
    case OChannelBinaryProtocol.REQUEST_DB_RELOAD: {
      data.commandInfo = "Reload database information";

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);

        sendDatabaseInformation();

      } finally {
        channel.releaseExclusiveLock();
      }

      break;
    }
    case OChannelBinaryProtocol.REQUEST_DB_CREATE: {
      data.commandInfo = "Create database";

      String dbName = channel.readString();
      String storageMode = channel.readString();

      checkServerAccess("database.create");
      connection.database = getDatabaseInstance(dbName, storageMode);
      createDatabase(connection.database, null, null);

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DB_CLOSE:
      data.commandInfo = "Close Database";

      if (connection != null) {
        connection.close();

        OClientConnectionManager.instance().disconnect(connection.id);
        // sendShutdown();
      }

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;

    case OChannelBinaryProtocol.REQUEST_DB_EXIST: {
      data.commandInfo = "Exists database";
      String dbName = channel.readString();

      checkServerAccess("database.exists");

      connection.database = getDatabaseInstance(dbName, "local");

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeByte((byte) (connection.database.exists() ? 1 : 0));
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DB_DELETE: {
      data.commandInfo = "Delete database";
      String dbName = channel.readString();

      checkServerAccess("database.delete");

      connection.database = getDatabaseInstance(dbName, "local");

      OLogManager.instance().info(this, "Dropped database '%s", connection.database.getURL());

      connection.database.delete();

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DB_SIZE: {
      data.commandInfo = "Database size";

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(connection.database.getStorage().getSize());
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DB_COUNTRECORDS: {
      data.commandInfo = "Database count records";

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(connection.database.getStorage().countRecords());
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DATACLUSTER_COUNT: {
      data.commandInfo = "Count cluster elements";

      int[] clusterIds = new int[channel.readShort()];
      for (int i = 0; i < clusterIds.length; ++i)
        clusterIds[i] = channel.readShort();

      final long count = connection.database.countClusterElements(clusterIds);

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(count);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DATACLUSTER_DATARANGE: {
      data.commandInfo = "Get the begin/end range of data in cluster";

      long[] pos = connection.database.getStorage().getClusterDataRange(channel.readShort());

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(pos[0]);
        channel.writeLong(pos[1]);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DATACLUSTER_ADD: {
      data.commandInfo = "Add cluster";

      final String type = channel.readString();
      final String name = channel.readString();

      final int num;
      OStorage.CLUSTER_TYPE t = OStorage.CLUSTER_TYPE.valueOf(type);
      switch (t) {
      case PHYSICAL:
        num = connection.database.addPhysicalCluster(name, channel.readString(), channel.readInt());
        break;

      case MEMORY:
        num = connection.database.getStorage().addCluster(name, t);
        break;

      case LOGICAL:
        num = connection.database.addLogicalCluster(name, channel.readInt());
        break;

      default:
        throw new IllegalArgumentException("Cluster type " + type + " is not supported");
      }

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeShort((short) num);
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_DATACLUSTER_REMOVE: {
      data.commandInfo = "Remove cluster";

      final int id = channel.readShort();

      boolean result = connection.database.dropCluster(connection.database.getClusterNameById(id));

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeByte((byte) (result ? 1 : 0));
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_RECORD_LOAD: {
      data.commandInfo = "Load record";

      final ORecordId rid = channel.readRID();
      final String fetchPlanString = channel.readString();
      if (rid.clusterId == 0 && rid.clusterPosition == 0) {
        // @COMPATIBILITY 0.9.25
        // SEND THE DB CONFIGURATION INSTEAD SINCE IT WAS ON RECORD 0:0
        OFetchHelper.checkFetchPlanValid(fetchPlanString);
        channel.acquireExclusiveLock();
        try {
          sendOk(lastClientTxId);
          channel.writeByte((byte) 1);
          channel.writeBytes(connection.database.getStorage().getConfiguration().toStream());
          channel.writeInt(0);
          channel.writeByte(ORecordBytes.RECORD_TYPE);
        } finally {
          channel.releaseExclusiveLock();
        }
      } else {
        final ORecordInternal<?> record = connection.database.load(rid, fetchPlanString);

        // if (rid.equals(((OSchemaImpl) connection.database.getMetadata().getSchema()).getDocument().getIdentity()))
        // connection.database.getMetadata().getSchema().reload();

        channel.acquireExclusiveLock();
        try {
          sendOk(lastClientTxId);

          if (record != null) {
            channel.writeByte((byte) 1);
            channel.writeBytes(record.toStream());
            channel.writeInt(record.getVersion());
            channel.writeByte(record.getRecordType());

            if (fetchPlanString.length() > 0) {
              // BUILD THE SERVER SIDE RECORD TO ACCES TO THE FETCH
              // PLAN
              if (record instanceof ODocument) {
                final Map<String, Integer> fetchPlan = OFetchHelper.buildFetchPlan(fetchPlanString);

                final Set<ODocument> recordsToSend = new HashSet<ODocument>();
                OFetchHelper.fetch((ODocument) record, record, fetchPlan, null, 0, -1, new OFetchListener() {
                  @Override
                  public int size() {
                    return recordsToSend.size();
                  }

                  // ADD TO THE SET OF OBJECTS TO SEND
                  @Override
                  public Object fetchLinked(final ODocument iRoot, final Object iUserObject, final String iFieldName,
                      final Object iLinked) {
                    if (iLinked instanceof ODocument) {
                      if (((ODocument) iLinked).getIdentity().isValid())
                        return recordsToSend.add((ODocument) iLinked) ? iLinked : null;
                      return null;
                    } else if (iLinked instanceof Collection<?>)
                      return recordsToSend.addAll((Collection<? extends ODocument>) iLinked) ? iLinked : null;
                    else if (iLinked instanceof Map<?, ?>)
                      return recordsToSend.addAll(((Map<String, ? extends ODocument>) iLinked).values()) ? iLinked : null;
                    else
                      throw new IllegalArgumentException("Unrecognized type while fetching records: " + iLinked);
                  }
                });

                // SEND RECORDS TO LOAD IN CLIENT CACHE
                for (ODocument doc : recordsToSend) {
                  if (doc.getIdentity().isValid()) {
                    channel.writeByte((byte) 2); // CLIENT CACHE
                    // RECORD. IT ISN'T PART OF THE RESULT SET
                    writeIdentifiable(doc);
                  }
                }
              }

            }
          }
        } finally {
          channel.releaseExclusiveLock();
        }
      }
      channel.writeByte((byte) 0); // NO MORE RECORDS
      break;
    }

    case OChannelBinaryProtocol.REQUEST_RECORD_CREATE: {
      data.commandInfo = "Create record";

      final ORecordId rid = new ORecordId(channel.readShort(), ORID.CLUSTER_POS_INVALID);

      final byte[] buffer = channel.readBytes();
      final byte recordType = channel.readByte();

      final ORecordInternal<?> record = Orient.instance().getRecordFactoryManager().newInstance(connection.database, recordType);
      record.fill(connection.database, rid, 0, buffer, true);
      connection.database.save(record);

      channel.acquireExclusiveLock();
      try {
        sendOk(lastClientTxId);
        channel.writeLong(record.getIdentity().getClusterPosition());
      } finally {
        channel.releaseExclusiveLock();
      }
      break;
    }

    case OChannelBinaryProtocol.REQUEST_RECORD_UPDATE: {
      data.commandInfo = "Update record";

      final ORecordId rid = channel.readRID();

      final byte[] buffer = channel.readBytes();
      final int version = channel.readInt();
      final byte recordType = channel.readByte();
      final ORecordInternal<?> newRecord = Orient.instance().getRecordFactoryManager().newInstance(connection.database, recordType);
      newRecord.fill(connection.database, rid, version, buffer, true);

      if (((OSchemaProxy) connection.database.getMetadata().getSchema()).getIdentity().equals(rid))
        // || ((OIndexManagerImpl) connection.database.getMetadata().getIndexManager()).getDocument().getIdentity().equals(rid)) {
        throw new OSecurityAccessException("Can't update internal record " + rid);

      final ORecordInternal<?> currentRecord;
      if (newRecord instanceof ODocument) {
        currentRecord = connection.database.load(rid);
View Full Code Here


    }
  }

  private void serverLogin(final String iUser, final String iPassword) {
    if (!OServerMain.server().authenticate(iUser, iPassword, "connect"))
      throw new OSecurityAccessException(
          "Wrong user/password to [connect] to the remote OrientDB Server instance. Get the user/password from the config/orientdb-server-config.xml file");

    serverUser = OServerMain.server().getUser(iUser);
  }
View Full Code Here

    serverUser = OServerMain.server().getUser(iUser);
  }

  protected void checkServerAccess(final String iResource) {
    if (serverUser == null)
      throw new OSecurityAccessException("Server user not authenticated.");

    if (!OServerMain.server().authenticate(serverUser.name, null, iResource))
      throw new OSecurityAccessException("User '" + serverUser.name + "' can't access to the resource [" + iResource
          + "]. Use another server user or change permission in the file config/orientdb-server-config.xml");
  }
View Full Code Here

        if (dbPool == null) {
          dbPool = new ODatabasePoolAbstract<OGraphDatabase>(this, iMinSize, iMaxSize) {

            public OGraphDatabase createNewResource(final String iDatabaseName, final Object... iAdditionalArgs) {
              if (iAdditionalArgs.length < 2)
                throw new OSecurityAccessException("Username and/or password missed");

              final OGraphDatabasePooled db = new OGraphDatabasePooled((OGraphDatabasePool) owner, iDatabaseName,
                  (String) iAdditionalArgs[0], (String) iAdditionalArgs[1]);

              ODatabaseRecordThreadLocal.INSTANCE.set(db);
View Full Code Here

        if (dbPool == null) {
          dbPool = new ODatabasePoolAbstract<ODatabaseObjectTx>(this, iMinSize, iMaxSize) {

            public ODatabaseObjectTx createNewResource(final String iDatabaseName, final Object... iAdditionalArgs) {
              if (iAdditionalArgs.length < 2)
                throw new OSecurityAccessException("Username and/or password missed");

              final ODatabaseObjectTxPooled db = new ODatabaseObjectTxPooled((ODatabaseObjectPool) owner, iDatabaseName,
                  (String) iAdditionalArgs[0], (String) iAdditionalArgs[1]);

              ODatabaseRecordThreadLocal.INSTANCE.set(db.getUnderlying());
View Full Code Here

   * @return The role that has granted the permission if any, otherwise a OSecurityAccessException exception is raised
   * @exception OSecurityAccessException
   */
  public ORole allow(final String iResource, final int iOperation) {
    if (roles == null || roles.isEmpty())
      throw new OSecurityAccessException(document.getDatabase().getName(), "User '" + document.field("name")
          + "' has no role defined");

    final ORole role = checkIfAllowed(iResource, iOperation);

    if (role == null)
      throw new OSecurityAccessException(document.getDatabase().getName(), "User '" + document.field("name")
          + "' has no the permission to execute the operation '" + ORole.permissionToString(iOperation)
          + "' against the resource: " + iResource);

    return role;
  }
View Full Code Here

        if (dbPool == null) {
          dbPool = new ODatabasePoolAbstract<ODatabaseDocumentTx>(this, iMinSize, iMaxSize) {

            public ODatabaseDocumentTx createNewResource(final String iDatabaseName, final Object... iAdditionalArgs) {
              if (iAdditionalArgs.length < 2)
                throw new OSecurityAccessException("Username and/or password missed");

              final ODatabaseDocumentTxPooled db = new ODatabaseDocumentTxPooled((ODatabaseDocumentPool) owner, iDatabaseName,
                  (String) iAdditionalArgs[0], (String) iAdditionalArgs[1]);

              ODatabaseRecordThreadLocal.INSTANCE.set(db);

              return db;
            }

            public ODatabaseDocumentTx reuseResource(final String iKey, final Object[] iAdditionalArgs,
                final ODatabaseDocumentTx iValue) {
              ODatabaseRecordThreadLocal.INSTANCE.set(iValue);

              ((ODatabaseDocumentTxPooled) iValue).reuse(owner);
              if (iValue.getStorage().isClosed())
                // STORAGE HAS BEEN CLOSED: REOPEN IT
                iValue.getStorage().open((String) iAdditionalArgs[0], (String) iAdditionalArgs[1], null);
              else if (!iValue.getUser().checkPassword((String) iAdditionalArgs[1]))
                throw new OSecurityAccessException(iValue.getName(), "User or password not valid for database: '"
                    + iValue.getName() + "'");

              return iValue;
            }
          };
View Full Code Here

      final String dbName = getDatabase().getName();

      final OUser user = getUser(iUserName);
      if (user == null)
        throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");

      if (user.getAccountStatus() != STATUSES.ACTIVE)
        throw new OSecurityAccessException(dbName, "User '" + iUserName + "' is not active");

      if (getDatabase().getStorage() instanceof OStorageEmbedded) {
        // CHECK USER & PASSWORD
        if (!user.checkPassword(iUserPassword)) {
          // WAIT A BIT TO AVOID BRUTE FORCE
          try {
            Thread.sleep(200);
          } catch (InterruptedException e) {
          }
          throw new OSecurityAccessException(dbName, "User or password not valid for database: '" + dbName + "'");
        }
      }

      return user;
View Full Code Here

        false);
  }

  protected ODatabaseDocumentTx getProfiledDatabaseInstance(final OHttpRequest iRequest) throws InterruptedException {
    if (iRequest.authorization == null)
      throw new OSecurityAccessException(iRequest.databaseName, "No user and password received");

    final List<String> parts = OStringSerializerHelper.split(iRequest.authorization, ':');

    return OSharedDocumentDatabase.acquire(iRequest.databaseName, parts.get(0), parts.get(1));
  }
View Full Code Here

        if (dbPool == null) {
          dbPool = new ODatabasePoolAbstract<ODatabaseObjectTx>(this, iMinSize, iMaxSize) {

            public ODatabaseObjectTx createNewResource(final String iDatabaseName, final String... iAdditionalArgs) {
              if (iAdditionalArgs.length < 2)
                throw new OSecurityAccessException("Username and/or password missed");

              return new ODatabaseObjectTxPooled((ODatabaseObjectPool) owner, iDatabaseName, iAdditionalArgs[0], iAdditionalArgs[1]);
            }

            @Override
View Full Code Here

TOP

Related Classes of com.orientechnologies.orient.core.exception.OSecurityAccessException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.