[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;
|
---|
[800] | 30 |
|
---|
| 31 | namespace HeuristicLab.Hive.Server.Core {
|
---|
| 32 | public class ServerConsoleFacade: IServerConsoleFacade {
|
---|
[1099] | 33 | private IClientManager clientManager =
|
---|
| 34 | ServiceLocator.GetClientManager();
|
---|
[1084] | 35 |
|
---|
[1099] | 36 | private IJobManager jobManager =
|
---|
| 37 | ServiceLocator.GetJobManager();
|
---|
| 38 |
|
---|
[1650] | 39 | //private IPermissionManager permManager = ServiceLocator.GetPermissionManager();
|
---|
[1084] | 40 |
|
---|
| 41 | #region IServerConsoleFacade Members
|
---|
| 42 |
|
---|
[1648] | 43 | public Guid sessionID = Guid.Empty;
|
---|
| 44 |
|
---|
[1086] | 45 | public Response Login(string username, string password) {
|
---|
| 46 | Response resp = new Response();
|
---|
[1649] | 47 | /*
|
---|
[1648] | 48 | sessionID = permManager.Authenticate(username, password);
|
---|
| 49 | if (sessionID == Guid.Empty)
|
---|
| 50 | resp.Success = false;
|
---|
| 51 | else {
|
---|
[1649] | 52 |
|
---|
[1648] | 53 | resp.Success = true;
|
---|
| 54 | resp.StatusMessage =
|
---|
| 55 | ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
|
---|
| 56 | }
|
---|
[1649] | 57 | */
|
---|
| 58 | resp.Success = true;
|
---|
| 59 | resp.StatusMessage =
|
---|
| 60 | ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
|
---|
[1086] | 61 | return resp;
|
---|
[1084] | 62 | }
|
---|
| 63 |
|
---|
| 64 | #endregion
|
---|
| 65 |
|
---|
[800] | 66 | #region IClientManager Members
|
---|
| 67 |
|
---|
[902] | 68 | public ResponseList<ClientInfo> GetAllClients() {
|
---|
[1648] | 69 | if (hasPermission(PermissiveSecurityAction.List_AllClients))
|
---|
| 70 | return clientManager.GetAllClients();
|
---|
| 71 | else
|
---|
| 72 | throw new PermissionException();
|
---|
[800] | 73 | }
|
---|
| 74 |
|
---|
[902] | 75 | public ResponseList<ClientGroup> GetAllClientGroups() {
|
---|
[1648] | 76 | if (hasPermission(PermissiveSecurityAction.List_AllClientGroups))
|
---|
| 77 | return clientManager.GetAllClientGroups();
|
---|
| 78 | else
|
---|
| 79 | throw new PermissionException();
|
---|
[800] | 80 | }
|
---|
| 81 |
|
---|
[902] | 82 | public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
|
---|
[1648] | 83 | if (hasPermission(PermissiveSecurityAction.Show_Statistics))
|
---|
| 84 | return clientManager.GetAllUpTimeStatistics();
|
---|
| 85 | else
|
---|
| 86 | throw new PermissionException();
|
---|
[800] | 87 | }
|
---|
| 88 |
|
---|
[934] | 89 | public Response AddClientGroup(ClientGroup clientGroup) {
|
---|
[1648] | 90 | if (hasPermission(PermissiveSecurityAction.Add_ClientGroup))
|
---|
| 91 | return clientManager.AddClientGroup(clientGroup);
|
---|
| 92 | else
|
---|
| 93 | throw new PermissionException();
|
---|
[934] | 94 | }
|
---|
| 95 |
|
---|
[1449] | 96 | public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
|
---|
[1648] | 97 | if (hasPermission(PermissiveSecurityAction.Add_Resource))
|
---|
| 98 | return clientManager.AddResourceToGroup(clientGroupId, resource);
|
---|
| 99 | else
|
---|
| 100 | throw new PermissionException();
|
---|
[934] | 101 | }
|
---|
| 102 |
|
---|
[1449] | 103 | public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
|
---|
[1648] | 104 | if (hasPermission(PermissiveSecurityAction.Delete_Resource))
|
---|
| 105 | return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
|
---|
| 106 | else
|
---|
| 107 | throw new PermissionException();
|
---|
[934] | 108 | }
|
---|
| 109 |
|
---|
[800] | 110 | #endregion
|
---|
| 111 |
|
---|
| 112 | #region IJobManager Members
|
---|
| 113 |
|
---|
[902] | 114 | public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
|
---|
[1648] | 115 | if (hasPermission(PermissiveSecurityAction.Get_AllJobs))
|
---|
| 116 | return jobManager.GetAllJobs();
|
---|
| 117 | else
|
---|
| 118 | throw new PermissionException();
|
---|
[800] | 119 | }
|
---|
[1648] | 120 |
|
---|
[967] | 121 | public ResponseObject<Job> AddNewJob(Job job) {
|
---|
[1648] | 122 | if (hasPermission(PermissiveSecurityAction.Add_Job))
|
---|
| 123 | return jobManager.AddNewJob(job);
|
---|
| 124 | else
|
---|
| 125 | throw new PermissionException();
|
---|
[967] | 126 | }
|
---|
[800] | 127 |
|
---|
[1509] | 128 | public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
|
---|
[1648] | 129 | if (hasPermission(PermissiveSecurityAction.Get_LastJobResult))
|
---|
| 130 | return jobManager.GetLastJobResultOf(jobId, requested);
|
---|
| 131 | else
|
---|
| 132 | throw new PermissionException();
|
---|
[1171] | 133 | }
|
---|
| 134 |
|
---|
[1648] | 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 |
|
---|
[1449] | 142 | public Response RemoveJob(Guid jobId) {
|
---|
[1648] | 143 | if (hasPermission(PermissiveSecurityAction.Remove_Job))
|
---|
| 144 | return jobManager.RemoveJob(jobId);
|
---|
| 145 | else
|
---|
| 146 | throw new PermissionException();
|
---|
[967] | 147 | }
|
---|
| 148 |
|
---|
[1509] | 149 | public Response RequestSnapshot(Guid jobId) {
|
---|
[1648] | 150 | if (hasPermission(PermissiveSecurityAction.Request_Snapshot))
|
---|
| 151 | return jobManager.RequestSnapshot(jobId);
|
---|
| 152 | else
|
---|
| 153 | throw new PermissionException();
|
---|
[1509] | 154 | }
|
---|
| 155 |
|
---|
| 156 | public Response AbortJob(Guid jobId) {
|
---|
[1648] | 157 | if (hasPermission(PermissiveSecurityAction.Abort_Job))
|
---|
| 158 | return jobManager.AbortJob(jobId);
|
---|
| 159 | else
|
---|
| 160 | throw new PermissionException();
|
---|
[1509] | 161 | }
|
---|
| 162 |
|
---|
[1648] | 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 | */
|
---|
[1627] | 170 | }
|
---|
| 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 |
|
---|
[800] | 184 | #endregion
|
---|
[1648] | 185 |
|
---|
[800] | 186 | }
|
---|
| 187 | }
|
---|