2
* Copyright © 2016 Canonical Ltd.
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 2 or 3 as
6
* published by the Free Software Foundation.
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.
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/>.
16
* Authored by: Alan Griffiths <alan@octopull.co.uk>
19
#ifndef MIRAL_APPLICATION_AUTHORIZER_H
20
#define MIRAL_APPLICATION_AUTHORIZER_H
22
#include <miral/version.h>
24
#include <sys/types.h>
28
namespace mir { class Server; }
29
namespace mir { namespace frontend { class SessionCredentials; } }
33
class ApplicationCredentials
36
ApplicationCredentials(mir::frontend::SessionCredentials const& creds);
43
ApplicationCredentials() = delete;
45
mir::frontend::SessionCredentials const& creds;
48
class ApplicationAuthorizer
51
ApplicationAuthorizer() = default;
52
virtual ~ApplicationAuthorizer() = default;
53
ApplicationAuthorizer(ApplicationAuthorizer const&) = delete;
54
ApplicationAuthorizer& operator=(ApplicationAuthorizer const&) = delete;
56
virtual bool connection_is_allowed(ApplicationCredentials const& creds) = 0;
57
virtual bool configure_display_is_allowed(ApplicationCredentials const& creds) = 0;
58
virtual bool set_base_display_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
59
virtual bool screencast_is_allowed(ApplicationCredentials const& creds) = 0;
60
virtual bool prompt_session_is_allowed(ApplicationCredentials const& creds) = 0;
63
// Mir has introduced new functions. We can't introduce new functions to ApplicationAuthorizer
64
// without breaking ABI, but we can offer an extension interface:
65
class ApplicationAuthorizer1 : public ApplicationAuthorizer
68
virtual bool configure_input_is_allowed(ApplicationCredentials const& creds) = 0;
69
virtual bool set_base_input_configuration_is_allowed(ApplicationCredentials const& creds) = 0;
71
#if MIRAL_VERSION >= MIR_VERSION_NUMBER(2, 0, 0)
72
#error "We've presumably broken ABI - please roll this interface into ApplicationAuthorizer"
76
class BasicSetApplicationAuthorizer
79
explicit BasicSetApplicationAuthorizer(std::function<std::shared_ptr<ApplicationAuthorizer>()> const& builder);
80
~BasicSetApplicationAuthorizer();
82
void operator()(mir::Server& server);
83
auto the_application_authorizer() const -> std::shared_ptr<ApplicationAuthorizer>;
87
std::shared_ptr<Self> self;
90
template<typename Policy>
91
class SetApplicationAuthorizer : public BasicSetApplicationAuthorizer
94
template<typename ...Args>
95
explicit SetApplicationAuthorizer(Args const& ...args) :
96
BasicSetApplicationAuthorizer{[&args...]() { return std::make_shared<Policy>(args...); }} {}
98
auto the_custom_application_authorizer() const -> std::shared_ptr<Policy>
99
{ return std::static_pointer_cast<Policy>(the_application_authorizer()); }
103
#endif //MIRAL_APPLICATION_AUTHORIZER_H