Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs @ 6703

Last change on this file since 6703 was 1825, checked in by msteinbi, 16 years ago

changed signature of addClientGroup method (#599)

File size: 6.6 KB
Line 
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
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.Interfaces;
27using HeuristicLab.Hive.Contracts.BusinessObjects;
28using HeuristicLab.Hive.Contracts;
29using HeuristicLab.Security.Contracts.Interfaces;
30using HeuristicLab.Hive.Server.Core.InternalInterfaces;
31
32namespace HeuristicLab.Hive.Server.Core {
33  public class ServerConsoleFacade: IServerConsoleFacade {
34    private IClientManager clientManager =
35      ServiceLocator.GetClientManager();
36
37    private IJobManager jobManager =
38      ServiceLocator.GetJobManager();
39
40    private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
41
42    public Guid sessionID = Guid.Empty;
43
44    public Response Login(string username, string password) {
45      Response resp = new Response();
46     
47      /*
48      sessionID = secMan.Login(username, password);
49      if (sessionID == Guid.Empty) {
50        resp.Success = false;
51        resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_FAILED;
52      } else {
53        resp.Success = true;
54        resp.StatusMessage =
55          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
56      }
57      */
58      sessionID = Guid.Empty;
59      resp.Success = true;
60      resp.StatusMessage = ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
61      return resp;
62    }
63
64
65    public ResponseList<ClientInfo> GetAllClients() {
66      if (HasPermission(PermissiveSecurityAction.List_AllClients))
67        return clientManager.GetAllClients();
68      else
69        throw new PermissionException();
70    }
71
72    public ResponseList<ClientGroup> GetAllClientGroups() {
73      if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
74        return clientManager.GetAllClientGroups();
75      else
76        throw new PermissionException();
77    }
78
79    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
80      if (HasPermission(PermissiveSecurityAction.Show_Statistics))
81        return clientManager.GetAllUpTimeStatistics();
82      else
83        throw new PermissionException();
84    }
85
86    public ResponseObject<ClientGroup> AddClientGroup(ClientGroup clientGroup) {
87      if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
88        return clientManager.AddClientGroup(clientGroup);
89      else
90        throw new PermissionException();
91    }
92
93    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
94      if (HasPermission(PermissiveSecurityAction.Add_Resource))
95        return clientManager.AddResourceToGroup(clientGroupId, resource);
96      else
97        throw new PermissionException();
98    }
99
100    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
101      if (HasPermission(PermissiveSecurityAction.Delete_Resource))
102        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
103      else
104        throw new PermissionException();
105    }
106
107
108    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
109      if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
110        return jobManager.GetAllJobs();
111      else
112        throw new PermissionException();
113    }
114
115    public ResponseObject<Job> AddNewJob(Job job) {
116      if (HasPermission(PermissiveSecurityAction.Add_Job))
117        return jobManager.AddNewJob(job);
118      else
119        throw new PermissionException();
120    }
121
122    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
123      if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
124        return jobManager.GetLastJobResultOf(jobId, requested);
125      else
126        throw new PermissionException();
127    }
128
129    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
130      if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
131        return jobManager.GetAllJobResults(jobId);
132      else
133        throw new PermissionException();
134    }
135
136    public Response RemoveJob(Guid jobId) {
137      if (HasPermission(PermissiveSecurityAction.Remove_Job))
138        return jobManager.RemoveJob(jobId);
139      else
140        throw new PermissionException();
141    }
142
143    public Response RequestSnapshot(Guid jobId) {
144      if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
145        return jobManager.RequestSnapshot(jobId);
146      else
147        throw new PermissionException();
148    }
149
150    public Response AbortJob(Guid jobId) {
151      if (HasPermission(PermissiveSecurityAction.Abort_Job))
152        return jobManager.AbortJob(jobId);
153      else
154        throw new PermissionException();
155    }
156
157    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
158      if (HasPermission(PermissiveSecurityAction.Get_AllGroupsOfResource))
159        return clientManager.GetAllGroupsOfResource(resourceId);
160      else
161        throw new PermissionException();     
162    }
163
164    public Response DeleteClientGroup(Guid clientGroupId) {
165      return clientManager.DeleteClientGroup(clientGroupId);
166    }
167
168  /*
169    private bool HasPermission(Guid action) {
170      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, Guid.Empty);
171    }
172
173    private bool HasPermission(Guid action, Guid entityId) {
174      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, entityId);
175    }
176   */
177
178    [Obsolete("Only for testing!")]
179    private bool HasPermission(Guid g) { return true; }
180    [Obsolete("Only for testing!")]
181    private bool HasPermission(Guid g, Guid f) { return true; }
182
183    public class PermissionException : Exception {
184      public PermissionException()
185        : base("Current user has insufficent rights for this action!") {
186      }
187
188      public PermissionException(string msg)
189        : base(msg) {
190      }
191
192
193    }
194  }
195}
Note: See TracBrowser for help on using the repository browser.