How to configure apache tomcat server to the oracle database - node.js

I have created an application based upon node JS and react JS, here I am using the oracle database for the data with node JS. The issue here is that the application is able to run but it does not able to make any API calls because all the data that needed to be handled is on the oracle database, I think the application does not able to establish a connection to the oracle database server.
I am new to this whole deployment stuff and this my first web based project.
Here is the configuration code for the database connectivity:
module.exports = {
database:{
user : 'user_name',
password : 'pass',
connectString : 'something'
},
jwtSecretKey: "jmvhDlong......."
};
I am using two oracle database server, one for storing the user details and the second to fetch the details:
Code for the user database server:
module.exports = {
database:{
user : 'user_name',
password : 'pass',
connectString : 'something'
},
jwtSecretKey: "jmvhDlong......."
};
Code for the database server from which the details need to be fetched:
module.exports = {
database:{
user : 'user_name',
password : 'pass',
connectString : 'something'
},
};
And don't worry about the user, password and connectstring those are correct.
I need to bypass the apache server configuration so that the application can able to connect to the oracle database and able to make the API calls.

do you want to use appache as a user to login to an oracle-db?
there is a parameter for ms-sql, called integratedSecurity (=true), and you can set a software as a user in db, so you can acces ms-sql with tomcat.
if you want to do something like this, i think this isnt possible, my knowlegde is 2years old, dont know if something changed meanwhile.

Related

Mongoose times out if databasename is set

I'm rather new to Linux, NodeJs and MongoDB but I setup a Linux Server running a MongoDB (db version v4.0.16).
I added two users like this. One called mongo-admin and one called mongo-root.
# mongo
> use admin
> db.createUser({
user: "mongo-admin",
pwd: "myAwesomePassword",
roles: [ { role: "userAdminAnyDatabase", db: "admin" } ]
})
> db.createUser({
user: "mongo-root",
pwd: "myAwesomePassword",
roles: [ { role: "root", db: "admin" } ]
})
I then enabled authentication in /etc/mongod.conf like this
security:
authorization: "enabled"
On my development Machine I setup a little NodeJS script that tries to connect to the server using mongoose, and simply add a document there.
Now the situation is very strange. If I use mongodb://mongo-root:myAwesomePassword#100.100.100.100:27017 as a connectionstring, everything works fine and a new DB named test is created and the document is added. But as soon as I add a /mydatabasename at the end of the string, mongoose will suddntly time out after 30 seconds of trying to connect.
If I connect to MongoDB using a Software called Robo3T, I can connect just fine, and I also have the rights to create a new database just fine.
I also checked the /etc/log/mongod.log and found this error:
2020-02-05T07:40:22.006+0000 I ACCESS [conn27] SASL SCRAM-SHA-1 authentication failed for mongo-root on mydatabasename from client 101.101.101.101:51270 ; UserNotFound: Could not find user mongo-admin#mydatabasename
This is the way I connect to the DB
mongoose.connect(
"mongodb://mongo-root:myAwesomePassword#100.100.100.100:27017/mydatabasename",
{
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true
}
);
It seems like mongodb is looking for the user in the database that should be created instead of in the admin db.
Check Connection String URI Format
mongodb://[username:password#]host1[:port1][,...hostN[:portN]][/[database][?options]]
/database
Optional. The name of the database to authenticate if the connection
string includes authentication credentials in the form of
username:password#. If /database is not specified and the connection
string includes credentials, the driver will authenticate to the admin
database. See also authSource.
authSource
Specify the database name associated with the user’s credentials.
authSource defaults to the database specified in the connection
string.
Actually the documentation is not 100% correct for this point, the connection string must be like this:
mongodb://mongo-root:myAwesomePassword#100.100.100.100:27017/mydatabasename?authSource=admin

How to connect to a postgreSQL database stored on a server and request this database? Node.js

I am working to develop a server with Node.js to request a postgreSQL database. My problem is, that I can't connect (with my local computer, using wifi connection, not ethernet) to this server, and also to the postgreSQL.
I have an username and a password to connect to the server, and also an another username and password to connect the database.
How can to connect both of those, and get the information I want from the postgreSQL database? Can I connect to this server with command bash like ssh but in node.js?
I did something like this:
var ssh = new SSH({
host: 'hostname',
user: 'user',
pass: 'password'
});
or something like this:
var connectionString = 'postgres://user:password#database:port';
I have another problem, my teacher give me a password containing a #, and I think this will make some problems when I have to put my password:
postgres://user:pass**#**word#database:port
How to bypass this password problem?
you need to pass ip address of machine where database resides in place of hostname.

How do I correctly authenticate in mongo for a user that has access to multiple databases?

I have a user with the role: {role: 'root', db:'admin'} which should have access to all the databases in my mongo instance. I'm using mongoskin in node.js to interact with mongo. My problem is that it isn't correctly accessing my databases. If I authenticate with
mongodb://owner:mylocalpassword#localhost:27017/mydatabase
It simply gives me MongoError: Authentication failed. If I instead auth with:
mongodb://owner:mylocalpassword#localhost:27017/admin
it authenticates, but I can't access mydatabase.
Here's my connection code:
var connection = mongoskin.db("mongodb://owner:mylocalpassword#localhost:27017/admin", {journal:true, auto_reconnect:true})
I assume that since I'm accessing the admin database there, that's the only one it interacts with. So I tried do then do this:
var mydatabaseConnection = connection.db('mydatabase')
But when I use that, my app is returning no results for queries on collections that I know have data. What am I doing wrong here? How do I get this user to access a database other than admin?
Ok, so I found out that mongoskin's db method simply doesn't work. Finally I'm forced to completely remove mongoskin from my codebase. The real answer here is don't use mongoskin.
This code worked with mongo native:
MongoClient.connect("mongodb://owner:mylocalpassword#localhost:27017/admin", {journal: true, auto_reconnect:true}).then(function(db) {
console.log("Connected!")
var mydb = db.db('mydatabase')
var User = mydb.collection('User')
return User.find({}).toArray().then(function(users) {
console.log(users)
db.close()
})
}).catch(function(e) {
console.log(e.stack)
})

Bitnami Meanstack Mongoose Connection

I created a simple service in Ubuntu 16.04 with mongo db node and express to return data to an angular 2 app.
I have a file called server.js that connects to a local mongodb instance with a database called game and a collection called players. It works fine installed on my local machine. However I am trying to deploy it with Bitnami's mean stack image on amazon ec2. (bleh mouth full). I have set ports correctly according to this guide, and I can connect to it remotely. However, I can't get mongoose to connect to any database. here is my code that works on my local machine.
mongoose.connect('mongodb://localhost:27017/game');
router.route('/player')
.get(function(req, res) {
console.log(mongoose.connection.readyState);
Player.find({"player":user,"password":password},function(err, Test) {
if (err)
res.send(err);
res.json(Test);
});
});
And here is my adjusted code for the mean stack image
mongoose.connect('mongodb://root:"My-Root-Password#127.0.0.1:27017/game');
router.route('/player')
.get(function(req, res) {
console.log(mongoose.connection.readyState);
Player.find({"player":user,"password":password},function(err, Test) {
if (err)
res.send(err);
res.json(Test);
});
});
On my local machine I get a value of 1 on the console.log and value of zero on the mean stack image. I'm not sure how to connect to bitnami's mongo instance with mongoose. I have checked that game exist and has the data I want.
I found a fix Although I don't yet fully understand it. It came from the guide I posted here . First I had to un comment out the section of the mongodb.conf that says noauth = true then comment out the line that says auth = true. I then restart mongo, and create a new user with permissions to read and write the the data base I want to use like this
db.createUser({
user: "NEW USERNAME",
pwd: "NEW PASSWORD",
roles:[
{
"role" : "readWrite",
"db": "game"
}
]})
After creating the user I undo what I did to noauth = true and auth = true, and restart mongodb. Then I am able to connect with mongoose like this
mongoose.connect('mongodb://NEW USERNAME:NEW PASSWORD#127.0.0.1:27017/game');
With MongoDB 3.0, they added a new authentication mechanism for MongoDB (more details in the links below).
Authentication information: https://docs.mongodb.com/manual/core/authentication/
How to use the new authentication mechanism: https://www.mongodb.com/blog/post/improved-password-based-authentication-mongodb-30-scram-explained-part-2
Due to this, the guide provides that workaround to get the connection with the database. Now, you have created that user with "readWrite" privileges on your database so you are able to use it.

In nodejs with MySQL

I am Using Nodejs with MySQL.
But problem is that My MYSQL Connection Password Able to see in browser, With this any user get my my SQL username and Password.
Is it possible no one can see my MySQL Connection permanent as its is a server side.
Can any one help me in this.
Do not send you password to client but store it in a variable inside your server-side script. On a request, use it to access database and send only the result of the operation.
If you show your code you might get a more detailed answer then this...
var connection = mysql.createConnection({
host : 'host',
user : 'dbuser',
password : "pword",
database : 'database',
});
connection.connect();
connection.query(etc etc etc)
for full example see mysql module in node.js not works in my case
or another way is to save the configuration and password details in either an env file or other file (or even sqlite db file and load it on startup/restart of your script

Resources