@@ -111,30 +111,17 @@ class ACLChecker {
111111 * @param [options.host] Request's host URI (with protocol)
112112 */
113113 checkAccess ( graph , user , mode , resource , accessType , acl , options = { } ) {
114- if ( ! graph || graph . length === 0 ) {
115- debug ( 'ACL ' + acl + ' is empty' )
116- return Promise . reject ( new Error ( 'No policy found - empty ACL' ) )
117- }
118- let isContainer = accessType . startsWith ( 'default' )
119- let aclOptions = {
120- aclSuffix : this . suffix ,
121- graph : graph ,
122- host : options . host ,
123- origin : options . origin ,
124- rdf : rdf ,
125- strictOrigin : this . strictOrigin ,
126- isAcl : uri => this . isAcl ( uri ) ,
127- aclUrlFor : uri => this . aclUrlFor ( uri )
128- }
129- let acls = new PermissionSet ( resource , acl , isContainer , aclOptions )
114+ const isContainer = accessType . startsWith ( 'default' )
115+ const acls = this . getPermissionSet ( graph , resource , isContainer , acl , options )
116+
130117 return acls . checkAccess ( resource , user , mode )
131118 . then ( hasAccess => {
132119 if ( hasAccess ) {
133120 this . debug ( `${ mode } access permitted to ${ user } ` )
134121 return true
135122 } else {
136123 this . debug ( `${ mode } access NOT permitted to ${ user } ` +
137- aclOptions . strictOrigin ? ` and origin ${ options . origin } ` : '' )
124+ this . strictOrigin ? ` and origin ${ options . origin } ` : '' )
138125 throw new Error ( 'ACL file found but no matching policy found' )
139126 }
140127 } )
@@ -145,6 +132,26 @@ class ACLChecker {
145132 } )
146133 }
147134
135+ // Gets the permission set for the given resource
136+ getPermissionSet ( graph , resource , isContainer , acl , options = { } ) {
137+ const debug = this . debug
138+ if ( ! graph || graph . length === 0 ) {
139+ debug ( 'ACL ' + acl + ' is empty' )
140+ throw new Error ( 'No policy found - empty ACL' )
141+ }
142+ const aclOptions = {
143+ aclSuffix : this . suffix ,
144+ graph : graph ,
145+ host : options . host ,
146+ origin : options . origin ,
147+ rdf : rdf ,
148+ strictOrigin : this . strictOrigin ,
149+ isAcl : uri => this . isAcl ( uri ) ,
150+ aclUrlFor : uri => this . aclUrlFor ( uri )
151+ }
152+ return new PermissionSet ( resource , acl , isContainer , aclOptions )
153+ }
154+
148155 aclUrlFor ( uri ) {
149156 if ( this . isAcl ( uri ) ) {
150157 return uri
0 commit comments