@@ -16,15 +16,16 @@ export class ProtocolAuthorization {
1616 * @throws {Error } if authorization fails.
1717 */
1818 public static async authorize (
19+ tenant : string ,
1920 recordsWrite : RecordsWrite ,
2021 requesterDid : string ,
2122 messageStore : MessageStore
2223 ) : Promise < void > {
2324 // fetch the protocol definition
24- const protocolDefinition = await ProtocolAuthorization . fetchProtocolDefinition ( recordsWrite , messageStore ) ;
25+ const protocolDefinition = await ProtocolAuthorization . fetchProtocolDefinition ( tenant , recordsWrite , messageStore ) ;
2526
2627 // fetch ancestor message chain
27- const ancestorMessageChain : RecordsWriteMessage [ ] = await ProtocolAuthorization . constructAncestorMessageChain ( recordsWrite , messageStore ) ;
28+ const ancestorMessageChain : RecordsWriteMessage [ ] = await ProtocolAuthorization . constructAncestorMessageChain ( tenant , recordsWrite , messageStore ) ;
2829
2930 // record schema -> schema label map
3031 const recordSchemaToLabelMap : Map < string , string > = new Map ( ) ;
@@ -41,12 +42,11 @@ export class ProtocolAuthorization {
4142 ) ;
4243
4344 // verify the requester of the inbound message against allowed requester rule
44- ProtocolAuthorization . verifyAllowedRequester (
45- requesterDid , recordsWrite . target , inboundMessageRuleSet , ancestorMessageChain , recordSchemaToLabelMap
45+ ProtocolAuthorization . verifyAllowedRequester ( tenant , requesterDid , inboundMessageRuleSet , ancestorMessageChain , recordSchemaToLabelMap
4646 ) ;
4747
4848 // verify method invoked against the allowed actions
49- ProtocolAuthorization . verifyAllowedActions ( requesterDid , recordsWrite , inboundMessageRuleSet ) ;
49+ ProtocolAuthorization . verifyAllowedActions ( tenant , requesterDid , recordsWrite , inboundMessageRuleSet ) ;
5050
5151 // verify allowed condition of the write
5252 await ProtocolAuthorization . verifyActionCondition ( recordsWrite , messageStore ) ;
@@ -55,13 +55,13 @@ export class ProtocolAuthorization {
5555 /**
5656 * Fetches the protocol definition based on the protocol specified in the given message.
5757 */
58- private static async fetchProtocolDefinition ( recordsWrite : RecordsWrite , messageStore : MessageStore ) : Promise < ProtocolDefinition > {
58+ private static async fetchProtocolDefinition ( tenant : string , recordsWrite : RecordsWrite , messageStore : MessageStore ) : Promise < ProtocolDefinition > {
5959 // get the protocol URI
6060 const protocolUri = recordsWrite . message . descriptor . protocol ;
6161
6262 // fetch the corresponding protocol definition
6363 const query = {
64- target : recordsWrite . target ,
64+ tenant ,
6565 method : DwnMethodName . ProtocolsConfigure ,
6666 protocol : protocolUri
6767 } ;
@@ -79,7 +79,7 @@ export class ProtocolAuthorization {
7979 * Constructs a chain of ancestor messages
8080 * @returns the ancestor chain of messages where the first element is the root of the chain; returns empty array if no parent is specified.
8181 */
82- private static async constructAncestorMessageChain ( recordsWrite : RecordsWrite , messageStore : MessageStore )
82+ private static async constructAncestorMessageChain ( tenant : string , recordsWrite : RecordsWrite , messageStore : MessageStore )
8383 : Promise < RecordsWriteMessage [ ] > {
8484 const ancestorMessageChain : RecordsWriteMessage [ ] = [ ] ;
8585
@@ -91,7 +91,7 @@ export class ProtocolAuthorization {
9191 while ( currentParentId !== undefined ) {
9292 // fetch parent
9393 const query = {
94- target : recordsWrite . target ,
94+ tenant ,
9595 method : DwnMethodName . RecordsWrite ,
9696 protocol,
9797 contextId,
@@ -157,16 +157,16 @@ export class ProtocolAuthorization {
157157 * @throws {Error } if requester not allowed.
158158 */
159159 private static verifyAllowedRequester (
160+ tenant : string ,
160161 requesterDid : string ,
161- targetDid : string ,
162162 inboundMessageRuleSet : ProtocolRuleSet ,
163163 ancestorMessageChain : RecordsWriteMessage [ ] ,
164164 recordSchemaToLabelMap : Map < string , string >
165165 ) : void {
166166 const allowRule = inboundMessageRuleSet . allow ;
167167 if ( allowRule === undefined ) {
168- // if no allow rule is defined, still allow if requester is the same as target, but throw otherwise
169- if ( requesterDid !== targetDid ) {
168+ // if no allow rule is defined, still allow if requester is the same as target tenant , but throw otherwise
169+ if ( requesterDid !== tenant ) {
170170 throw new Error ( `no allow rule defined for requester, ${ requesterDid } is unauthorized` ) ;
171171 }
172172 } else if ( allowRule . anyone !== undefined ) {
@@ -189,13 +189,13 @@ export class ProtocolAuthorization {
189189 * Verifies the actions specified in the given message matches the allowed actions in the rule set.
190190 * @throws {Error } if action not allowed.
191191 */
192- private static verifyAllowedActions ( requesterDid : string , incomingMessage : Message , inboundMessageRuleSet : ProtocolRuleSet ) : void {
192+ private static verifyAllowedActions ( tenant : string , requesterDid : string , incomingMessage : Message , inboundMessageRuleSet : ProtocolRuleSet ) : void {
193193 const allowRule = inboundMessageRuleSet . allow ;
194194 const incomingMessageMethod = incomingMessage . message . descriptor . method ;
195195
196196 if ( allowRule === undefined ) {
197197 // if no allow rule is defined, owner of DWN can do everything
198- if ( requesterDid === incomingMessage . target ) {
198+ if ( requesterDid === tenant ) {
199199 return ;
200200 } else {
201201 throw new Error ( `no allow rule defined for ${ incomingMessageMethod } , ${ requesterDid } is unauthorized` ) ;
0 commit comments