<commit_before>"use strict";

/**
 * @license
 * Copyright SOAJS All Rights Reserved.
 *
 * Use of this source code is governed by an Apache license that can be
 * found in the LICENSE file at the root of this repository
 */

const uracDriver = require('soajs.urac.driver');
const coreModules = require("soajs.core.modules");
let provision = coreModules.provision;

const lib = require("./lib.js");

function Urac(param) {
	let _self = this;
	
	_self.soajs = param.soajs;
	_self.userRecord = null;
	_self.user_ACL = null;
	_self.id = null;
	
	if (param.oauth && 0 === param.oauth.type) {
		_self.userRecord = param.oauth.bearerToken;
	} else {
		// if type === 2
		if (param.oauth && param.oauth.bearerToken && param.oauth.bearerToken.user) {
			
			_self.id = param.oauth.bearerToken.user.id;
			if (param.oauth.bearerToken.user.username) {
				_self.username = param.oauth.bearerToken.user.username;
			}
			if (param.oauth.bearerToken.user.loginMode === "oauth") {
				_self.userRecord = param.oauth.bearerToken.user;
			}
			else if (_self.soajs.registry.serviceConfig.oauth.getUserFromToken) {
				_self.userRecord = param.oauth.bearerToken.user;
			}
		} else if (param._id) {
			_self.id = param._id;
			_self.username = param.username;
		}
	}
}

/**
 * Initialize Driver and set userRecord if found
 * @param cb
 */
Urac.prototype.init = function (cb) {
	let _self = this;
	if (_self.userRecord) {
		if (_self.user_ACL) {
			return cb(null, _self.userRecord);
		} else {
			_self.resolveACL(() => {
				return cb(null, _self.userRecord);
			});
		}
	}<commit_msg>not adding roaming obj to req.soajs.tenant unless needed, force reload user record if roaming or in case of clientId mismatch with req.soajs.tenant.id to guarantee allowedTenant configuration<commit_after>"use strict";

/**
 * @license
 * Copyright SOAJS All Rights Reserved.
 *
 * Use of this source code is governed by an Apache license that can be
 * found in the LICENSE file at the root of this repository
 */

const uracDriver = require('soajs.urac.driver');
const coreModules = require("soajs.core.modules");
let provision = coreModules.provision;

const lib = require("./lib.js");

function Urac(param) {
	let _self = this;
	
	_self.soajs = param.soajs;
	_self.userRecord = null;
	_self.user_ACL = null;
	_self.id = null;
	if (param.oauth && 0 === param.oauth.type) {
		_self.userRecord = param.oauth.bearerToken;
	} else {
		// if type === 2
		if (param.oauth && param.oauth.bearerToken && param.oauth.bearerToken.user) {
			_self.id = param.oauth.bearerToken.user.id;
			if (param.oauth.bearerToken.user.username) {
				_self.username = param.oauth.bearerToken.user.username;
			}
			if (param.oauth.bearerToken.user.loginMode === "oauth") {
				_self.userRecord = param.oauth.bearerToken.user;
			}
			else if (_self.soajs.registry.serviceConfig.oauth.getUserFromToken) {
				// NOTE:
				// if roaming, must load again user
				// if the clientId is not the same as _self.soajs.tenant.id then we should get the record
				if (!_self.soajs.tenant.roaming && (param.oauth.bearerToken.clientId === _self.soajs.tenant.id)) {
					_self.userRecord = param.oauth.bearerToken.user;
				}
			}
		} else if (param._id) {
			_self.id = param._id;
			_self.username = param.username;
		}
	}
}

/**
 * Initialize Driver and set userRecord if found
 * @param cb
 */
Urac.prototype.init = function (cb) {
	let _self = this;
	if (_self.userRecord) {
		if (_self.user_ACL) {
			return cb(null, _self.userRecord);
		} else {
			_self.resolveACL(() => {
				return cb(null, _self.userRecord);
			});
		}
	}
{'fraction_non_alphanumeric': 0.13385606272752731, 'fraction_numerical': 0.0011201344161299357, 'mean_word_length': 3.3828220858895706, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5539128', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1272, 'n_words': 295}