OrientDB Server Error

817 Views Asked by At

I have a Problem with the orientjs Driver (https://github.com/orientechnologies/orientjs) or my OrientDB (v2.1.15). I have a Node.js Server and open a Connection to the Database Server like this:

var OrientDB = require('orientjs');
var orientserver = OrientDB({
    host: 'localhost',
    port: 2424,
    username: 'root',
    password: 'Orientdb'
});

Next I open a Database Connection and work with this DB, all works fine to this point. But if I want to list all Databases with the orientserver.list() Method I get this Error:

Unhandled rejection OrientDB.RequestError: Server user not authenticated.
at Operation.parseError (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/protocol28/operation.js:855:13)
at Operation.consume (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/protocol28/operation.js:446:35)
at Connection.process (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/connection.js:383:17)
at Connection.handleSocketData (/home/mklaus/IdeaProjects/Thesis/node_modules/orientjs/lib/transport/binary/connection.js:284:17)
at emitOne (events.js:90:13)
at Socket.emit (events.js:182:7)
at readableAddChunk (_stream_readable.js:147:16)
at Socket.Readable.push (_stream_readable.js:111:10)
at TCP.onread (net.js:525:20)

To find the Issue I logged my Server at this Moment and get:

Server {
  useToken: false,
  logger: 
   { error: [Function: bound bound ],
     log: [Function: bound bound ],
     debug: [Function] },
  transport: 
   BinaryTransport {
     domain: null,
     _events: { reset: [Function: bound ] },
     _eventsCount: 1,
     _maxListeners: Infinity,
     connecting: 
      Promise {
        _bitField: 268566529,
        _fulfillmentHandler0: undefined,
        _rejectionHandler0: undefined,
        _progressHandler0: undefined,
        _promise0: undefined,
        _receiver0: undefined,
        _settledValue: [Circular],
        _boundTo: [Circular] },
     closing: false,
     retries: 0,
     maxRetries: 5,
     host: 'localhost',
     port: 2424,
     username: 'admin',
     password: 'admin',
     servers: [ [Object] ],
     currentServer: 0,
     enableRIDBags: true,
     useToken: false,
     token: <Buffer >,
     sessionId: 62,
     logger: 
      { error: [Function: bound bound ],
        log: [Function: bound bound ],
        debug: [Function] },
     connection: 
      Connection {
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: Infinity,
        host: 'localhost',
        port: 2424,
        socket: [Object],
        logger: [Object],
        enableRIDBags: true,
        closing: false,
        reconnectNow: false,
        protocol: [Object],
        queue: [],
        writes: [],
        remaining: null,
        connecting: false,
        protocolVersion: 32 },
     skipServerConnect: true },
  config: 
   { get: [Function: bound ],
     set: [Function: bound ],
     list: [Function: bound ] },
  domain: null,
  _events: 
   { reset: 
      [ [Function: bound ],
        [Function: bound ],
        [Function: bound ],
        [Function: bound ],
        [Function: bound ] ],
     error: [ [Object], [Object] ] },
  _eventsCount: 2,
  _maxListeners: Infinity }

As you can see the username and the Password is wrong. Someone know why this happen? Why I cant have Access to the Server after working with one DB on it?

*edit Here is the Code of my nodejs Server (Not everything, just the important parts)

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');
var stringify = require('json-stringify-safe');
var routes = require('./routes/index');
var users = require('./routes/users');

var passport = require('passport');
var expressSession = require('express-session');
var Strategy = require('passport-local').Strategy;

var users = {};
var databases = {};

var OrientDB = require('orientjs');

var orientserver = OrientDB({
    host: 'localhost',
    port: 2424,
    httpPort: 2480,
    username: 'root',
    password: 'Orientdb'
});
passport.use(new Strategy({
        usernameField: 'username',
        passwordField: 'password',
        passReqToCallback: true
    },
    function(req, username, password, cb) {
        var sessID = req.sessionID;
        var dbkey = username+"_"+req.params.database;
        if(dbkey in databases) {
        } else {
            databases[dbkey] = orientserver.use({
                name: req.params.database,
                username: username,
                password: password
            });
        }
        users[sessID]= {id: sessID, username: username, database: dbkey};
        return cb(null, users[sessID]);
    }));
    var app = express();

// view engine setup
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));

app.use(expressSession({secret: 'mySecretKey', cookie: { maxAge: 60000 }}));
app.use(passport.initialize());
app.use(passport.session());

app.get('/', function (req, res) {

});

app.get('/getAllProjects', function(req, res) {

    //https://github.com/kriskowal/q
    orientserver.list()
        .then(function (dbs) {
            var json = [];
            dbs.forEach(function(value, index) {
                json.push({"name": value.name});
            });
            //console.log('There are ' + dbs.length + ' databases on the server.');
            res.status(200).send(json);
        });
});

app.post('/:database',
    passport.authenticate('local', { failureRedirect: '/' }),
    function(req, res) {
        res.redirect("/"+req.params.database);
    });

So when I send the second Request to getAllProjects I get the Error.

0

There are 0 best solutions below