1- import { KeyValueStorage , PodStore , ResourceIdentifier , StorageLocationStrategy , WrappedSetMultiMap ,
2- getLoggerFor } from '@solid/community-server' ;
1+ import { PodStore , ResourceIdentifier , StorageLocationStrategy , getLoggerFor } from '@solid/community-server' ;
32import { ACCOUNT_SETTINGS_AUTHZ_SERVER , type AccountStore } from '../identity/interaction/account/util/AccountStore' ;
43
54/**
@@ -15,10 +14,9 @@ export class OwnerUtil {
1514 * @param storageStrategy
1615 */
1716 public constructor (
18- protected podStore : PodStore ,
19- protected accountStore : AccountStore ,
20- protected storageStrategy : StorageLocationStrategy ,
21- protected umaPatStore : KeyValueStorage < string , { issuer : string , pat : string } > ,
17+ private podStore : PodStore ,
18+ private accountStore : AccountStore ,
19+ private storageStrategy : StorageLocationStrategy ,
2220 ) { }
2321
2422 /**
@@ -33,55 +31,32 @@ export class OwnerUtil {
3331 throw new Error ( `Unable to find root storage for ${ resource } ` ) ;
3432 }
3533 }
36-
34+
3735 /**
38- * Finds the owners of the given resource.
36+ * Finds the pod of the given resource.
3937 */
40- public async findOwners ( resource : ResourceIdentifier ) : Promise < string [ ] > {
41- const storage = await this . storageStrategy . getStorageIdentifier ( resource ) ;
38+ public async findPod ( resource : ResourceIdentifier ) : Promise < { id : string , accountId : string } > {
39+ this . logger . debug ( `Looking up pod containing ${ resource . path } ` ) ;
40+
41+ const storage = await this . findStorage ( resource ) ;
4242
43- this . logger . debug ( `Looking up pod corresponding to storage ${ storage . path } ` ) ;
4443 const pod = await this . podStore . findByBaseUrl ( storage . path ) ;
4544 if ( ! pod ) throw new Error ( `Unable to find pod ${ storage . path } ` ) ;
4645
47- this . logger . debug ( `Looking up owners of pod ${ pod . id } ` ) ;
48-
49- const as = await this . accountStore . getSetting ( pod . accountId , ACCOUNT_SETTINGS_AUTHZ_SERVER ) ;
50- this . logger . warn ( `REAL AS is ${ JSON . stringify ( as ) } ` ) ;
51-
52- const owners = await this . podStore . getOwners ( pod . id ) ;
53- if ( ! owners ) throw new Error ( `Unable to find owners for pod ${ storage . path } ` ) ;
54-
55- return owners . map ( ( owner ) => owner . webId ) ;
46+ return pod ;
5647 }
5748
58- public async findCommonOwner ( resources : Iterable < ResourceIdentifier > ) : Promise < string > {
59- const resourceSet = new Set ( resources ) ;
60- const ownerMap = new WrappedSetMultiMap < string , string > ( ) ;
61-
62- for ( const target of resourceSet ) {
63- const storage = await this . findStorage ( target ) ;
64- const owners = await this . findOwners ( storage ) ;
65-
66- for ( const owner of owners ) ownerMap . add ( owner , target . path ) ;
67- }
68-
69- for ( const [ owner , targets ] of ownerMap . entrySets ( ) ) {
70- if ( targets . size === resourceSet . size ) return owner ;
71- }
72-
73- throw new Error ( `No common owner found for resources: ${ Array . from ( resources ) . map ( r => r . path ) . join ( ', ' ) } ` ) ;
74- }
75-
76- public async findIssuer ( webid : string ) : Promise < string | undefined > {
77- return 'http://localhost:4000/uma' ;
78-
79- // TODO: softcode
80-
81- // const profile = await fetchDataset(webid);
82- // const quads = await readableToQuads(profile.data);
83- // const issuers = quads.getObjects(namedNode(webid), UMA.terms.as, null);
49+ /**
50+ * Finds the authorization server of the given resource.
51+ */
52+ public async findAuthorizationServer ( resource : ResourceIdentifier ) : Promise < string > {
53+ this . logger . debug ( `Looking up authorization server of ${ resource . path } ` ) ;
8454
85- // return issuers.length > 0 ? issuers[0].value : undefined;
55+ const pod = await this . findPod ( resource ) ;
56+
57+ const as = await this . accountStore . getSetting ( pod . accountId , ACCOUNT_SETTINGS_AUTHZ_SERVER ) ;
58+ if ( ! as ) throw new Error ( `Unable to find authorization server for pod ${ pod . id } (account ${ pod . accountId } )` ) ;
59+
60+ return as ;
8661 }
8762}
0 commit comments