Orientdb Cant open Database from Java - orientdb

I created a database out of the orientdb console:
create database plocal:/C:/Development/orientdb/databases/testdb root root plocal graph
I started the server to make sure my database was created successfully. I opened
the webinterface:
localhost:2480
And i logged in into testdb using root as user and root as password. Everything
worked fine. But when i now want to connect to my database from Java-Code:
OrientGraph graph = null;
try {
graph = new OrientGraph("plocal:C:/Development/orientdb/databases/testdb", "root", "root");
System.out.println("success");
} catch(OException e) {
System.out.println("no success - " + e.getMessage());
e.printStackTrace();
} finally {
if(graph != null) {
graph.shutdown();
}
}
I get the following exception:
Exception in thread "main" com.orientechnologies.orient.core.exception.OSecurityAccessException: User or password not valid for database: 'testdb'
at com.orientechnologies.orient.core.metadata.security.OSecurityShared.authenticate(OSecurityShared.java:150)
at com.orientechnologies.orient.core.metadata.security.OSecurityProxy.authenticate(OSecurityProxy.java:83)
at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.open(ODatabaseRecordAbstract.java:128)
at com.orientechnologies.orient.core.db.ODatabaseWrapperAbstract.open(ODatabaseWrapperAbstract.java:49)
at com.orientechnologies.orient.core.db.graph.OGraphDatabase.open(OGraphDatabase.java:92)
at de.hof.iisys.relationExtraction.freebase.tinkerpop.DAO.openGraph(DAO.java:30)
at de.hof.iisys.relationExtraction.freebase.main.Main.main(Main.java:44)
Why he is telling me that username or password is wrong when its not?

In "create database" command from the console, user and password are used only to authenticate against a remote database. With "plocal", "local" and "memory" URL the admin user is always "admin" with password "admin".
So use:
graph = new OrientGraph("plocal:C:/Development/orientdb/databases/testdb", "admin", "admin");
Starting from OrientDB 1.7-SNAPSHOT the console accepts only the URL for such cases:
create database plocal:/C:/Development/orientdb/databases/testdb

Related

VertX mongo auth client returns : No account found for user [username]

I am using mongodb Community edition. I have created a user in the mongodb. The user exists and the Vertx mongodb client successfully starts when config is initialized with this user.
var mongoconfig = {
"connection_string": "mongodb://127.0.0.1:27017",
"db_name": "admin",
"username": "username",
"password": "password",
"authSource": "admin" };
The db.auth command returns 1 for the same user from mongo shell.
db.getName()
admin
db.auth("username","password");
1
Now, when I try to authenticate with the same user using mongo AuthProvider implementation, there is an error returned:
io.vertx.ext.auth.mongo.AuthenticationException: No account found for user [username]
My code is exactly as per the Vertx mongo authprovider implementation example.
var mongoClient = MongoClient.createShared(vertx, mongoconfig);
var authProperties = {};
var authProvider = MongoAuth.create(mongoClient, authProperties);
var authInfo = { "username" : "username", "password" : "password" };
Has anyone encountered this issue before? Thanks a lot in advance.
Vert.x Auth Mongo does not use database accounts to authenticate users.
Instead, it uses a specific collection in your database (by default, the user collection).
Check out the docs section about Auth Mongo implementation.

How to destroy Postgres databases owned by other users in RDS using Terraform?

I managed to nicely get Terraform creating databases and roles in an RDS Postgres database but due to the stripped down permissions of the rds_superuser I can't see an easy way to destroy the created databases that are owned by another user.
Using the following config:
resource "postgresql_role" "app" {
name = "app"
login = true
password = "foo"
skip_reassign_owned = true
}
resource "postgresql_database" "database" {
name = "app_database"
owner = "${postgresql_role.app.name}"
}
(For reference the skip_reassign_owned is required because the rds_superuser group doesn't get the necessary permissions to reassign ownership)
leads to this error:
Error applying plan:
1 error(s) occurred:
* postgresql_database.database (destroy): 1 error(s) occurred:
* postgresql_database.database: Error dropping database: pq: must be owner of database debug_db1
Terraform does not automatically rollback in the face of errors.
Instead, your Terraform state file has been partially updated with
any resources that successfully completed. Please address the error
above and apply again to incrementally change your infrastructure.
Using local-exec provisioners I was able to grant the role that owned the database to the admin user and the application user:
resource "aws_db_instance" "database" {
...
}
provider "postgresql" {
host = "${aws_db_instance.database.address}"
port = 5432
username = "myadminuser"
password = "adminpassword"
sslmode = "require"
connect_timeout = 15
}
resource "postgresql_role" "app" {
name = "app"
login = true
password = "apppassword"
skip_reassign_owned = true
}
resource "postgresql_role" "group" {
name = "${postgresql_role.app.name}_group"
skip_reassign_owned = true
provisioner "local-exec" {
command = "PGPASSWORD=adminpassword psql -h ${aws_db_instance.database.address} -U myadminuser postgres -c 'GRANT ${self.name} TO myadminuser, ${postgresql_role.app.name};'"
}
}
resource "postgresql_database" "database" {
name = "mydatabase"
owner = "${postgresql_role.group.name}"
}
which seems to work compared to setting ownership only for the app user. I do wonder if there's a better way I can do this without having to shell out in a local-exec though?
After raising this question I managed to raise a pull request with the fix that was released in in version 0.1.1 of the Postgresql provider so now works fine in the latest release of the provider.

mongodb authorization exception in JMeter : code13

In MongoDB 3.2 I've setup a user with rights:
db.createUser(
{
user: "username",
pwd: "pass",
roles: [ { role: "readWrite", db: "dbname" }]
}
)
db.auth("username", "pass" )
When I use the JMeter(2.13) to connect to the database (using Jmeter's elements MongoDB Source Config , MongoDB Script) and run a query like this:
db.mycollectionname.find()
I get this error:
error: { "$err" : "not authorized on dbname to execute command { $eval: \"db.mycollectionname.find()\", args: [] }" , "code" : 13}
While I have provided all the necessary details Server Address List , Database , User , Password to Jmeter's MongoDB Source Config , MongoDB Script respectively.
Any ideas what can be happening?
I had the same issue. I had to set up a user with eval permissions even though this is not recommended (even the admin user does not have these permissions).
Try that and change you script to look at the new user and it should work.

grails, mongodb - multiple dbs

Is it possible to create aapliaction in grails that works the way:
User login with password and login to apliaction (authentication with spring security and postgredb), then aplication geting url to mongodb database (one per user), and then I configre application to use this db (with working mongo maped domain class)
If I am not wrong, you are asking about possibility of saving data in two data stores(Mongodb and Postgredb). In Postgredb, you want to store Spring Security authentication data and other application data in Mongodb.Yes, this is possible. My current project had similar requirements and we are using MySQL and MongoDb.
Yes you can use Mongo and postgre both using following line of code in dataSource.groovy
development {
grails {
mongo {
host = "localhost"
username = ""
password = ""
databaseName = "schema_name"
}
}
dataSource_lookup {
dialect = 'org.hibernate.dialect.PostgreSQLDialect'
pooled = true
driverClassName = 'org.postgresql.Driver'
username = "postgres"
password = "admin"
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:postgresql://localhost:5432/schama_name?prepareThreshold=5&socketTimeout=5400"
}
}

MongoDB user authentication performing actions

I have installed MongoDB for my research and I created to DBs: mydb, jobs
I created a user:
db.createUser( { user: "devdbuser", pwd: "123456", roles: [ "readWrite" ] } )
Then in my jave code I am trying:
MongoClient client = new MongoClient(Arrays.asList(new ServerAddress[] { new ServerAddress("localhost", 27017)}),
Arrays.asList(new MongoCredential[] { MongoCredential.createMongoCRCredential("devdbuser", "mydb", "123456".toCharArray()) } ));
DB myDB = client.getDB("jobs"); // Here I get the jobs DB with user I created for 'mydb'
DBCollection collection = myDB.getCollection("myfirstcollection");
collection.insert((DBObject)JSON.parse("{\"name\": \"First user\", \"email\": \"first_user#mail.com\"}"));
client.close();
Please notice then when I create the MongoClient I am requesting to connect to 'mydb' and I provide the credentials for the created user.
But when I take the jobs DB and try to insert data to a collection everything works well.
I would expect an error that user has no privileges, am I missing something?
Thank you for your help.
You have created a user devdbuser with readWrite role. Due to which devdbuser acquires all the privileges of the read and has the ability to modify data of all non-system collections.
If you try to create credentials with "jobs" database instead of "mydb" then authentication would fail.
MongoClient client = new MongoClient(Arrays.asList(new ServerAddress[] { new ServerAddress("localhost", 27017)}),
Arrays.asList(
new MongoCredential[] { MongoCredential.createMongoCRCredential("devdbuser",
"jobs", "123456".toCharArray()) } ));
Error Stacktrace
com.mongodb.CommandFailureException: { "serverUsed" : "localhost/127.0.0.1:27017" , "ok" : 0.0 , "errmsg" : "auth failed" , "code" : 18}
Essentially user once authenticated on "mydb" but has readWrite permission for collections across database