Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
74 lines
3.3 KiB
TypeScript
74 lines
3.3 KiB
TypeScript
import { License } from '@rocket.chat/license';
|
|
import { Roles, Users } from '@rocket.chat/models';
|
|
|
|
import { ensureArray } from '../../../lib/utils/arrayUtils';
|
|
import type { ISAMLUser } from '../../../server/lib/saml/definition/ISAMLUser';
|
|
import { SAMLUtils } from '../../../server/lib/saml/lib/Utils';
|
|
import { settings } from '../../../server/settings';
|
|
import { addSettings } from '../settings/saml';
|
|
|
|
await License.onLicense('saml-enterprise', () => {
|
|
SAMLUtils.events.on('mapUser', async ({ profile, userObject }: { profile: Record<string, any>; userObject: ISAMLUser }) => {
|
|
const roleAttributeName = settings.get('SAML_Custom_Default_role_attribute_name') as string;
|
|
const roleAttributeSync = settings.get('SAML_Custom_Default_role_attribute_sync');
|
|
|
|
if (!roleAttributeSync) {
|
|
return;
|
|
}
|
|
|
|
if (roleAttributeName && profile[roleAttributeName]) {
|
|
let value = profile[roleAttributeName] || '';
|
|
if (typeof value === 'string') {
|
|
value = value.split(',');
|
|
}
|
|
|
|
const savedRoles = await Roles.findInIdsOrNames(ensureArray<string>(value)).toArray();
|
|
|
|
userObject.roles = savedRoles.map((role) => role._id);
|
|
}
|
|
});
|
|
|
|
SAMLUtils.events.on('loadConfigs', (service: string, configs: Record<string, any>): void => {
|
|
// Include ee settings on the configs object so that they can be copied to the login service too
|
|
const rawCustomAuthnContext = settings.get(`${service}_custom_authn_context`);
|
|
const customAuthnContext = typeof rawCustomAuthnContext === 'string' ? rawCustomAuthnContext.trim() : undefined;
|
|
|
|
Object.assign(configs, {
|
|
...(customAuthnContext !== undefined && { customAuthnContext }),
|
|
authnContextComparison: settings.get(`${service}_authn_context_comparison`),
|
|
identifierFormat: settings.get(`${service}_identifier_format`),
|
|
nameIDPolicyTemplate: settings.get(`${service}_NameId_template`),
|
|
authnContextTemplate: settings.get(`${service}_AuthnContext_template`),
|
|
authRequestTemplate: settings.get(`${service}_AuthRequest_template`),
|
|
logoutResponseTemplate: settings.get(`${service}_LogoutResponse_template`),
|
|
logoutRequestTemplate: settings.get(`${service}_LogoutRequest_template`),
|
|
metadataCertificateTemplate: settings.get(`${service}_MetadataCertificate_template`),
|
|
metadataTemplate: settings.get(`${service}_Metadata_template`),
|
|
});
|
|
});
|
|
|
|
SAMLUtils.events.on('updateCustomFields', async (loginResult: Record<string, any>, updatedUser: { userId: string; token: string }) => {
|
|
const userDataCustomFieldMap = settings.get('SAML_Custom_Default_user_data_custom_fieldmap') as string;
|
|
const customMap: Record<string, any> = JSON.parse(userDataCustomFieldMap);
|
|
|
|
const customFieldsList: Record<string, any> = {};
|
|
|
|
for (const spCustomFieldName in customMap) {
|
|
if (!customMap.hasOwnProperty(spCustomFieldName)) {
|
|
continue;
|
|
}
|
|
|
|
const customAttribute = customMap[spCustomFieldName];
|
|
const value = SAMLUtils.getProfileValue(loginResult.profile, {
|
|
fieldName: spCustomFieldName,
|
|
});
|
|
customFieldsList[customAttribute] = value;
|
|
}
|
|
|
|
await Users.updateCustomFieldsById(updatedUser.userId, customFieldsList);
|
|
});
|
|
});
|
|
|
|
// For setting creation we add the listener first because the event is emmited during startup
|
|
SAMLUtils.events.on('addSettings', (name: string): void | Promise<void> => License.onLicense('saml-enterprise', () => addSettings(name)));
|