23
23
import com .atomgraph .linkeddatahub .model .auth .Agent ;
24
24
import com .atomgraph .linkeddatahub .model .Service ;
25
25
import com .atomgraph .linkeddatahub .server .security .AuthorizationContext ;
26
+ import com .atomgraph .linkeddatahub .server .util .AuthorizationParams ;
27
+ import com .atomgraph .linkeddatahub .server .util .SetResultSetValues ;
26
28
import com .atomgraph .linkeddatahub .vocabulary .ACL ;
27
29
import com .atomgraph .linkeddatahub .vocabulary .DH ;
28
30
import com .atomgraph .linkeddatahub .vocabulary .Default ;
29
- import com .atomgraph .server .vocabulary .LDT ;
31
+ import com .atomgraph .linkeddatahub .vocabulary .LACL ;
30
32
import com .atomgraph .spinrdf .vocabulary .SPIN ;
31
33
import java .io .IOException ;
32
34
import java .util .Collections ;
43
45
import jakarta .ws .rs .container .PreMatching ;
44
46
import jakarta .ws .rs .core .Response ;
45
47
import java .net .URI ;
46
- import java .util .ArrayList ;
47
48
import java .util .HashSet ;
48
- import java .util .List ;
49
49
import java .util .Set ;
50
50
import org .apache .jena .query .ParameterizedSparqlString ;
51
51
import org .apache .jena .query .Query ;
58
58
import org .apache .jena .rdf .model .ResIterator ;
59
59
import org .apache .jena .rdf .model .Resource ;
60
60
import org .apache .jena .rdf .model .ResourceFactory ;
61
- import org .apache .jena .sparql .core .Var ;
62
- import org .apache .jena .sparql .engine .binding .Binding ;
63
61
import org .apache .jena .vocabulary .RDF ;
64
- import org .apache .jena .vocabulary .RDFS ;
65
62
import org .slf4j .Logger ;
66
63
import org .slf4j .LoggerFactory ;
67
64
@@ -156,33 +153,6 @@ public void filter(ContainerRequestContext request) throws IOException
156
153
request .setProperty (AuthorizationContext .class .getCanonicalName (), new AuthorizationContext (authorization .getModel ()));
157
154
}
158
155
159
- /**
160
- * Builds solution map for the authorization query.
161
- *
162
- * @param absolutePath request URL without query string
163
- * @param agent agent resource or null
164
- * @return solution map
165
- */
166
- public QuerySolutionMap getAuthorizationParams (Resource absolutePath , Resource agent )
167
- {
168
- QuerySolutionMap qsm = new QuerySolutionMap ();
169
- qsm .add (SPIN .THIS_VAR_NAME , absolutePath );
170
- qsm .add (LDT .base .getLocalName (), getApplication ().getBase ());
171
-
172
- if (agent != null )
173
- {
174
- qsm .add ("AuthenticatedAgentClass" , ACL .AuthenticatedAgent ); // enable AuthenticatedAgent UNION branch
175
- qsm .add ("agent" , agent );
176
- }
177
- else
178
- {
179
- qsm .add ("AuthenticatedAgentClass" , RDFS .Resource ); // disable AuthenticatedAgent UNION branch
180
- qsm .add ("agent" , RDFS .Resource ); // disables UNION branch with $agent
181
- }
182
-
183
- return qsm ;
184
- }
185
-
186
156
/**
187
157
* Returns authorization for the current request.
188
158
*
@@ -241,11 +211,11 @@ public Resource authorize(ContainerRequestContext request, Resource agent, Resou
241
211
}
242
212
243
213
ParameterizedSparqlString pss = getApplication ().canAs (EndUserApplication .class ) ? getACLQuery () : getOwnerACLQuery ();
244
- Query query = setResultSetValues (pss .asQuery (), docTypes );
214
+ Query query = new SetResultSetValues (). apply (pss .asQuery (), docTypes );
245
215
pss = new ParameterizedSparqlString (query .toString ()); // make sure VALUES are now part of the query string
246
216
assert pss .toString ().contains ("VALUES" );
247
217
248
- Model authModel = loadModel (getAdminService (), pss , getAuthorizationParams ( accessTo , agent ));
218
+ Model authModel = loadModel (getAdminService (), pss , new AuthorizationParams ( getApplication (). getBase (), accessTo , agent ). get ( ));
249
219
return authorize (authModel , accessMode );
250
220
}
251
221
finally
@@ -360,27 +330,6 @@ protected ResultSetRewindable loadResultSet(com.atomgraph.linkeddatahub.model.Se
360
330
}
361
331
}
362
332
363
- /**
364
- * Converts a SPARQL result set into a <code>VALUES</code> block.
365
- *
366
- * @param query SPARQL query
367
- * @param resultSet result set
368
- * @return query with appended values
369
- */
370
- public Query setResultSetValues (Query query , ResultSet resultSet )
371
- {
372
- if (query == null ) throw new IllegalArgumentException ("Query cannot be null" );
373
- if (resultSet == null ) throw new IllegalArgumentException ("ResultSet cannot be null" );
374
-
375
- List <Var > vars = resultSet .getResultVars ().stream ().map (Var ::alloc ).toList ();
376
- List <Binding > values = new ArrayList <>();
377
- while (resultSet .hasNext ())
378
- values .add (resultSet .nextBinding ());
379
-
380
- query .setValuesDataBlock (vars , values );
381
- return query ;
382
- }
383
-
384
333
/**
385
334
* Creates a special <code>acl:Authorization</code> resource for an owner.
386
335
* @param accessTo requested URI
@@ -395,6 +344,7 @@ public Resource createOwnerAuthorization(Resource accessTo, Resource agent)
395
344
return ModelFactory .createDefaultModel ().
396
345
createResource ().
397
346
addProperty (RDF .type , ACL .Authorization ).
347
+ addProperty (RDF .type , LACL .CreatorAuthorization ).
398
348
addProperty (ACL .accessTo , accessTo ).
399
349
addProperty (ACL .agent , agent ).
400
350
addProperty (ACL .mode , ACL .Read ).
0 commit comments