From 879f6b57148a83c264be52d0149f87c8ceba630f Mon Sep 17 00:00:00 2001 From: Jason Sherman Date: Mon, 26 Feb 2024 09:57:02 -0800 Subject: [PATCH] SSO - standard realm updates remove keycloak from API, replace with jwt verification only. token to user mapping now in configuration not in keycloak. frontend keycloak configuration changes slightly (no resource_access). no user role. Signed-off-by: Jason Sherman --- app/app.js | 22 ++- app/config/custom-environment-variables.json | 13 +- app/config/default.json | 14 +- .../src/components/base/BaseSecure.vue | 59 ++---- .../src/components/bcgov/BCGovNavBar.vue | 2 +- .../src/components/designer/FormsTable.vue | 2 +- .../designer/settings/FormAccessSettings.vue | 11 +- .../settings/FormFunctionalitySettings.vue | 2 +- .../src/components/forms/SubmissionsTable.vue | 2 +- .../components/forms/manage/AddTeamMember.vue | 4 +- .../forms/manage/TeamManagement.vue | 7 +- .../submission/ManageSubmissionUsers.vue | 6 +- app/frontend/src/main.js | 10 +- app/frontend/src/store/auth.js | 40 ++-- app/frontend/src/store/identityProviders.js | 41 +++- app/frontend/src/utils/permissionUtils.js | 6 +- app/frontend/src/views/Login.vue | 8 +- .../components/base/BaseAuthButton.spec.js | 8 +- .../unit/components/base/BaseSecure.spec.js | 53 +---- .../unit/components/bcgov/BCGovNavBar.spec.js | 12 +- .../unit/fixtures/identityProviders.json | 4 +- .../unit/store/modules/auth.actions.spec.js | 9 +- .../unit/store/modules/auth.getters.spec.js | 67 ++----- .../tests/unit/utils/permissionUtils.spec.js | 2 +- app/frontend/tests/unit/views/Login.spec.js | 4 +- app/package-lock.json | 187 ++---------------- app/package.json | 2 +- app/src/components/idpService.js | 169 ++++++++++++++++ app/src/components/jwtService.js | 100 ++++++++++ app/src/components/keycloak.js | 19 -- ...119172630_identity_provider_permissions.js | 48 +++++ app/src/forms/admin/routes.js | 5 +- app/src/forms/auth/middleware/userAccess.js | 144 ++++++++++---- app/src/forms/auth/service.js | 57 ++---- app/src/forms/common/constants.js | 11 -- .../common/models/tables/identityProvider.js | 6 + app/src/forms/common/models/tables/user.js | 5 +- app/src/forms/form/routes.js | 5 +- app/src/forms/permission/routes.js | 5 +- app/src/forms/rbac/routes.js | 9 +- app/src/forms/rbac/service.js | 16 +- app/src/forms/role/routes.js | 11 +- app/src/forms/user/routes.js | 4 +- app/src/forms/user/service.js | 28 +-- app/tests/unit/forms/auth/authService.spec.js | 15 +- .../forms/auth/middleware/userAccess.spec.js | 83 +++++--- app/tests/unit/forms/user/service.spec.js | 3 + app/tests/unit/routes/v1/admin.spec.js | 4 +- app/tests/unit/routes/v1/form.spec.js | 4 +- app/tests/unit/routes/v1/permission.spec.js | 4 +- app/tests/unit/routes/v1/rbac.spec.js | 4 +- app/tests/unit/routes/v1/role.spec.js | 4 +- app/tests/unit/routes/v1/user.spec.js | 4 +- 53 files changed, 749 insertions(+), 615 deletions(-) create mode 100644 app/src/components/idpService.js create mode 100644 app/src/components/jwtService.js delete mode 100755 app/src/components/keycloak.js diff --git a/app/app.js b/app/app.js index f960debc5..e2e202789 100644 --- a/app/app.js +++ b/app/app.js @@ -5,7 +5,6 @@ const path = require('path'); const Problem = require('api-problem'); const querystring = require('querystring'); -const keycloak = require('./src/components/keycloak'); const log = require('./src/components/log')(module.filename); const httpLogger = require('./src/components/log').httpLogger; const middleware = require('./src/forms/common/middleware'); @@ -40,9 +39,6 @@ if (process.env.NODE_ENV !== 'test') { app.use(httpLogger); } -// Use Keycloak OIDC Middleware -app.use(keycloak.middleware()); - // Block requests until service is ready app.use((_req, res, next) => { if (state.shutdown) { @@ -178,11 +174,16 @@ function initializeConnections() { .then((results) => { state.connections.data = results[0]; - if (state.connections.data) log.info('DataConnection Reachable', { function: 'initializeConnections' }); + if (state.connections.data) + log.info('DataConnection Reachable', { + function: 'initializeConnections', + }); }) .catch((error) => { log.error(`Initialization failed: Database OK = ${state.connections.data}`, { function: 'initializeConnections' }); - log.error('Connection initialization failure', error.message, { function: 'initializeConnections' }); + log.error('Connection initialization failure', error.message, { + function: 'initializeConnections', + }); if (!state.ready) { process.exitCode = 1; shutdown(); @@ -191,7 +192,9 @@ function initializeConnections() { .finally(() => { state.ready = Object.values(state.connections).every((x) => x); if (state.ready) { - log.info('Service ready to accept traffic', { function: 'initializeConnections' }); + log.info('Service ready to accept traffic', { + function: 'initializeConnections', + }); // Start periodic 10 second connection probe check probeId = setInterval(checkConnections, 10000); } @@ -211,7 +214,10 @@ function checkConnections() { Promise.all(tasks).then((results) => { state.connections.data = results[0]; state.ready = Object.values(state.connections).every((x) => x); - if (!wasReady && state.ready) log.info('Service ready to accept traffic', { function: 'checkConnections' }); + if (!wasReady && state.ready) + log.info('Service ready to accept traffic', { + function: 'checkConnections', + }); log.verbose(state); if (!state.ready) { process.exitCode = 1; diff --git a/app/config/custom-environment-variables.json b/app/config/custom-environment-variables.json index ca034709e..06d1c82b6 100755 --- a/app/config/custom-environment-variables.json +++ b/app/config/custom-environment-variables.json @@ -35,7 +35,8 @@ "keycloak": { "clientId": "FRONTEND_KC_CLIENTID", "realm": "FRONTEND_KC_REALM", - "serverUrl": "FRONTEND_KC_SERVERURL" + "serverUrl": "FRONTEND_KC_SERVERURL", + "logoutUrl": "FRONTEND_KC_LOGOUTURL" } }, "server": { @@ -43,11 +44,11 @@ "basePath": "SERVER_BASEPATH", "bodyLimit": "SERVER_BODYLIMIT", "keycloak": { - "clientId": "SERVER_KC_CLIENTID", - "clientSecret": "SERVER_KC_CLIENTSECRET", - "publicKey": "SERVER_KC_PUBLICKEY", - "realm": "SERVER_KC_REALM", - "serverUrl": "SERVER_KC_SERVERURL" + "serverUrl": "SERVER_KC_SERVERURL", + "jwksUri": "SERVER_KC_JWKSURI", + "issuer": "SERVER_KC_ISSUER", + "audience": "SERVER_KC_AUDIENCE", + "maxTokenAge": "SERVER_KC_MAXTOKENAGE" }, "logFile": "SERVER_LOGFILE", "logLevel": "SERVER_LOGLEVEL", diff --git a/app/config/default.json b/app/config/default.json index 3fadfbf56..99bb82950 100644 --- a/app/config/default.json +++ b/app/config/default.json @@ -32,8 +32,9 @@ "basePath": "/app", "keycloak": { "clientId": "chefs-frontend", - "realm": "chefs", - "serverUrl": "https://dev.loginproxy.gov.bc.ca/auth" + "realm": "standard", + "serverUrl": "https://dev.loginproxy.gov.bc.ca/auth", + "logoutUrl": "https://logon7.gov.bc.ca/clp-cgi/logoff.cgi?retnow=1&returl=https%3A%2F%2Fdev.loginproxy.gov.bc.ca%2Fauth%2Frealms%2Fstandard%2Fprotocol%2Fopenid-connect%2Flogout%3Fpost_logout_redirect_uri%3Dhttp%3A%2F%2Flocalhost%3A5173%2Fapp%26client_id%3Dchefs-frontend" } }, "server": { @@ -41,9 +42,12 @@ "basePath": "/app", "bodyLimit": "30mb", "keycloak": { - "clientId": "chefs", - "realm": "chefs", - "serverUrl": "https://dev.loginproxy.gov.bc.ca/auth" + "realm": "standard", + "serverUrl": "https://dev.loginproxy.gov.bc.ca/auth", + "jwksUri": "https://dev.loginproxy.gov.bc.ca/auth/realms/standard/protocol/openid-connect/certs", + "issuer": "https://dev.loginproxy.gov.bc.ca/auth/realms/standard", + "audience": "chefs-frontend", + "maxTokenAge": "300" }, "logLevel": "http", "port": "8080", diff --git a/app/frontend/src/components/base/BaseSecure.vue b/app/frontend/src/components/base/BaseSecure.vue index f4ee5e424..d75aa7761 100755 --- a/app/frontend/src/components/base/BaseSecure.vue +++ b/app/frontend/src/components/base/BaseSecure.vue @@ -20,7 +20,6 @@ export default { 'authenticated', 'identityProvider', 'isAdmin', - 'isUser', 'ready', ]), ...mapState(useFormStore, ['lang']), @@ -44,48 +43,32 @@ export default {