1 /*
2  * Copyright (C) 2019 Emeric Poupon
3  *
4  * This file is part of LMS.
5  *
6  * LMS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * LMS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with LMS.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #pragma once
21 
22 #include <optional>
23 #include <string>
24 
25 #include "database/Types.hpp"
26 
27 namespace Database
28 {
29 	class Session;
30 }
31 
32 namespace Wt
33 {
34 	class WEnvironment;
35 }
36 
37 namespace Wt::Http
38 {
39 	class Request;
40 }
41 
42 namespace Auth
43 {
44 	class IEnvService
45 	{
46 		public:
47 			virtual ~IEnvService() = default;
48 
49 			// Auth Token services
50 			struct CheckResult
51 			{
52 				enum class State
53 				{
54 					Granted,
55 					Denied,
56 					Throttled,
57 				};
58 
59 				State state {State::Denied};
60 				std::optional<Database::IdType>	userId {};
61 			};
62 
63 			virtual CheckResult			processEnv(Database::Session& session, const Wt::WEnvironment& env) = 0;
64 			virtual CheckResult			processRequest(Database::Session& session, const Wt::Http::Request& request) = 0;
65 	};
66 
67 	std::unique_ptr<IEnvService> createEnvService(std::string_view backendName);
68 } // namespace Auth
69