1/* Part of SWISH 2 3 Author: Jan Wielemaker 4 E-mail: J.Wielemaker@cs.vu.nl 5 WWW: http://www.swi-prolog.org 6 Copyright (C): 2017, VU University Amsterdam 7 CWI Amsterdam 8 All rights reserved. 9 10 Redistribution and use in source and binary forms, with or without 11 modification, are permitted provided that the following conditions 12 are met: 13 14 1. Redistributions of source code must retain the above copyright 15 notice, this list of conditions and the following disclaimer. 16 17 2. Redistributions in binary form must reproduce the above copyright 18 notice, this list of conditions and the following disclaimer in 19 the documentation and/or other materials provided with the 20 distribution. 21 22 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 27 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 28 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 30 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 32 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 33 POSSIBILITY OF SUCH DAMAGE. 34*/ 35 36:- module(swish_pep, 37 [ authorized/2 % +Request, +Action 38 ]). 39:- use_module(library(debug)). 40:- use_module(library(option)). 41:- use_module(library(error)). 42:- use_module(library(http/http_wrapper)). 43 44:- use_module(authenticate). 45:- use_module(storage). 46:- use_module(config).
59:- multifile
60 swish_config:approve/2,
61 swish_config:deny/2.
autenticate.pl
.Actions defined:
file(File)
or hash(Hash)
in
Format, see storage_get/4 from storage.pl
named
or random
and indicates whether the file is named
by the user or the name is generated by the system.95authorized(Action, _Options) :- 96 var(Action), 97 !, 98 instantiation_error(Action). 99authorized(Action, Options) :- 100 option(identity(Id), Options), 101 ( authorize(Action, Id) 102 -> debug(pep, 'Approved gitty action ~p to ~p', [Action, Id]) 103 ; debug(pep, 'Denied action ~p to ~p', [Action, Id]), 104 http_current_request(Request), 105 option(path(Path), Request), 106 throw(http_reply(forbidden(Path))) 107 ). 108 109:- multifile 110 approve/2, 111 deny/2. 112 Action, Id) (:- 114 approve(Action, Id), !, 115 \+ deny(Action, Id).
119approve(gitty(update(_File,PrevMeta,_Meta)), Auth) :- !, 120 storage_meta_property(PrevMeta, modify(Modify)), 121 ( memberchk(any, Modify) 122 -> true 123 ; memberchk(login, Modify) 124 -> user_property(Auth, login(_)) 125 ; storage_meta_property(PrevMeta, identity(Id)), 126 user_property(Auth, identity(Id)) 127 ). 128approve(gitty(_), _). 129approve(file(update(_File, _Meta)), Auth) :- 130 user_property(Auth, login(local)). 131approve(run(any, _), Auth) :- 132 user_property(Auth, login(local)). 133approve(chat, _).
140 /******************************* 141 * PENGINES * 142 *******************************/
149:- multifile pengines:not_sandboxed/2. 150 151penginesnot_sandboxed(User, Application) :- 152 authorized(run(any, Application), [identity(User)])
SWISH PEP (Policy Enforcement Point)
This module implements the Policy Enforcement Point. It is called by modules that perform operations that may not be publically accessible. Examples are:
*/