-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
/
authentication.js
182 lines (171 loc) · 7.22 KB
/
authentication.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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import { ReactiveCache } from '/imports/reactiveCache';
import Fiber from 'fibers';
Meteor.startup(() => {
// Node Fibers 100% CPU usage issue
// https://github.com/wekan/wekan-mongodb/issues/2#issuecomment-381453161
// https://github.com/meteor/meteor/issues/9796#issuecomment-381676326
// https://github.com/sandstorm-io/sandstorm/blob/0f1fec013fe7208ed0fd97eb88b31b77e3c61f42/shell/server/00-startup.js#L99-L129
Fiber.poolSize = 1e9;
Accounts.validateLoginAttempt(function(options) {
const user = options.user || {};
return !user.loginDisabled;
});
Authentication = {};
Authentication.checkUserId = function(userId) {
if (userId === undefined) {
const error = new Meteor.Error('Unauthorized', 'Unauthorized');
error.statusCode = 401;
throw error;
}
const admin = ReactiveCache.getUser({ _id: userId, isAdmin: true });
if (admin === undefined) {
const error = new Meteor.Error('Forbidden', 'Forbidden');
error.statusCode = 403;
throw error;
}
};
// This will only check if the user is logged in.
// The authorization checks for the user will have to be done inside each API endpoint
Authentication.checkLoggedIn = function(userId) {
if (userId === undefined) {
const error = new Meteor.Error('Unauthorized', 'Unauthorized');
error.statusCode = 401;
throw error;
}
};
// An admin should be authorized to access everything, so we use a separate check for admins
// This throws an error if otherReq is false and the user is not an admin
Authentication.checkAdminOrCondition = function(userId, otherReq) {
if (otherReq) return;
const admin = ReactiveCache.getUser({ _id: userId, isAdmin: true });
if (admin === undefined) {
const error = new Meteor.Error('Forbidden', 'Forbidden');
error.statusCode = 403;
throw error;
}
};
// Helper function. Will throw an error if the user does not have read only access to the given board
Authentication.checkBoardAccess = function(userId, boardId) {
Authentication.checkLoggedIn(userId);
const board = ReactiveCache.getBoard(boardId);
const normalAccess =
board.permission === 'public' ||
board.members.some(e => e.userId === userId && e.isActive);
Authentication.checkAdminOrCondition(userId, normalAccess);
};
if (Meteor.isServer) {
if (
process.env.ORACLE_OIM_ENABLED === 'true' ||
process.env.ORACLE_OIM_ENABLED === true
) {
ServiceConfiguration.configurations.upsert(
// eslint-disable-line no-undef
{ service: 'oidc' },
{
$set: {
loginStyle: process.env.OAUTH2_LOGIN_STYLE,
clientId: process.env.OAUTH2_CLIENT_ID,
secret: process.env.OAUTH2_SECRET,
serverUrl: process.env.OAUTH2_SERVER_URL,
authorizationEndpoint: process.env.OAUTH2_AUTH_ENDPOINT,
userinfoEndpoint: process.env.OAUTH2_USERINFO_ENDPOINT,
tokenEndpoint: process.env.OAUTH2_TOKEN_ENDPOINT,
idTokenWhitelistFields:
process.env.OAUTH2_ID_TOKEN_WHITELIST_FIELDS || [],
requestPermissions: process.env.OAUTH2_REQUEST_PERMISSIONS,
},
},
);
} else if (
process.env.OAUTH2_ENABLED === 'true' ||
process.env.OAUTH2_ENABLED === true
) {
ServiceConfiguration.configurations.upsert(
// eslint-disable-line no-undef
{ service: 'oidc' },
{
$set: {
loginStyle: process.env.OAUTH2_LOGIN_STYLE,
clientId: process.env.OAUTH2_CLIENT_ID,
secret: process.env.OAUTH2_SECRET,
serverUrl: process.env.OAUTH2_SERVER_URL,
authorizationEndpoint: process.env.OAUTH2_AUTH_ENDPOINT,
userinfoEndpoint: process.env.OAUTH2_USERINFO_ENDPOINT,
tokenEndpoint: process.env.OAUTH2_TOKEN_ENDPOINT,
idTokenWhitelistFields:
process.env.OAUTH2_ID_TOKEN_WHITELIST_FIELDS || [],
requestPermissions: process.env.OAUTH2_REQUEST_PERMISSIONS,
},
// OAUTH2_ID_TOKEN_WHITELIST_FIELDS || [],
// OAUTH2_REQUEST_PERMISSIONS || 'openid profile email',
},
);
} else if (
process.env.CAS_ENABLED === 'true' ||
process.env.CAS_ENABLED === true
) {
ServiceConfiguration.configurations.upsert(
// eslint-disable-line no-undef
{ service: 'cas' },
{
$set: {
baseUrl: process.env.CAS_BASE_URL,
loginUrl: process.env.CAS_LOGIN_URL,
serviceParam: 'service',
popupWidth: 810,
popupHeight: 610,
popup: true,
autoClose: true,
validateUrl: process.env.CASE_VALIDATE_URL,
casVersion: 3.0,
attributes: {
debug: process.env.DEBUG === 'true',
},
},
},
);
} else if (
process.env.SAML_ENABLED === 'true' ||
process.env.SAML_ENABLED === true
) {
ServiceConfiguration.configurations.upsert(
// eslint-disable-line no-undef
{ service: 'saml' },
{
$set: {
provider: process.env.SAML_PROVIDER,
entryPoint: process.env.SAML_ENTRYPOINT,
issuer: process.env.SAML_ISSUER,
cert: process.env.SAML_CERT,
idpSLORedirectURL: process.env.SAML_IDPSLO_REDIRECTURL,
privateKeyFile: process.env.SAML_PRIVATE_KEYFILE,
publicCertFile: process.env.SAML_PUBLIC_CERTFILE,
identifierFormat: process.env.SAML_IDENTIFIER_FORMAT,
localProfileMatchAttribute:
process.env.SAML_LOCAL_PROFILE_MATCH_ATTRIBUTE,
attributesSAML: process.env.SAML_ATTRIBUTES || [
'sn',
'givenName',
'mail',
],
/*
settings = {"saml":[{
"provider":"openam",
"entryPoint":"https://openam.idp.io/openam/SSORedirect/metaAlias/zimt/idp",
"issuer": "https://sp.zimt.io/", //replace with url of your app
"cert":"MIICizCCAfQCCQCY8tKaMc0 LOTS OF FUNNY CHARS ==",
"idpSLORedirectURL": "http://openam.idp.io/openam/IDPSloRedirect/metaAlias/zimt/idp",
"privateKeyFile": "certs/mykey.pem", // path is relative to $METEOR-PROJECT/private
"publicCertFile": "certs/mycert.pem", // eg $METEOR-PROJECT/private/certs/mycert.pem
"dynamicProfile": true // set to true if we want to create a user in Meteor.users dynamically if SAML assertion is valid
"identifierFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified", // Defaults to urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress
"localProfileMatchAttribute": "telephoneNumber" // CAUTION: this will be mapped to profile.<localProfileMatchAttribute> attribute in Mongo if identifierFormat (see above) differs from urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress,
"attributesSAML": [telephoneNumber, sn, givenName, mail], // attrs from SAML attr statement, which will be used for local Meteor profile creation. Currently no real attribute mapping. If required use mapping on IdP side.
}]}
*/
},
},
);
}
}
});