Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs @ 1799

Last change on this file since 1799 was 1799, checked in by msteinbi, 15 years ago

corrected signature of getalljobresults (#466)

File size: 6.2 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      sessionID = secMan.Login(username, password);
47      if (sessionID == Guid.Empty)
48        resp.Success = false;
49      else {
50        resp.Success = true;
51        resp.StatusMessage =
52          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
53      }
54      return resp;
55    }
56
57
58    public ResponseList<ClientInfo> GetAllClients() {
59      if (HasPermission(PermissiveSecurityAction.List_AllClients))
60        return clientManager.GetAllClients();
61      else
62        throw new PermissionException();
63    }
64
65    public ResponseList<ClientGroup> GetAllClientGroups() {
66      if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
67        return clientManager.GetAllClientGroups();
68      else
69        throw new PermissionException();
70    }
71
72    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
73      if (HasPermission(PermissiveSecurityAction.Show_Statistics))
74        return clientManager.GetAllUpTimeStatistics();
75      else
76        throw new PermissionException();
77    }
78
79    public Response AddClientGroup(ClientGroup clientGroup) {
80      if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
81        return clientManager.AddClientGroup(clientGroup);
82      else
83        throw new PermissionException();
84    }
85
86    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
87      if (HasPermission(PermissiveSecurityAction.Add_Resource))
88        return clientManager.AddResourceToGroup(clientGroupId, resource);
89      else
90        throw new PermissionException();
91    }
92
93    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
94      if (HasPermission(PermissiveSecurityAction.Delete_Resource))
95        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
96      else
97        throw new PermissionException();
98    }
99
100
101    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
102      if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
103        return jobManager.GetAllJobs();
104      else
105        throw new PermissionException();
106    }
107
108    public ResponseObject<Job> AddNewJob(Job job) {
109      if (hasPermission(PermissiveSecurityAction.Add_Job, job.Client.Id))
110        return jobManager.AddNewJob(job);
111      else
112        throw new PermissionException();
113    }
114
115    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
116      if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
117        return jobManager.GetLastJobResultOf(jobId, requested);
118      else
119        throw new PermissionException();
120    }
121
122    public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
123      if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
124        return jobManager.GetAllJobResults(jobId);
125      else
126        throw new PermissionException();
127    }
128
129    public Response RemoveJob(Guid jobId) {
130      if (HasPermission(PermissiveSecurityAction.Remove_Job))
131        return jobManager.RemoveJob(jobId);
132      else
133        throw new PermissionException();
134    }
135
136    public Response RequestSnapshot(Guid jobId) {
137      if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
138        return jobManager.RequestSnapshot(jobId);
139      else
140        throw new PermissionException();
141    }
142
143    public Response AbortJob(Guid jobId) {
144      if (HasPermission(PermissiveSecurityAction.Abort_Job))
145        return jobManager.AbortJob(jobId);
146      else
147        throw new PermissionException();
148    }
149
150    public ResponseObject<List<ClientGroup>> GetAllGroupsOfResource(Guid resourceId) {
151      if (HasPermission(PermissiveSecurityAction.Get_AllGroupsOfResource))
152        return clientManager.GetAllGroupsOfResource(resourceId);
153      else
154        throw new PermissionException();     
155    }
156
157  /*
158    private bool HasPermission(Guid action) {
159      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, Guid.Empty);
160    }
161
162    private bool HasPermission(Guid action, Guid entityId) {
163      return (sessionID == Guid.Empty) ? false : secMan.CheckPermission(sessionID, action, entityId);
164    }
165   */
166
167    [Obsolete("Only for testing!")]
168    private bool HasPermission(Guid g) { return true; }
169    [Obsolete("Only for testing!")]
170    private bool hasPermission(Guid g, Guid f) { return true; }
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
185  }
186}
Note: See TracBrowser for help on using the repository browser.