2018-04-18 16:03:49 +03:00
import Fiber from 'fibers' ;
2017-05-11 12:15:02 +02:00
Meteor . startup ( ( ) => {
2018-04-16 21:18:09 +03:00
// 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 ;
2019-06-28 12:52:09 -05:00
Accounts . validateLoginAttempt ( function ( options ) {
2017-11-19 17:51:26 +02:00
const user = options . user || { } ;
return ! user . loginDisabled ;
2017-10-13 08:15:19 +02:00
} ) ;
2017-05-11 12:15:02 +02:00
Authentication = { } ;
2019-06-28 12:52:09 -05:00
Authentication . checkUserId = function ( userId ) {
2017-05-11 12:15:02 +02:00
if ( userId === undefined ) {
const error = new Meteor . Error ( 'Unauthorized' , 'Unauthorized' ) ;
error . statusCode = 401 ;
throw error ;
}
const admin = Users . findOne ( { _id : userId , isAdmin : true } ) ;
if ( admin === undefined ) {
const error = new Meteor . Error ( 'Forbidden' , 'Forbidden' ) ;
error . statusCode = 403 ;
throw error ;
}
} ;
2017-05-15 18:40:45 +02:00
// 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 ) {
2019-06-28 12:52:09 -05:00
if ( userId === undefined ) {
2017-05-15 18:40:45 +02:00
const error = new Meteor . Error ( 'Unauthorized' , 'Unauthorized' ) ;
error . statusCode = 401 ;
throw error ;
}
} ;
2017-05-15 19:43:15 +02:00
// 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 ) {
2019-06-28 12:52:09 -05:00
if ( otherReq ) return ;
2017-05-15 19:43:15 +02:00
const admin = Users . findOne ( { _id : userId , isAdmin : true } ) ;
if ( admin === undefined ) {
const error = new Meteor . Error ( 'Forbidden' , 'Forbidden' ) ;
error . statusCode = 403 ;
throw error ;
}
2017-05-15 22:10:46 +02:00
} ;
2017-05-15 19:43:15 +02:00
2017-05-15 21:02:31 +02:00
// 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 = Boards . findOne ( { _id : boardId } ) ;
2019-06-28 12:52:09 -05:00
const normalAccess =
board . permission === 'public' ||
2019-12-16 18:10:48 +01:00
board . members . some ( e => e . userId === userId && e . isActive ) ;
2017-05-15 21:02:31 +02:00
Authentication . checkAdminOrCondition ( userId , normalAccess ) ;
2017-05-15 22:10:46 +02:00
} ;
2017-05-15 21:02:31 +02:00
2018-04-09 16:49:07 +02:00
if ( Meteor . isServer ) {
2020-09-14 19:57:50 +03:00
if (
2020-10-02 23:15:39 +03:00
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 || [ ] ,
2020-10-21 19:20:48 +03:00
requestPermissions : process . env . OAUTH2 _REQUEST _PERMISSIONS ,
2020-10-02 23:15:39 +03:00
} ,
} ,
) ;
} else if (
2020-09-14 19:57:50 +03:00
process . env . OAUTH2 _ENABLED === 'true' ||
process . env . OAUTH2 _ENABLED === true
) {
2019-06-28 12:52:09 -05:00
ServiceConfiguration . configurations . upsert (
// eslint-disable-line no-undef
2018-08-25 00:49:02 +03:00
{ service : 'oidc' } ,
{
$set : {
2019-03-21 21:37:38 +02:00
loginStyle : process . env . OAUTH2 _LOGIN _STYLE ,
2018-08-25 00:49:02 +03:00
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 ,
2019-06-28 12:52:09 -05:00
idTokenWhitelistFields :
process . env . OAUTH2 _ID _TOKEN _WHITELIST _FIELDS || [ ] ,
2019-06-12 06:29:57 +03:00
requestPermissions : process . env . OAUTH2 _REQUEST _PERMISSIONS ,
2018-08-25 00:49:02 +03:00
} ,
2019-06-12 06:29:57 +03:00
// OAUTH2_ID_TOKEN_WHITELIST_FIELDS || [],
// OAUTH2_REQUEST_PERMISSIONS || 'openid profile email',
2019-06-28 12:52:09 -05:00
} ,
2022-08-30 23:12:23 +03:00
) ;
2020-10-02 23:15:39 +03:00
} 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 ,
} ,
2020-09-14 19:57:50 +03:00
} ,
} ,
2020-10-02 23:15:39 +03:00
) ;
} 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' ,
] ,
2020-09-14 19:57:50 +03:00
2020-10-02 23:15:39 +03:00
/ *
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.
} ] }
* /
} ,
2020-09-14 19:57:50 +03:00
} ,
2020-10-02 23:15:39 +03:00
) ;
}
2018-08-25 00:49:02 +03:00
}
2017-05-11 12:15:02 +02:00
} ) ;