-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.5.0 See merge request !315
- Loading branch information
Showing
26 changed files
with
636 additions
and
335 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "BatchRun", | ||
"plural": "BatchRuns", | ||
"base": "BaseEntity", | ||
"strict": false, | ||
"idInjection": true, | ||
"properties": {}, | ||
"validations": [], | ||
"relations": { | ||
}, | ||
"acls": [], | ||
"methods": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"name": "BatchStatus", | ||
"plural": "BatchStatus", | ||
"base": "BaseEntity", | ||
"strict": false, | ||
"idInjection": true, | ||
"properties": {}, | ||
"validations": [], | ||
"relations": { | ||
}, | ||
"acls": [], | ||
"methods": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
{ | ||
"name": "Error", | ||
"base": "BaseEntity", | ||
"plural": "errors", | ||
"idInjection": false, | ||
"description": "This Model stores all the Customized error details", | ||
"options": { | ||
"validateUpsert": true, | ||
"isFrameworkModel": true, | ||
"disableManualPersonalization":false | ||
}, | ||
"properties": { | ||
"errCode": { | ||
"type": "string", | ||
"max": 100 | ||
"name": "Error", | ||
"base": "BaseEntity", | ||
"plural": "errors", | ||
"idInjection": false, | ||
"description": "This Model stores all the Customized error details", | ||
"options": { | ||
"validateUpsert": true, | ||
"isFrameworkModel": true, | ||
"disableManualPersonalization": false | ||
}, | ||
"errMessage": { | ||
"type": "string", | ||
"max": 250 | ||
"properties": { | ||
"errCode": { | ||
"type": "string", | ||
"max": 100 | ||
}, | ||
"errMessage": { | ||
"type": "string", | ||
"max": 250 | ||
}, | ||
"errCategory": { | ||
"type": "string", | ||
"max": 100 | ||
}, | ||
"moreInformation": { | ||
"type": "string", | ||
"max": 500 | ||
} | ||
}, | ||
"moreInformation": { | ||
"type": "string", | ||
"max": 500 | ||
} | ||
}, | ||
"validations": [], | ||
"relations": {}, | ||
"acls": [], | ||
"methods": {} | ||
"validations": [], | ||
"relations": {}, | ||
"acls": [], | ||
"methods": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/** | ||
* | ||
* ©2016-2017 EdgeVerve Systems Limited (a fully owned Infosys subsidiary), | ||
* Bangalore, India. All Rights Reserved. | ||
* | ||
*/ | ||
var jwt = require('jsonwebtoken'); | ||
const loopback = require('loopback'); | ||
const log = require('oe-logger')('trusted-app'); | ||
var jwtUtil = require('../../../lib/jwt-token-util'); | ||
|
||
|
||
module.exports = function TrustedApp(trustedApp) { | ||
/** | ||
* This function accepts username and password, | ||
* and authenticates the user with service account set with trusted app | ||
* | ||
* | ||
* @param {object} data - {"username":"", "password":"", "appId":""} | ||
* @param {object} options - callcontext options | ||
* @param {function} cb - callback/next function | ||
* @returns {string} token - jwt token to use to use | ||
*/ | ||
trustedApp.authenticate = function authenticateTrustedApp(data, options, cb) { | ||
var self = this; | ||
var error; | ||
// cb = cb || utils.createPromiseCallback(); | ||
// verify the trusted app is assigned with this username | ||
if (!data.username || !data.password || !data.appId) { | ||
error = new Error(); | ||
error.message = 'username, password and appId; all three values are mandatory'; | ||
error.statusCode = 400; | ||
error.code = 'USERNAME_PASSWORD_REQUIRED'; | ||
error.retriable = false; | ||
return cb(error); | ||
} | ||
var where = { | ||
'where': { | ||
'and': [{ | ||
'username': data.username | ||
}, | ||
{ | ||
'appId': data.appId | ||
} | ||
] | ||
} | ||
}; | ||
self.findOne(where, options, function fnFetchTrustedApp(err, app) { | ||
if (err) { | ||
log.info(options, err); | ||
return cb(err); | ||
} | ||
|
||
if (app && app.appId) { | ||
log.debug(options, 'trusted app configured properly for ', data.appId, ' and username ', data.username); | ||
// make login call | ||
if (app) { | ||
var baseUser = loopback.getModelByType('BaseUser'); | ||
baseUser.login({ 'username': data.username, 'password': data.password }, options, function fnTrustedAppLoggedIn(err, user) { | ||
if (err) { | ||
log.error(options, err); | ||
return cb(err); | ||
} | ||
|
||
if (!user) { | ||
log.debug(options, 'Associated service user not found for ', data.appId, ' and username ', data.username); | ||
error = new Error(); | ||
error.message = 'Trusted app not configured properly.'; | ||
error.statusCode = 400; | ||
error.code = 'TRUSTED_APP_AUTH_FAILED'; | ||
error.retriable = false; | ||
return cb(error); | ||
} | ||
// generate a jwt for trusted app | ||
if (user && user.id) { | ||
var jwtConfig = jwtUtil.getJWTConfig(); | ||
var jwtOpts = {}; | ||
var jwtData = {}; | ||
jwtOpts.issuer = jwtConfig.issuer; | ||
jwtOpts.audience = jwtConfig.audience; | ||
// access token ttl set to jwt's expiry in seconds | ||
jwtOpts.expiresIn = user.ttl; | ||
jwtData.username = user.username; | ||
jwtData.userId = user.userId; | ||
jwtData.roles = user.roles; | ||
jwtData.tenantId = user.tenantId; | ||
jwtData.expiresIn = jwtOpts.expiresIn; | ||
jwtData[jwtConfig.keyToVerify] = app.appId; | ||
|
||
jwt.sign(jwtData, jwtConfig.secretOrKey, jwtOpts, function jwtSignCb(err, token) { | ||
if (err) { | ||
log.error(options, 'Trusred app JWT signing error ', err); | ||
log.debug(options, err); | ||
return cb(err); | ||
} | ||
|
||
cb(null, token); | ||
}); | ||
} | ||
}); | ||
} | ||
} else { | ||
log.debug(options, 'trusted app not configured properly for ', data.appId, ' and username ', data.username); | ||
error = new Error(); | ||
error.message = 'Trusted app not configured properly.'; | ||
error.statusCode = 400; | ||
error.code = 'TRUSTED_APP_ERROR'; | ||
error.retriable = false; | ||
return cb(error); | ||
} | ||
}); | ||
}; | ||
// accepts object with username, | ||
trustedApp.remoteMethod('authenticate', { | ||
description: 'authenticate a trusted app service account', | ||
accepts: [{ arg: 'data', type: 'object', required: true, http: { source: 'body' } }], | ||
http: { | ||
verb: 'POST', | ||
path: '/authenticate' | ||
}, | ||
returns: { | ||
arg: 'token', | ||
type: 'string', | ||
root: true | ||
} | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.