[907] | 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;
|
---|
[800] | 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;
|
---|
[902] | 28 | using HeuristicLab.Hive.Contracts;
|
---|
[1648] | 29 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
[1769] | 30 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
[800] | 31 |
|
---|
| 32 | namespace HeuristicLab.Hive.Server.Core {
|
---|
| 33 | public class ServerConsoleFacade: IServerConsoleFacade {
|
---|
[1099] | 34 | private IClientManager clientManager =
|
---|
| 35 | ServiceLocator.GetClientManager();
|
---|
[1084] | 36 |
|
---|
[1099] | 37 | private IJobManager jobManager =
|
---|
| 38 | ServiceLocator.GetJobManager();
|
---|
| 39 |
|
---|
[1769] | 40 | private IHivePermissionManager secMan = ServiceLocator.GetHivePermissionManager();
|
---|
[1084] | 41 |
|
---|
[1648] | 42 | public Guid sessionID = Guid.Empty;
|
---|
| 43 |
|
---|
[1086] | 44 | public Response Login(string username, string password) {
|
---|
| 45 | Response resp = new Response();
|
---|
[1769] | 46 | sessionID = secMan.Login(username, password);
|
---|
[1648] | 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 | }
|
---|
[1086] | 54 | return resp;
|
---|
[1084] | 55 | }
|
---|
| 56 |
|
---|
| 57 |
|
---|
[902] | 58 | public ResponseList<ClientInfo> GetAllClients() {
|
---|
[1769] | 59 | if (HasPermission(PermissiveSecurityAction.List_AllClients))
|
---|
[1648] | 60 | return clientManager.GetAllClients();
|
---|
| 61 | else
|
---|
| 62 | throw new PermissionException();
|
---|
[800] | 63 | }
|
---|
| 64 |
|
---|
[902] | 65 | public ResponseList<ClientGroup> GetAllClientGroups() {
|
---|
[1769] | 66 | if (HasPermission(PermissiveSecurityAction.List_AllClientGroups))
|
---|
[1648] | 67 | return clientManager.GetAllClientGroups();
|
---|
| 68 | else
|
---|
| 69 | throw new PermissionException();
|
---|
[800] | 70 | }
|
---|
| 71 |
|
---|
[902] | 72 | public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
|
---|
[1769] | 73 | if (HasPermission(PermissiveSecurityAction.Show_Statistics))
|
---|
[1648] | 74 | return clientManager.GetAllUpTimeStatistics();
|
---|
| 75 | else
|
---|
| 76 | throw new PermissionException();
|
---|
[800] | 77 | }
|
---|
| 78 |
|
---|
[934] | 79 | public Response AddClientGroup(ClientGroup clientGroup) {
|
---|
[1769] | 80 | if (HasPermission(PermissiveSecurityAction.Add_ClientGroup))
|
---|
[1648] | 81 | return clientManager.AddClientGroup(clientGroup);
|
---|
| 82 | else
|
---|
| 83 | throw new PermissionException();
|
---|
[934] | 84 | }
|
---|
| 85 |
|
---|
[1449] | 86 | public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
|
---|
[1769] | 87 | if (HasPermission(PermissiveSecurityAction.Add_Resource))
|
---|
[1648] | 88 | return clientManager.AddResourceToGroup(clientGroupId, resource);
|
---|
| 89 | else
|
---|
| 90 | throw new PermissionException();
|
---|
[934] | 91 | }
|
---|
| 92 |
|
---|
[1449] | 93 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
[1769] | 94 | if (HasPermission(PermissiveSecurityAction.Delete_Resource))
|
---|
[1648] | 95 | return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
|
---|
| 96 | else
|
---|
| 97 | throw new PermissionException();
|
---|
[934] | 98 | }
|
---|
| 99 |
|
---|
[800] | 100 |
|
---|
[902] | 101 | public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
|
---|
[1769] | 102 | if (HasPermission(PermissiveSecurityAction.Get_AllJobs))
|
---|
[1648] | 103 | return jobManager.GetAllJobs();
|
---|
| 104 | else
|
---|
| 105 | throw new PermissionException();
|
---|
[800] | 106 | }
|
---|
[1648] | 107 |
|
---|
[967] | 108 | public ResponseObject<Job> AddNewJob(Job job) {
|
---|
[1769] | 109 | if (hasPermission(PermissiveSecurityAction.Add_Job, job.Client.Id))
|
---|
[1648] | 110 | return jobManager.AddNewJob(job);
|
---|
| 111 | else
|
---|
| 112 | throw new PermissionException();
|
---|
[967] | 113 | }
|
---|
[800] | 114 |
|
---|
[1509] | 115 | public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
|
---|
[1769] | 116 | if (HasPermission(PermissiveSecurityAction.Get_LastJobResult))
|
---|
[1648] | 117 | return jobManager.GetLastJobResultOf(jobId, requested);
|
---|
| 118 | else
|
---|
| 119 | throw new PermissionException();
|
---|
[1171] | 120 | }
|
---|
| 121 |
|
---|
[1799] | 122 | public ResponseList<JobResult> GetAllJobResults(Guid jobId) {
|
---|
[1769] | 123 | if (HasPermission(PermissiveSecurityAction.Get_AllJobResults))
|
---|
[1648] | 124 | return jobManager.GetAllJobResults(jobId);
|
---|
| 125 | else
|
---|
| 126 | throw new PermissionException();
|
---|
| 127 | }
|
---|
| 128 |
|
---|
[1449] | 129 | public Response RemoveJob(Guid jobId) {
|
---|
[1769] | 130 | if (HasPermission(PermissiveSecurityAction.Remove_Job))
|
---|
[1648] | 131 | return jobManager.RemoveJob(jobId);
|
---|
| 132 | else
|
---|
| 133 | throw new PermissionException();
|
---|
[967] | 134 | }
|
---|
| 135 |
|
---|
[1509] | 136 | public Response RequestSnapshot(Guid jobId) {
|
---|
[1769] | 137 | if (HasPermission(PermissiveSecurityAction.Request_Snapshot))
|
---|
[1648] | 138 | return jobManager.RequestSnapshot(jobId);
|
---|
| 139 | else
|
---|
| 140 | throw new PermissionException();
|
---|
[1509] | 141 | }
|
---|
| 142 |
|
---|
| 143 | public Response AbortJob(Guid jobId) {
|
---|
[1769] | 144 | if (HasPermission(PermissiveSecurityAction.Abort_Job))
|
---|
[1648] | 145 | return jobManager.AbortJob(jobId);
|
---|
| 146 | else
|
---|
| 147 | throw new PermissionException();
|
---|
[1509] | 148 | }
|
---|
| 149 |
|
---|
[1769] | 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();
|
---|
[1627] | 155 | }
|
---|
| 156 |
|
---|
[1769] | 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 |
|
---|
[1648] | 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 |
|
---|
[1757] | 184 |
|
---|
[800] | 185 | }
|
---|
| 186 | }
|
---|