Skip to content

Commit

Permalink
Merge pull request #1372 from bcgov/suspended-tenants-suspend-tokens
Browse files Browse the repository at this point in the history
Added middleware to prevent suspended tenants from making use of tokens
  • Loading branch information
Gavinok authored Sep 27, 2024
2 parents ca3780b + 4659400 commit 3a54a6a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import logging

from aiohttp import web
from aiohttp.web_middlewares import middleware
from aiohttp_apispec import (
docs,
match_info_schema,
Expand All @@ -22,6 +23,7 @@
WalletRecordSchema,
WalletRecord,
)
from aries_cloudagent.admin import server
from marshmallow import fields, validate

from ..innkeeper.routes import (
Expand Down Expand Up @@ -85,6 +87,9 @@ class TenantLedgerIdConfigSchema(OpenAPISchema):
async def setup_tenant_context(request: web.Request, handler):
"""Middle ware to extract tenant_id and provide it to log formatter
In addition this will also ensure tenants are not suspended before
accessing endpoints.
This middleware is appended to the app middlewares and therefore runs
last. At this point the wallet_id has been extracted from a previous
middleware function and is used to query the tenant record.
Expand All @@ -103,6 +108,9 @@ async def setup_tenant_context(request: web.Request, handler):
rec = await TenantRecord.query_by_wallet_id(session, wallet_id)
LOGGER.debug(rec)
tenant_id = rec.tenant_id
# Ensure tokens are not associated with suspended tenants
if TenantRecord.STATE_DELETED == rec.state:
raise web.HTTPUnauthorized(reason="Tenant Is Suspended")

log_records_inject(tenant_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<div class="flex justify-content-end">
<div class="container">
<ToggleButton
v-model="showDeleted"
:on-label="$t('common.hideDeleted')"
:off-label="$t('common.showDeleted')"
v-model="showSuspended"
:on-label="$t('common.hideSuspended')"
:off-label="$t('common.showSuspended')"
class="mr-2 container-item"
style="width: 10rem"
@change="loadTable"
Expand All @@ -49,7 +49,7 @@
</div>
<div v-else class="container">
<span class="container-item deleted-btn">
{{ $t('common.deleted') }}
{{ $t('common.suspended') }}
</span>
<RestoreTenant :id="data.tenant_id" :name="data.tenant_name" />
<DeleteTenant :tenant="data" unsuspendable />
Expand Down Expand Up @@ -137,10 +137,10 @@
<Column
:sortable="true"
field="deleted"
:header="$t('common.deletedAt')"
:header="$t('common.suspendedAt')"
filter-field="deleted"
:show-filter-match-modes="false"
:hidden="!showDeleted"
:hidden="!showSuspended"
>
<template #body="{ data }">
{{ data.deleted_at }}
Expand All @@ -150,7 +150,7 @@
v-model="filterModel.value"
type="text"
class="p-column-filter"
:placeholder="$t('common.searchByDeleted')"
:placeholder="$t('common.searchBySuspended')"
@input="filterCallback()"
/>
</template>
Expand Down Expand Up @@ -186,13 +186,13 @@ import RowExpandData from '@/components/common/RowExpandData.vue';
const toast = useToast();
const innkeeperTenantsStore = useInnkeeperTenantsStore();
const showDeleted = ref(false);
const showSuspended = ref(false);
// Populating the Table
const { loading, tenants } = storeToRefs(useInnkeeperTenantsStore());
const loadTable = () => {
innkeeperTenantsStore
.listTenants(showDeleted.value ? 'all' : 'active')
.listTenants(showSuspended.value ? 'all' : 'active')
.catch((err: string) => {
console.error(err);
toast.error(`Failure: ${err}`);
Expand Down
20 changes: 10 additions & 10 deletions services/tenant-ui/frontend/src/plugins/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,13 @@
"credentialId": "Credential ID",
"credentials": "Credentials",
"decodedJwt": "Decoded JWT",
"deleted": "Deleted",
"deletedAt": "Deleted At",
"developer": "Developer",
"emailAddress": "Email Address",
"encodedJwt": "Encoded JWT",
"endorser": "Endorser",
"errorGettingUrl": "Error fetching {url}",
"genericError": "An error occurred",
"hideDeleted": "Hide Deleted",
"hideSuspended": "Hide Suspended",
"invitationUrl": "Invitation URL",
"json": "JSON",
"loading": "Loading data. Please wait...",
Expand All @@ -78,12 +76,14 @@
"refreshTable": "Refresh Table",
"request": "Request",
"searchByCreated": "Search By Created at Date",
"searchByDeleted": "Search By Deleted at Date",
"searchByName": "Search By Name",
"searchBySuspended": "Search By Suspended at Date",
"settings": "Settings",
"showDeleted": "Show Deleted",
"showSuspended": "Show Suspended",
"status": "Status",
"submit": "Submit",
"suspended": "Suspended",
"suspendedAt": "Suspended At",
"tenantId": "Tenant ID",
"tenantName": "Tenant Name",
"tenantReason": "Tenant Reason",
Expand Down Expand Up @@ -524,20 +524,20 @@
"confirmDeletion": "To confirm, type \"{tenantName}\" in the box below",
"confirmDeletionIncorrect": "Incorrect tenant name. Please confirm the correct name before deletion.",
"confirmDeletionSuccess": "Tenant {0} successfully marked as {1}",
"suspended": "suspended",
"deleted": "deleted",
"deleteTenant": "Suspend Tenant",
"permanentDelete": "Permanently Delete",
"softDelete": "Suspend Tenant",
"tenantDeletionWarning": ": This will delete all data associated with this tenant.",
"editSettings": "Edit Tenant Config",
"enableLedgerSwitch": "Tenant can switch endorser/ledger",
"endorserAlias": "Endorser Alias:",
"ledgerName": "Ledger Name:",
"permanentDelete": "Permanently Delete",
"restoreConfirm": "Restore tenant {0}",
"restoreSuccess": "Tenant {0} successfully restored",
"restoreTenant": "Restore Tenant",
"success": "Tenant Config Updated"
"softDelete": "Suspend Tenant",
"success": "Tenant Config Updated",
"suspended": "suspended",
"tenantDeletionWarning": ": This will delete all data associated with this tenant."
},
"tenants": "Tenants"
},
Expand Down
20 changes: 18 additions & 2 deletions services/tenant-ui/frontend/src/plugins/i18n/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"errorGettingUrl": "Error fetching {url} <FR>",
"genericError": "An error occurred <FR>",
"hideDeleted": "Hide Deleted <FR>",
"hideSuspended": "Hide Suspended <FR>",
"invitationUrl": "Invitation URL <FR>",
"json": "JSON <FR>",
"loading": "Loading data. Please wait... <FR>",
Expand All @@ -80,15 +81,20 @@
"searchByCreated": "Search By Created at Date <FR>",
"searchByDeleted": "Search By Deleted at Date <FR>",
"searchByName": "Search By Name <FR>",
"searchBySuspended": "Search By Suspended at Date <FR>",
"settings": "Settings <FR>",
"showDeleted": "Show Deleted <FR>",
"showSuspended": "Show Suspended <FR>",
"status": "Status <FR>",
"submit": "Submit <FR>",
"suspended": "Suspended <FR>",
"suspendedAt": "Suspended At <FR>",
"tenantId": "Tenant ID <FR>",
"tenantName": "Tenant Name <FR>",
"tenantReason": "Tenant Reason <FR>",
"toggleCardExpand": "Toggle Expanded <FR>",
"walletId": "Wallet ID <FR>"
"walletId": "Wallet ID <FR>",
"warning": "Warning <FR>"
},
"configuration": {
"configuration": "Configuration <FR>",
Expand Down Expand Up @@ -322,13 +328,17 @@
"connectToEndorserAndRegisterDID": "Connect to Endorser and Register DID corresponding to a Ledger <FR>",
"contact": "Contact Email <FR>",
"createdAt": "Created at <FR>",
"didNotActiveApproved": "DID Registration approved by Endorser, continue above. <FR>",
"didNotActiveYet": "DID Registration approval pending, refresh or come back once Endorser approves request. <FR>",
"endorserConnection": "Endorser Connection <FR>",
"endorserInfo": "Endorser Info <FR>",
"imageUrl": "Image URL <FR>",
"issuer": "Issuer <FR>",
"name": "Name <FR>",
"noEndorserInfoFound": "No Endorser info found, issuance disabled <FR>",
"pendingDidTx": "Pending Public DID Endorser Transaction <FR>",
"publicDid": "Public DID <FR>",
"publicDidPending": "Requested Public DID (Pending Endorser Approval) <FR>",
"registerPublicDid": "Register a public DID <FR>",
"registerPublicDidNotAllowed": "Innkeeper has not approved public DID registration for your tenant <FR>",
"state": "State: {0} <FR>",
Expand All @@ -348,6 +358,7 @@
"tenantNotConnectedToEndorserYet": "Tenant not connected to Endorser yet <FR>",
"token": "JWT Token <FR>",
"updatedAt": "Updated at <FR>",
"walletDids": "Wallet DIDs <FR>",
"walletLabel": "Wallet Label <FR>",
"webHookKey": "WebHook Key <FR>",
"webhooks": "Webhooks <FR>",
Expand Down Expand Up @@ -521,17 +532,22 @@
"canConnectEndorser": "Tenant allowed to connect to Endorser <FR>",
"canRegisterDid": "Tenant allowed to register public DID <FR>",
"confirmDeletion": "To confirm, type \"{tenantName}\" in the box below <FR>",
"confirmDeletionIncorrect": "Incorrect tenant name. Please confirm the correct name before deletion. <FR>",
"confirmDeletionSuccess": "Tenant {0} successfully marked as deleted <FR>",
"deleted": "deleted <FR>",
"deleteTenant": "Delete Tenant <FR>",
"editSettings": "Edit Tenant Config <FR>",
"enableLedgerSwitch": "Tenant can switch endorser/ledger <FR>",
"endorserAlias": "Endorser Alias <FR>",
"ledgerName": "Ledger Name <FR>",
"permanentDelete": "Permanently Delete <FR>",
"restoreConfirm": "Restore tenant {0} <FR>",
"restoreSuccess": "Tenant {0} successfully restored <FR>",
"restoreTenant": "Restore Tenant <FR>",
"softDelete": "Suspend Tenant <FR>",
"success": "Tenant Config Updated <FR>",
"confirmDeletionIncorrect": "Incorrect tenant name. Please confirm the correct name before deletion. <FR>"
"suspended": "suspended <FR>",
"tenantDeletionWarning": ": This will delete all data associated with this tenant. <FR>"
},
"tenants": "Tenants <FR>"
},
Expand Down
20 changes: 18 additions & 2 deletions services/tenant-ui/frontend/src/plugins/i18n/locales/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"errorGettingUrl": "Error fetching {url} <JA>",
"genericError": "An error occurred <JA>",
"hideDeleted": "Hide Deleted <JA>",
"hideSuspended": "Hide Suspended <JA>",
"invitationUrl": "Invitation URL <JA>",
"json": "JSON <JA>",
"loading": "Loading data. Please wait... <JA>",
Expand All @@ -80,15 +81,20 @@
"searchByCreated": "Search By Created at Date <JA>",
"searchByDeleted": "Search By Deleted at Date <JA>",
"searchByName": "Search By Name <JA>",
"searchBySuspended": "Search By Suspended at Date <JA>",
"settings": "Settings <JA>",
"showDeleted": "Show Deleted <JA>",
"showSuspended": "Show Suspended <JA>",
"status": "Status <JA>",
"submit": "Submit <JA>",
"suspended": "Suspended <JA>",
"suspendedAt": "Suspended At <JA>",
"tenantId": "Tenant ID <JA>",
"tenantName": "Tenant Name <JA>",
"tenantReason": "Tenant Reason <JA>",
"toggleCardExpand": "Toggle Expanded <JA>",
"walletId": "Wallet ID <JA>"
"walletId": "Wallet ID <JA>",
"warning": "Warning <JA>"
},
"configuration": {
"configuration": "Configuration <JA>",
Expand Down Expand Up @@ -322,13 +328,17 @@
"connectToEndorserAndRegisterDID": "Connect to Endorser and Register DID corresponding to a Ledger <JA>",
"contact": "Contact Email <JA>",
"createdAt": "Created at <JA>",
"didNotActiveApproved": "DID Registration approved by Endorser, continue above. <JA>",
"didNotActiveYet": "DID Registration approval pending, refresh or come back once Endorser approves request. <JA>",
"endorserConnection": "Endorser Connection <JA>",
"endorserInfo": "Endorser Info <JA>",
"imageUrl": "Image URL <JA>",
"issuer": "Issuer <JA>",
"name": "Name <JA>",
"noEndorserInfoFound": "No Endorser info found, issuance disabled <JA>",
"pendingDidTx": "Pending Public DID Endorser Transaction <JA>",
"publicDid": "Public DID <JA>",
"publicDidPending": "Requested Public DID (Pending Endorser Approval) <JA>",
"registerPublicDid": "Register a public DID <JA>",
"registerPublicDidNotAllowed": "Innkeeper has not approved public DID registration for your tenant <JA>",
"state": "State: {0} <JA>",
Expand All @@ -348,6 +358,7 @@
"tenantNotConnectedToEndorserYet": "Tenant not connected to Endorser yet <JA>",
"token": "JWT Token <JA>",
"updatedAt": "Updated at <JA>",
"walletDids": "Wallet DIDs <JA>",
"walletLabel": "Wallet Label <JA>",
"webHookKey": "WebHook Key <JA>",
"webhooks": "Webhooks <JA>",
Expand Down Expand Up @@ -521,17 +532,22 @@
"canConnectEndorser": "Tenant allowed to connect to Endorser <JA>",
"canRegisterDid": "Tenant allowed to register public DID <JA>",
"confirmDeletion": "To confirm, type \"{tenantName}\" in the box below <JA>",
"confirmDeletionIncorrect": "Incorrect tenant name. Please confirm the correct name before deletion. <JA>",
"confirmDeletionSuccess": "Tenant {0} successfully marked as deleted <JA>",
"deleted": "deleted <JA>",
"deleteTenant": "Delete Tenant <JA>",
"editSettings": "Edit Tenant Config <JA>",
"enableLedgerSwitch": "Tenant can switch endorser/ledger <JA>",
"endorserAlias": "Endorser Alias <JA>",
"ledgerName": "Ledger Name <JA>",
"permanentDelete": "Permanently Delete <JA>",
"restoreConfirm": "Restore tenant {0} <JA>",
"restoreSuccess": "Tenant {0} successfully restored <JA>",
"restoreTenant": "Restore Tenant <JA>",
"softDelete": "Suspend Tenant <JA>",
"success": "Tenant Config Updated <JA>",
"confirmDeletionIncorrect": "Incorrect tenant name. Please confirm the correct name before deletion. <JA>"
"suspended": "suspended <JA>",
"tenantDeletionWarning": ": This will delete all data associated with this tenant. <JA>"
},
"tenants": "Tenants <JA>"
},
Expand Down

0 comments on commit 3a54a6a

Please sign in to comment.