Debian Codegraph @

README

raw
1 NAME
2 RDF::ACL - access control lists for the semantic web
3
4 SYNOPSIS
5 use RDF::ACL;
6
7 my $acl = RDF::ACL->new('access.ttl');
8 my $auth = $acl->allow(
9 webid => 'http://example.com/joe#me',
10 item => 'http://example.com/private/document',
11 level => ['Read', 'Write'],
12 );
13 $acl->save('turtle', 'access.ttl');
14
15 # later...
16
17 if ($acl->check('http://example.com/joe#me',
18 'http://example.com/private/document',
19 'Read'))
20 {
21 print slurp("private/document");
22 }
23 else
24 {
25 print "Denied";
26 }
27
28 # later...
29
30 foreach my $reason ($acl->why('http://example.com/joe#me',
31 'http://example.com/private/document',
32 'Read'))
33 {
34 $acl->deny($reason) if defined $reason;
35 }
36 $acl->save('turtle', 'access.ttl');
37
38 DESCRIPTION
39 Note that this module provides access control and does not perform
40 authentication!
41
42 Constructors
43 `$acl->new($input, %args)`
44 Creates a new access control list based on RDF data defined in $input.
45 $input can be a serialised string of RDF, a file name, a URI or any
46 other input accepted by the `parse` function of
47 RDF::TrineX::Functions.
48
49 `new()` can be called with no arguments to create a fresh, clean ACL
50 containing no authorisations.
51
52 `$acl->new_remote($endpoint)`
53 Creates a new access control list based on RDF data accessed via a
54 remote SPARQL Protocol 1.0 endpoint.
55
56 Public Methods
57 `$acl->check($webid, $item, $level, @data)`
58 Checks an agent's authorisation to access an item.
59
60 $webid is the WebID (URI) of the agent requesting access to the item.
61
62 $item is the URL (URI) of the item being accessed.
63
64 $level is a URI identifying the type of access required. As special
65 cases, the case-insensitive string 'read' is expanded to the URI
66 <http://www.w3.org/ns/auth/acl#Read>, 'write' to
67 <http://www.w3.org/ns/auth/acl#Write>, 'append' to
68 <http://www.w3.org/ns/auth/acl#Append> and 'control' to
69 <http://www.w3.org/ns/auth/acl#Control>.
70
71 If the access control list is local (not remote), zero or more
72 additional RDF graphs can be passed (i.e. @data) containing data to
73 take into consideration when checking the agent's authorisation. This
74 data is trusted blindly, so should not include data that the user has
75 themselves supplied. If the access control list is remote, then this
76 method throws an error if any additional data is provided. (A remote
77 ACL cannot take into account local data.)
78
79 If $level is provided, this method returns a boolean.
80
81 If $level is undefined or omitted, this method returns a list of URIs
82 which each represent a type of access that the user is authorised.
83
84 `$acl->why($webid, $item, $level, @data)`
85 Investigates an agent's authorisation to access an item.
86
87 Arguments as per `check`, however $level is required.
88
89 Returns a list of authorisations that justify a user's access to the
90 item with the given access level. These authorisations are equivalent
91 to $authid values provided by `allow()`.
92
93 In some cases (especially if the authorisation was created by hand,
94 and not via `allow()`) an authorisation may not have an identifier. In
95 these cases, the list will contain undef.
96
97 `$acl->allow(%args)`
98 Adds an authorisation to the ACL. The ACL must be mutable.
99
100 The method takes a hash of named arguments:
101
102 my $authid = $acl->allow(
103 webid => 'http://example.com/joe#me',
104 item => 'http://example.com/private/document',
105 level => ['Read', 'Write'],
106 );
107
108 'item' is the URI of the item to authorise access to. As an
109 alternative, 'item_class' may be used to authorise access to an entire
110 class of items (using classes in the RDFS/OWL sense of the word). If
111 neither of these arguments is provided, then the method will throw an
112 error. Both may be provided. Either or both may be an arrayref,
113 because an authorisation may authorise access to more than one thing.
114
115 'container' is an alternative to using 'item' or 'item_class'. It
116 specifies the URI for a resource which in some way is a container for
117 other resources. Setting authorisations for a container allows you to
118 set a default authorisation for new items created within that
119 container. (You must use the `created()` method to notify the ACL
120 about newly created items.)
121
122 'webid' is the WebID (URI) of the person or agent being granted
123 access. As an alternative, 'agent_class' may be used to authorise
124 access to an entire class of agents. If neither is provided, an
125 agent_class of <http://xmlns.com/foaf/0.1/Agent> is assumed. Both may
126 be provided. Either or both may be an arrayref, because an
127 authorisation may authorise access by more than one agent. (For
128 consistency with 'item', 'agent' is supported as a synonym for
129 'webid'.)
130
131 'level' is the access level being granted. As with the `check` method,
132 the shortcuts 'read', 'write', 'append' and 'control' may be used. An
133 arrayref may be used. If no level is specified, 'read' is assumed.
134
135 This authorisation is not automatically saved, so it is probably
136 useful to call `save()` after adding authorisations.
137
138 The method returns an identifier for the authorisation. This
139 identifier may be needed again if you ever need to `deny()` the
140 authorisation.
141
142 This method is aware of `i_am()`/`who_am_i()`.
143
144 `$acl->deny($authid)`
145 Completely removes all traces of an authorisation from the ACL.
146
147 The authorisation identifier can be found using `why()` or you may
148 have remembered it when you first allowed the access. In some cases
149 (especially if the authorisation was created by hand, and not via
150 `allow()`) an authorisation may not have an identifier. In these
151 cases, you will have to be creative in figuring out how to deny
152 access.
153
154 Returns the number of statements removed from the ACL's internal model
155 as a result of the removal. (This will normally be at least 3.)
156
157 This authorisation is not automatically saved, so it is probably
158 useful to call `save()` after removing authorisations.
159
160 This method is aware of `i_am()`/`who_am_i()`.
161
162 `$acl->created($item, $container)`
163 Finds all authorisations which are the default for new items within
164 $container and clones each of them for newly created $item.
165
166 Returns a list of authorisation identifiers.
167
168 `$acl->i_am($webid)`
169 Tells the ACL object to "act like" the agent with the given WebID.
170
171 If the ACL object is acting like you, then methods that make changes
172 to the ACL (e.g. `allow()` and `deny()`) will only work if you have
173 'Control' permission over the resources specified.
174
175 $webid can be null to restore the usual behaviour.
176
177 Returns the previous WebID the ACL was acting like as a URI object.
178
179 `$acl->who_am_i`
180 Returns the WebID of the agent that ACL is acting like (if any).
181
182 `$acl->save($format, $filename)`
183 Serialises a local (not remote) ACL.
184
185 $format can be any format supported by the `serialize` function from
186 RDF::TrineX::Functions.
187
188 If $filename is provided, this method writes to the file and returns
189 the new file size in bytes.
190
191 If $filename is omitted, this method does not attempt to write to a
192 file, and simply returns the string it would have written.
193
194 `$acl->is_remote`
195 Returns true if the ACL is remote; false if local.
196
197 `$acl->is_mutable`
198 Can this ACL be modified?
199
200 `$acl->model`
201 The graph model against which authorisation checks are made.
202
203 Returned as an RDF::Trine::Model object.
204
205 `$acl->endpoint`
206 The endpoint URI for remote (non-local) ACL queries.
207
208 Returned as a URI object.
209
210 BUGS
211 Please report any bugs to <http://rt.cpan.org/>.
212
213 SEE ALSO
214 Web::ID.
215
216 <http://www.w3.org/ns/auth/acl.n3>.
217
218 <http://www.perlrdf.org/>,
219 <http://lists.foaf-project.org/mailman/listinfo/foaf-protocols>.
220
221 AUTHOR
222 Toby Inkster <[email protected]>.
223
224 COPYRIGHT AND LICENCE
225 This software is copyright (c) 2010-2013 by Toby Inkster.
226
227 This is free software; you can redistribute it and/or modify it under the
228 same terms as the Perl 5 programming language system itself.
229
230 DISCLAIMER OF WARRANTIES
231 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
232 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
233 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
234