-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathums_ca.js
140 lines (117 loc) · 4.04 KB
/
ums_ca.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*******************************************************************************
*
*
* (c) Copyright Merative US L.P. and others 2020-2022
*
* SPDX-Licence-Identifier: Apache 2.0
*
*******************************************************************************/
"use strict";
var chain_helper = require('../utils/chain_helper.js');
var hfc = require('fabric-client');
// Use a tag to make logs easier to find
var TAG = "ums_ca.js";
var log4js = require('log4js');
var logger = log4js.getLogger(TAG);
var log_level = hfc.getConfigSetting('log_level') ? hfc.getConfigSetting('log_level') : "INFO";
logger.level = log_level;
var adminUser = null;
module.exports.setup = function () {
//setupDefaultLoginUser(adminUser);
logger.info("ums blockchain configured");
};
//============================================================
// UMS functions
//============================================================
//ready
module.exports.ready = ready;
function ready() {
return true;
}
// set default user
module.exports.setupDefaultLoginUser = setupDefaultLoginUser;
function setupDefaultLoginUser(registrar) {
logger.info('setupDefaultUser');
//Do nothing
}
//update or create login user
//return error if failed, or null if succeed
module.exports.registerLoginUser = registerLoginUser;
function registerLoginUser(id, name, password, enrollId, enrollSecret, role, email, attr, cb ) {
cb && cb(new Error("not implemented"));
}
//return the message
module.exports.changePassword = changePassword;
function changePassword(id, password, token, cb) {
cb && cb(new Error("not implemented"));
}
// return the login User object
module.exports.getLoginUser = getLoginUser;
function getLoginUser(id, cb) {
cb && cb(new Error("not implemented"));
}
// validate userId and password
module.exports.validateLoginUser = validateLoginUser;
function validateLoginUser(id, password, data, cb) {
var org = data && data["org"] ? data["org"] : null;
var channel = data && data["channel"] ? data["channel"] : null;
var isOrginChannel = chain_helper.isOrgInChannel(channel, org);
if (!isOrginChannel) {
cb && cb(new Error('invalid channel or org is not in channel'));
} else {
let attr_reqs = [{name: "role"}];
chain_helper.enrollUser(id, password, org, attr_reqs).then((enrollment) => {
let role = null;
let amap = chain_helper.getAttributesFromEnrollCert(enrollment.certificate, false);
if (amap["attrs"] && amap["attrs"]["role"]) {
role = amap["attrs"]["role"];
}
var userdata = {
id: id,
name: id,
password: password,
email: null,
role: role,
enrollId: id,
enrollSecret: password,
caOrg: org,
channel: channel,
attr: null
};
cb && cb(null, userdata);
},(err) => {
cb && cb(new Error('enroll failed'));
} );
}
}
//validate user with Headers
module.exports.validateUserByHeaders = validateUserByHeaders;
function validateUserByHeaders(headers, cb) {
cb && cb(new Error("Authentication by header not allowed with CA"));
}
//login user with headers
//cb not used
module.exports.loginUserByHeaders = loginUserByHeaders;
function loginUserByHeaders(req, res, next, cb) {
next();
}
//get default password
module.exports.getDefaultPassword = getDefaultPassword;
function getDefaultPassword(cb) {
return defaultPassword;
}
//get login url
module.exports.getLoginUrl = getLoginUrl;
function getLoginUrl(cb) {
return "/loginLocal";
}
//get logout url
module.exports.getLogoutUrl = getLogoutUrl;
function getLogoutUrl(cb) {
return "/logoutLocal";
}
//get changePassword url
module.exports.getChangePasswordUrl = getChangePasswordUrl;
function getChangePasswordUrl(cb) {
return "/changePasswordLocal";
}