@manyos/smileconnect-api 1.33.0 → 1.34.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -11,6 +11,7 @@ const JwtStrategy = require('passport-jwt').Strategy,
11
11
  const bodyParser = require('body-parser');
12
12
 
13
13
  const config = require('./util/config');
14
+ const authUtil = require('./util/auth');
14
15
 
15
16
  const cors = require('cors');
16
17
 
@@ -83,6 +84,8 @@ if (audienceArray.length > 0) {
83
84
  opts.audience = audienceArray;
84
85
  }
85
86
 
87
+ opts.passReqToCallback = true
88
+
86
89
  // Do any necessary shutdown logic for our application here
87
90
  const shutdown = (signal, value) => {
88
91
  console.log("shutdown!");
@@ -130,12 +133,20 @@ app.use(compression()); //Compress all routes
130
133
 
131
134
  log.debug('Passport Opts', opts);
132
135
  passport.use(
133
- new JwtStrategy(opts, function (jwt_payload, done) {
136
+ new JwtStrategy(opts, function (req, jwt_payload, done) {
134
137
  //log.info(jwt_payload);
135
138
  //log.info('token', jwt_payload.sub);
136
139
  //TODO: Config error abfangen
137
140
  //TODO: Add AdminScope and Impersonate
138
- const clientId = jwt_payload[SSO_CLIENTNAME_ATTRIBUTE];
141
+ let clientId = jwt_payload[SSO_CLIENTNAME_ATTRIBUTE];
142
+
143
+ //check for master client
144
+ const requestedClientId = req.query.clientId
145
+ if (requestedClientId && authUtil.isMasterClient(clientId)) {
146
+ log.debug(`client ${clientId} acts as ${requestedClientId}`)
147
+ clientId = requestedClientId
148
+ }
149
+
139
150
  const user = {
140
151
  'id': jwt_payload.sub,
141
152
  'azp': jwt_payload.azp,
@@ -159,6 +170,7 @@ passport.use(
159
170
 
160
171
  app.use(bodyParser.json({limit: '200mb'}));
161
172
  app.use(bodyParser.urlencoded({limit: '200mb', extended: true}));
173
+
162
174
  //health check
163
175
  app.use('/v1/health', function (req, res, next) {
164
176
  res.json({status:"ok"})
package/conf/clients.json CHANGED
@@ -21,8 +21,10 @@
21
21
  "scripts": {}
22
22
  },
23
23
  "incident": {
24
- "basequery": "1=2",
25
- "fields": [],
24
+ "basequery": "1=1",
25
+ "fields": [
26
+ "Description"
27
+ ],
26
28
  "constants": [],
27
29
  "scripts": {}
28
30
  },
@@ -82,6 +82,15 @@ List of users who are allowed to access /v1/appconfig endpoints.
82
82
  Sample:
83
83
  ADMIN_USERS=username1, username2
84
84
 
85
+ ### MASTER_CLIENTS
86
+
87
+ List of clients that can act on behalf of other clients.
88
+
89
+ The URL Parameter *clientId* is used for this.
90
+
91
+ Sample:
92
+ MASTER_CLIENTS=idm,adminTool
93
+
85
94
  ## Cache
86
95
 
87
96
  ### CACHETTL_CMDB
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@manyos/smileconnect-api",
3
- "version": "1.33.0",
3
+ "version": "1.34.0",
4
4
  "description": "A proxy and abstraction layer for BMCs IT Service Management Suite",
5
5
  "main": "app.js",
6
6
  "scripts": {
package/util/auth.js CHANGED
@@ -19,6 +19,20 @@ function isAuthorizedAdmin(req, res, next) {
19
19
  }
20
20
  }
21
21
 
22
+ function isMasterClient(clientId) {
23
+ const masterClients = process.env.MASTER_CLIENTS;
24
+ if (masterClients !== null
25
+ && masterClients !== undefined
26
+ && clientId !== null
27
+ && clientId !== undefined
28
+ && isUserInList(masterClients, clientId)) {
29
+ log.debug('master client authorized', clientId);
30
+ return true
31
+ } else {
32
+ return false
33
+ }
34
+ }
35
+
22
36
  function isUserInList(userList, userName) {
23
37
  log.debug('Check if user is in List', userName, userList)
24
38
  if (userList !== null && userList !== undefined && userName !== null && userName !== undefined) {
@@ -33,5 +47,5 @@ function isUserInList(userList, userName) {
33
47
  }
34
48
 
35
49
  module.exports = {
36
- isAuthorizedAdmin
50
+ isAuthorizedAdmin, isMasterClient
37
51
  }