MirAL
application_authorizer.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2016 Canonical Ltd.
3  *
4  * This program is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  * Authored by: Alan Griffiths <alan@octopull.co.uk>
17  */
18 
19 #ifndef MIRAL_APPLICATION_AUTHORIZER_H
20 #define MIRAL_APPLICATION_AUTHORIZER_H
21 
22 #include <sys/types.h>
23 #include <memory>
24 
25 namespace mir { class Server; }
26 namespace mir { namespace frontend { class SessionCredentials; } }
27 
28 namespace miral
29 {
31 {
32 public:
33  ApplicationCredentials(mir::frontend::SessionCredentials const& creds);
34 
35  pid_t pid() const;
36  uid_t uid() const;
37  gid_t gid() const;
38 
39 private:
40  ApplicationCredentials() = delete;
41 
42  mir::frontend::SessionCredentials const& creds;
43 };
44 
46 {
47 public:
48  ApplicationAuthorizer() = default;
49  virtual ~ApplicationAuthorizer() = default;
51  ApplicationAuthorizer& operator=(ApplicationAuthorizer const&) = delete;
52 
53  virtual bool connection_is_allowed(ApplicationCredentials const& creds) = 0;
54  virtual bool configure_display_is_allowed(ApplicationCredentials const& creds) = 0;
55  virtual bool set_base_display_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
56  virtual bool screencast_is_allowed(ApplicationCredentials const& creds) = 0;
57  virtual bool prompt_session_is_allowed(ApplicationCredentials const& creds) = 0;
58 };
59 
61 {
62 public:
63  explicit BasicSetApplicationAuthorizer(std::function<std::shared_ptr<ApplicationAuthorizer>()> const& builder);
65 
66  void operator()(mir::Server& server);
67  auto the_application_authorizer() const -> std::shared_ptr<ApplicationAuthorizer>;
68 
69 private:
70  struct Self;
71  std::shared_ptr<Self> self;
72 };
73 
74 template<typename Policy>
76 {
77 public:
78  template<typename ...Args>
79  explicit SetApplicationAuthorizer(Args const& ...args) :
80  BasicSetApplicationAuthorizer{[&args...]() { return std::make_shared<Policy>(args...); }} {}
81 
82  auto the_custom_application_authorizer() const -> std::shared_ptr<Policy>
83  { return std::static_pointer_cast<Policy>(the_application_authorizer()); }
84 };
85 }
86 
87 #endif //MIRAL_APPLICATION_AUTHORIZER_H
Definition: active_outputs.h:25
Definition: application_authorizer.h:45
STL namespace.
auto the_custom_application_authorizer() const -> std::shared_ptr< Policy >
Definition: application_authorizer.h:82
SetApplicationAuthorizer(Args const &...args)
Definition: application_authorizer.h:79
Definition: application_authorizer.h:60
Definition: application_authorizer.h:75
Definition: application_authorizer.h:30
Mir Abstraction Layer.
Definition: active_outputs.h:27

Copyright © 2016 Canonical Ltd.
Generated on Tue Dec 20 16:03:55 UTC 2016