Skip to content

Commit

Permalink
Server_realtime_auth: add dbname to mongoose connection options when …
Browse files Browse the repository at this point in the history
…configured.
  • Loading branch information
riclolsen committed Aug 19, 2024
1 parent 348b423 commit 56f17d9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 16 deletions.
84 changes: 68 additions & 16 deletions src/server_realtime_auth/app/controllers/auth.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ exports.updateTag = async (req, res) => {
let _id = req.body._id
delete req.body._id

var IsNumberVal = function (value) {
let IsNumberVal = function (value) {
if (/^(\-|\+)?([0-9]+(\.[0-9]+)?)$/.test(value)) return true
return false
}
Expand Down Expand Up @@ -174,6 +174,7 @@ exports.updateProtocolConnection = async (req, res) => {
'I104M',
'TELEGRAF-LISTENER',
'OPC-UA_SERVER',
'ICCP_SERVER',
].includes(req?.body?.protocolDriver)
) {
if (
Expand All @@ -197,6 +198,9 @@ exports.updateProtocolConnection = async (req, res) => {
case 'TELEGRAF-LISTENER':
req.body.ipAddressLocalBind = '0.0.0.0:51920'
break
case 'ICCP_SERVER':
req.body.ipAddressLocalBind = '0.0.0.0:102'
break
}
}
}
Expand All @@ -213,6 +217,8 @@ exports.updateProtocolConnection = async (req, res) => {
'I104M',
'TELEGRAF-LISTENER',
'OPC-UA_SERVER',
'ICCP',
'ICCP_SERVER',
].includes(req?.body?.protocolDriver)
) {
if (!('ipAddresses' in req.body)) {
Expand All @@ -221,19 +227,32 @@ exports.updateProtocolConnection = async (req, res) => {
}

if (
['OPC-UA', 'TELEGRAF-LISTENER', 'MQTT-SPARKPLUG-B', 'IEC61850', 'PLC4X', 'OPC-DA'].includes(
req?.body?.protocolDriver
)
[
'OPC-UA',
'TELEGRAF-LISTENER',
'MQTT-SPARKPLUG-B',
'IEC61850',
'PLC4X',
'OPC-DA',
'ICCP',
].includes(req?.body?.protocolDriver)
) {
if (!('autoCreateTags' in req.body)) {
req.body.autoCreateTags = true
}
}

if (
['MQTT-SPARKPLUG-B', 'OPC-UA_SERVER', 'IEC61850', 'PLC4X', 'OPC-DA'].includes(
req?.body?.protocolDriver
)
[
'MQTT-SPARKPLUG-B',
'OPC-UA_SERVER',
'IEC61850',
'PLC4X',
'OPC-DA',
'OPC-DA_SERVER',
'ICCP',
'ICCP_SERVER',
].includes(req?.body?.protocolDriver)
) {
if (!('topics' in req.body)) {
req.body.topics = []
Expand Down Expand Up @@ -313,12 +332,39 @@ exports.updateProtocolConnection = async (req, res) => {
}
}

if (['OPC-UA', 'OPC-UA_SERVER', 'OPC-DA'].includes(req?.body?.protocolDriver)) {
if (
['OPC-UA', 'OPC-UA_SERVER', 'OPC-DA'].includes(req?.body?.protocolDriver)
) {
if (!('timeoutMs' in req.body)) {
req.body.timeoutMs = 20000.0
}
}

if (
['ICCP', 'ICCP_SERVER'].includes(req?.body?.protocolDriver)
) {
if (!('aeQualifier' in req.body)) {
req.body.aeQualifier = 12.0
}
if (!('localAppTitle' in req.body)) {
req.body.localAppTitle = '1.1.1.998'
}
if (!('localSelectors' in req.body)) {
req.body.localSelectors = '0 0 0 2 0 2 0 2'
}
}

if (
['ICCP'].includes(req?.body?.protocolDriver)
) {
if (!('remoteAppTitle' in req.body)) {
req.body.remoteAppTitle = '1.1.1.999'
}
if (!('remoteSelectors' in req.body)) {
req.body.remoteSelectors = '0 0 0 1 0 1 0 1'
}
}

if (['OPC-UA'].includes(req?.body?.protocolDriver)) {
if (!('configFileName' in req.body)) {
req.body.configFileName = '../conf/Opc.Ua.DefaultClient.Config.xml'
Expand Down Expand Up @@ -416,9 +462,15 @@ exports.updateProtocolConnection = async (req, res) => {
}

if (
['IEC60870-5-101', 'IEC60870-5-104', 'DNP3', 'PLCTAG', 'IEC61850', 'PLC4X', 'OPC-DA'].includes(
req?.body?.protocolDriver
)
[
'IEC60870-5-101',
'IEC60870-5-104',
'DNP3',
'PLCTAG',
'IEC61850',
'PLC4X',
'OPC-DA',
].includes(req?.body?.protocolDriver)
) {
if (!('giInterval' in req.body)) {
req.body.giInterval = 300
Expand Down Expand Up @@ -959,7 +1011,7 @@ exports.signup = async (req, res) => {
// Will check for valid user and then create a JWT access token
exports.signin = async (req, res) => {
try {
let user = await User.findOne({
const user = await User.findOne({
username: req.body.username,
})
.populate('roles', '-__v')
Expand All @@ -969,7 +1021,7 @@ exports.signin = async (req, res) => {
return res.status(200).send({ ok: false, message: 'User Not found.' })
}

var passwordIsValid = bcrypt.compareSync(req.body.password, user.password)
const passwordIsValid = bcrypt.compareSync(req.body.password, user.password)

if (!passwordIsValid) {
return res.status(200).cookie('x-access-token', null).send({
Expand All @@ -979,8 +1031,8 @@ exports.signin = async (req, res) => {
}

// Combines all roles rights for the user
var authorities = []
var rights = {
let authorities = []
let rights = {
isAdmin: false,
changePassword: false,
sendCommands: false,
Expand Down Expand Up @@ -1040,7 +1092,7 @@ exports.signin = async (req, res) => {
rights.maxSessionDays = user.roles[i].maxSessionDays
}

var token = jwt.sign(
const token = jwt.sign(
{ id: user.id, username: user.username, rights: rights },
config.secret,
{
Expand Down
3 changes: 3 additions & 0 deletions src/server_realtime_auth/load-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ function getMongoConnectionOptions(configObj) {
? ReadPreference.SECONDARY_PREFERRED
: ReadPreference.PRIMARY,
}
if ( 'mongoDatabaseName' in configObj && configObj.mongoDatabaseName!=='' ) {
connOptions.dbName = configObj.mongoDatabaseName
}

if (
typeof configObj.tlsCaPemFile === 'string' &&
Expand Down

0 comments on commit 56f17d9

Please sign in to comment.