|
| 1 | +/* |
| 2 | + * Copyright Inrupt Inc. |
| 3 | + * |
| 4 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 5 | + * of this software and associated documentation files (the "Software"), to deal in |
| 6 | + * the Software without restriction, including without limitation the rights to use, |
| 7 | + * copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the |
| 8 | + * Software, and to permit persons to whom the Software is furnished to do so, |
| 9 | + * subject to the following conditions: |
| 10 | + * |
| 11 | + * The above copyright notice and this permission notice shall be included in |
| 12 | + * all copies or substantial portions of the Software. |
| 13 | + * |
| 14 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, |
| 15 | + * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A |
| 16 | + * PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 17 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 18 | + * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
| 19 | + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 20 | + */ |
| 21 | +package com.inrupt.client.acp; |
| 22 | + |
| 23 | +import static com.inrupt.client.acp.AccessControlResource.asIRI; |
| 24 | + |
| 25 | +import com.inrupt.client.vocabulary.ACP; |
| 26 | +import com.inrupt.client.vocabulary.RDF; |
| 27 | +import com.inrupt.rdf.wrapping.commons.ValueMappings; |
| 28 | +import com.inrupt.rdf.wrapping.commons.WrapperIRI; |
| 29 | + |
| 30 | +import java.util.Set; |
| 31 | + |
| 32 | +import org.apache.commons.rdf.api.Graph; |
| 33 | +import org.apache.commons.rdf.api.IRI; |
| 34 | +import org.apache.commons.rdf.api.RDFTerm; |
| 35 | + |
| 36 | +/** |
| 37 | + * An AccessControl type for use with Access Control Policies. |
| 38 | + * |
| 39 | + * <p>An access control applies {@link Policy} objects directly to a resource |
| 40 | + * via {@code acp:accessControl} or to container members via {@code acp:memberAccessControl} |
| 41 | + */ |
| 42 | +public class AccessControl extends WrapperIRI { |
| 43 | + |
| 44 | + /** |
| 45 | + * Create a new AccessControl. |
| 46 | + * |
| 47 | + * @param identifier the access control identifier |
| 48 | + * @param graph the underlying graph |
| 49 | + */ |
| 50 | + public AccessControl(final RDFTerm identifier, final Graph graph) { |
| 51 | + super(identifier, graph); |
| 52 | + graph.add((IRI) identifier, asIRI(RDF.type), asIRI(ACP.AccessControl)); |
| 53 | + } |
| 54 | + |
| 55 | + public Set<Policy> apply() { |
| 56 | + return objects(asIRI(ACP.apply), Policy::asResource, ValueMappings.as(Policy.class)); |
| 57 | + } |
| 58 | + |
| 59 | + static IRI asResource(final AccessControl accessControl, final Graph graph) { |
| 60 | + graph.add(accessControl, asIRI(RDF.type), asIRI(ACP.AccessControl)); |
| 61 | + accessControl.apply().forEach(policy -> { |
| 62 | + graph.add(accessControl, asIRI(ACP.apply), policy); |
| 63 | + Policy.asResource(policy, graph); |
| 64 | + }); |
| 65 | + |
| 66 | + return accessControl; |
| 67 | + } |
| 68 | +} |
| 69 | + |
0 commit comments