1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
27 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
28 | using HeuristicLab.Hive.Contracts;
|
---|
29 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
30 |
|
---|
31 | namespace HeuristicLab.Hive.Server.Core {
|
---|
32 | public class ServerConsoleFacade: IServerConsoleFacade {
|
---|
33 | private IClientManager clientManager =
|
---|
34 | ServiceLocator.GetClientManager();
|
---|
35 |
|
---|
36 | private IJobManager jobManager =
|
---|
37 | ServiceLocator.GetJobManager();
|
---|
38 |
|
---|
39 | //private IPermissionManager permManager = ServiceLocator.GetPermissionManager();
|
---|
40 |
|
---|
41 | #region IServerConsoleFacade Members
|
---|
42 |
|
---|
43 | public Guid sessionID = Guid.Empty;
|
---|
44 |
|
---|
45 | public Response Login(string username, string password) {
|
---|
46 | Response resp = new Response();
|
---|
47 | /*
|
---|
48 | sessionID = permManager.Authenticate(username, password);
|
---|
49 | if (sessionID == Guid.Empty)
|
---|
50 | resp.Success = false;
|
---|
51 | else {
|
---|
52 |
|
---|
53 | resp.Success = true;
|
---|
54 | resp.StatusMessage =
|
---|
55 | ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
|
---|
56 | }
|
---|
57 | */
|
---|
58 | resp.Success = true;
|
---|
59 | resp.StatusMessage =
|
---|
60 | ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
|
---|
61 | return resp;
|
---|
62 | }
|
---|
63 |
|
---|
64 | #endregion
|
---|
65 |
|
---|
66 | #region IClientManager Members
|
---|
67 |
|
---|
68 | public ResponseList<ClientInfo> GetAllClients() {
|
---|
69 | if (hasPermission(PermissiveSecurityAction.List_AllClients))
|
---|
70 | return clientManager.GetAllClients();
|
---|
71 | else
|
---|
72 | throw new PermissionException();
|
---|
73 | }
|
---|
74 |
|
---|
75 | public ResponseList<ClientGroup> GetAllClientGroups() {
|
---|
76 | if (hasPermission(PermissiveSecurityAction.List_AllClientGroups))
|
---|
77 | return clientManager.GetAllClientGroups();
|
---|
78 | else
|
---|
79 | throw new PermissionException();
|
---|
80 | }
|
---|
81 |
|
---|
82 | public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
|
---|
83 | if (hasPermission(PermissiveSecurityAction.Show_Statistics))
|
---|
84 | return clientManager.GetAllUpTimeStatistics();
|
---|
85 | else
|
---|
86 | throw new PermissionException();
|
---|
87 | }
|
---|
88 |
|
---|
89 | public Response AddClientGroup(ClientGroup clientGroup) {
|
---|
90 | if (hasPermission(PermissiveSecurityAction.Add_ClientGroup))
|
---|
91 | return clientManager.AddClientGroup(clientGroup);
|
---|
92 | else
|
---|
93 | throw new PermissionException();
|
---|
94 | }
|
---|
95 |
|
---|
96 | public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
|
---|
97 | if (hasPermission(PermissiveSecurityAction.Add_Resource))
|
---|
98 | return clientManager.AddResourceToGroup(clientGroupId, resource);
|
---|
99 | else
|
---|
100 | throw new PermissionException();
|
---|
101 | }
|
---|
102 |
|
---|
103 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
104 | if (hasPermission(PermissiveSecurityAction.Delete_Resource))
|
---|
105 | return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
|
---|
106 | else
|
---|
107 | throw new PermissionException();
|
---|
108 | }
|
---|
109 |
|
---|
110 | #endregion
|
---|
111 |
|
---|
112 | #region IJobManager Members
|
---|
113 |
|
---|
114 | public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
|
---|
115 | if (hasPermission(PermissiveSecurityAction.Get_AllJobs))
|
---|
116 | return jobManager.GetAllJobs();
|
---|
117 | else
|
---|
118 | throw new PermissionException();
|
---|
119 | }
|
---|
120 |
|
---|
121 | public ResponseObject<Job> AddNewJob(Job job) {
|
---|
122 | if (hasPermission(PermissiveSecurityAction.Add_Job))
|
---|
123 | return jobManager.AddNewJob(job);
|
---|
124 | else
|
---|
125 | throw new PermissionException();
|
---|
126 | }
|
---|
127 |
|
---|
128 | public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
|
---|
129 | if (hasPermission(PermissiveSecurityAction.Get_LastJobResult))
|
---|
130 | return jobManager.GetLastJobResultOf(jobId, requested);
|
---|
131 | else
|
---|
132 | throw new PermissionException();
|
---|
133 | }
|
---|
134 |
|
---|
135 | public ResponseObject<List<JobResult>> GetAllJobResults(Guid jobId) {
|
---|
136 | if (hasPermission(PermissiveSecurityAction.Get_AllJobResults))
|
---|
137 | return jobManager.GetAllJobResults(jobId);
|
---|
138 | else
|
---|
139 | throw new PermissionException();
|
---|
140 | }
|
---|
141 |
|
---|
142 | public Response RemoveJob(Guid jobId) {
|
---|
143 | if (hasPermission(PermissiveSecurityAction.Remove_Job))
|
---|
144 | return jobManager.RemoveJob(jobId);
|
---|
145 | else
|
---|
146 | throw new PermissionException();
|
---|
147 | }
|
---|
148 |
|
---|
149 | public Response RequestSnapshot(Guid jobId) {
|
---|
150 | if (hasPermission(PermissiveSecurityAction.Request_Snapshot))
|
---|
151 | return jobManager.RequestSnapshot(jobId);
|
---|
152 | else
|
---|
153 | throw new PermissionException();
|
---|
154 | }
|
---|
155 |
|
---|
156 | public Response AbortJob(Guid jobId) {
|
---|
157 | if (hasPermission(PermissiveSecurityAction.Abort_Job))
|
---|
158 | return jobManager.AbortJob(jobId);
|
---|
159 | else
|
---|
160 | throw new PermissionException();
|
---|
161 | }
|
---|
162 |
|
---|
163 | private bool hasPermission(Guid action) {
|
---|
164 | return true;
|
---|
165 | /*
|
---|
166 | if (sessionID == Guid.Empty)
|
---|
167 | throw new Exception("sessionID is not set! Please check if user is successfully logged on!");
|
---|
168 | return permManager.CheckPermission(sessionID, action, Guid.Empty);
|
---|
169 | */
|
---|
170 | }
|
---|
171 |
|
---|
172 | public class PermissionException : Exception {
|
---|
173 | public PermissionException()
|
---|
174 | : base("Current user has insufficent rights for this action!") {
|
---|
175 | }
|
---|
176 |
|
---|
177 | public PermissionException(string msg)
|
---|
178 | : base(msg) {
|
---|
179 | }
|
---|
180 |
|
---|
181 |
|
---|
182 | }
|
---|
183 |
|
---|
184 | #endregion
|
---|
185 |
|
---|
186 | }
|
---|
187 | }
|
---|