@@ -47,20 +47,13 @@ class ACLChecker {
4747 // aclCheck.checkAccess(acl.graph, this.resource)
4848
4949 // Check the resource's permissions
50- < << << << 2740 f8873bfe7d7edcf0c2c31f927a106dc0abc7
51- this . acl = this . acl || await this . getNearestACL ( ) . catch ( err => {
52- throw new HTTPError ( 500 , `Found no ACL file:\n${ err } ` )
50+ const acl = await this . getNearestACL ( ) . catch ( err => {
51+ this . messagesCached [ cacheKey ] . push ( new HTTPError ( err . status || 500 , err . message || err ) )
5352 } )
54- === = ===
55- const acl = await this . getNearestACL ( )
56- . catch ( err => {
57- this . messagesCached [ cacheKey ] . push ( new HTTPError ( 500 , err ) )
58- } )
5953 if ( ! acl ) {
6054 this . aclCached [ cacheKey ] = Promise . resolve ( false )
6155 return this . aclCached [ cacheKey ]
6256 }
63- > >>> >>> Trying another approach to acl . can
6457 // console.log('TEST', this.acl)
6558 const resource = rdf . sym ( this . resource )
6659 // const directory = acl.isContainer ? this.resource : null
@@ -75,24 +68,17 @@ class ACLChecker {
7568 const agentOrigin = this . agentOrigin ? rdf . sym ( this . agentOrigin ) : null
7669 const trustedOrigins = this . trustedOrigins ? this . trustedOrigins . map ( trustedOrigin => rdf . sym ( trustedOrigin ) ) : null
7770 const accessDenied = aclCheck . accessDenied ( acl . graph , resource , directory , aclFile , agent , modes , agentOrigin , trustedOrigins )
78- console . log ( 'BAR' , accessDenied )
7971 if ( accessDenied && user ) {
80- < << << << 2740 f8873bfe7d7edcf0c2c31f927a106dc0abc7
81- throw new HTTPError ( 403 , accessDenied )
82- } else if ( accessDenied ) {
83- throw new HTTPError ( 401 , 'Unauthenticated' )
84- === = ===
85- this . messagesCached [ cacheKey ] . push ( new HTTPError ( 403 , `Access to ${ this . resource } denied for ${ user } : ${ accessDenied } ` ) )
72+ this . messagesCached [ cacheKey ] . push ( new HTTPError ( 403 , `No permission: Access to ${ this . resource } denied for ${ user } : ${ accessDenied } ` ) )
8673 } else if ( accessDenied ) {
8774 this . messagesCached [ cacheKey ] . push ( new HTTPError ( 401 , `Access to ${ this . resource } requires authorization: ${ accessDenied } ` ) )
88- >>> > >>> Trying another approach to acl . can
8975 }
9076 console . log ( 'ACCESS ALLOWED' , ! accessDenied , user , '\n\n' )
9177 this . aclCached [ cacheKey ] = Promise . resolve ( ! accessDenied )
92- return this . aclCached
78+ return this . aclCached [ cacheKey ]
9379 }
9480
95- async getError ( mode , user ) {
81+ async getError ( user , mode ) {
9682 const cacheKey = `${ mode } -${ user } `
9783 this . aclCached [ cacheKey ] = this . aclCached [ cacheKey ] || this . can ( user , mode )
9884 const isAllowed = await this . aclCached [ cacheKey ]
@@ -123,26 +109,6 @@ class ACLChecker {
123109 // let directory = null
124110 // Create a cascade of reject handlers (one for each possible ACL)
125111 const possibleACLs = this . getPossibleACLs ( )
126- << < << << 2740 f8873bfe7d7edcf0c2c31f927a106dc0abc7
127- const nearestACL = possibleACLs . reduce ( ( prevACL , acl ) => {
128- return prevACL . catch ( ( ) => new Promise ( ( resolve , reject ) => {
129- this . fetch ( acl , ( err , graph ) => {
130- if ( err && err . code !== 'ENOENT' ) {
131- isContainer = true
132- reject ( err )
133- } else {
134- if ( resource . endsWith ( '/' + this . suffix ) ) {
135- isContainer = true
136- }
137- const relative = resource . replace ( acl . replace ( / [ ^ / ] + $ / , '' ) , './' )
138- debug ( `Using ACL ${ acl } for ${ relative } ` )
139- resolve ( { acl, graph, isContainer } )
140- }
141- } )
142- } ) )
143- } , Promise . reject ( ) )
144- return nearestACL . catch ( e => { throw new Error ( `No ACL resource found, searched in \n- ${ possibleACLs . join ( '\n- ' ) } ` ) } )
145- === = ===
146112 const acls = [ ...possibleACLs ]
147113 let returnAcl = null
148114 while ( possibleACLs . length > 0 && ! returnAcl ) {
@@ -153,18 +119,18 @@ class ACLChecker {
153119 debug ( `Using ACL ${ acl } for ${ relative } ` )
154120 returnAcl = { acl, graph, isContainer }
155121 } catch ( err ) {
156- if ( err && err . code === 'ENOENT' ) {
122+ if ( err && ( err . code === 'ENOENT' || err . status === 404 ) ) {
157123 isContainer = true
158- return
124+ continue
159125 } else if ( err ) {
160- console . error ( 'ERROR IN getNearestACL' , err )
126+ console . error ( 'ERROR IN getNearestACL' , err . code , err )
161127 debug ( err )
162128 throw err
163129 }
164130 }
165131 }
166132 if ( ! returnAcl ) {
167- throw new Error ( `No ACL found for ${ resource } , searched in \n- ${ acls . join ( '\n- ' ) } ` )
133+ throw new HTTPError ( 403 , `No ACL found for ${ resource } , searched in \n- ${ acls . join ( '\n- ' ) } ` )
168134 }
169135 return returnAcl
170136 // const nearestACL = possibleACLs.reduce((prevACL, acl) => {
@@ -182,7 +148,6 @@ class ACLChecker {
182148 // }))
183149 // }, Promise.reject())
184150 // return nearestACL.catch(e => { throw new Error(`No ACL resource found, searched in \n- ${possibleACLs.join('\n- ')}`) })
185- >>> > >>> Trying another approach to acl . can
186151 }
187152
188153// Gets all possible ACL paths that apply to the resource
0 commit comments