Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1648 for trunk/sources


Ignore:
Timestamp:
04/24/09 12:07:58 (16 years ago)
Author:
mbecirov
Message:

#586: Add permission constants and adopt server console

Location:
trunk/sources/HeuristicLab.Hive.Server.Core/3.2
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/HeuristicLab.Hive.Server.Core-3.2.csproj

    r1534 r1648  
    9393    <Compile Include="JobManager.cs" />
    9494    <Compile Include="LifecycleManager.cs" />
     95    <Compile Include="PermissiveSecurityConstants.cs" />
    9596    <Compile Include="Properties\AssemblyInfo.cs" />
    9697    <Compile Include="ServerConsoleFacade.cs" />
     
    137138      <Name>HeuristicLab.PluginInfrastructure</Name>
    138139    </ProjectReference>
     140    <ProjectReference Include="..\..\HeuristicLab.Security.Contracts\3.2\HeuristicLab.Security.Contracts-3.2.csproj">
     141      <Project>{D59E852C-F205-4647-8C05-EB9ED1CF44E9}</Project>
     142      <Name>HeuristicLab.Security.Contracts-3.2</Name>
     143    </ProjectReference>
    139144  </ItemGroup>
    140145  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServerConsoleFacade.cs

    r1627 r1648  
    2727using HeuristicLab.Hive.Contracts.BusinessObjects;
    2828using HeuristicLab.Hive.Contracts;
     29using HeuristicLab.Security.Contracts.Interfaces;
    2930
    3031namespace HeuristicLab.Hive.Server.Core {
     
    3637      ServiceLocator.GetJobManager();
    3738
    38     private String loginName = null;
     39    private IPermissionManager permManager = ServiceLocator.GetPermissionManager();
    3940
    4041    #region IServerConsoleFacade Members
    4142
     43    public Guid sessionID = Guid.Empty;
     44
    4245    public Response Login(string username, string password) {
    4346      Response resp = new Response();
    44 
    45       loginName = username;
    46 
    47       resp.Success = true;
    48       resp.StatusMessage =
    49         ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
    50 
     47      sessionID = permManager.Authenticate(username, password);
     48      if (sessionID == Guid.Empty)
     49        resp.Success = false;
     50      else {
     51        resp.Success = true;
     52        resp.StatusMessage =
     53          ApplicationConstants.RESPONSE_SERVERCONSOLE_LOGIN_SUCCESS;
     54      }
    5155      return resp;
    5256    }
     
    5761
    5862    public ResponseList<ClientInfo> GetAllClients() {
    59       return clientManager.GetAllClients();
     63      if (hasPermission(PermissiveSecurityAction.List_AllClients))
     64        return clientManager.GetAllClients();
     65      else
     66        throw new PermissionException();
    6067    }
    6168
    6269    public ResponseList<ClientGroup> GetAllClientGroups() {
    63       return clientManager.GetAllClientGroups();
     70      if (hasPermission(PermissiveSecurityAction.List_AllClientGroups))
     71        return clientManager.GetAllClientGroups();
     72      else
     73        throw new PermissionException();
    6474    }
    6575
    6676    public ResponseList<UpTimeStatistics> GetAllUpTimeStatistics() {
    67       return clientManager.GetAllUpTimeStatistics();
     77      if (hasPermission(PermissiveSecurityAction.Show_Statistics))
     78        return clientManager.GetAllUpTimeStatistics();
     79      else
     80        throw new PermissionException();
    6881    }
    6982
    7083    public Response AddClientGroup(ClientGroup clientGroup) {
    71       return clientManager.AddClientGroup(clientGroup);
     84      if (hasPermission(PermissiveSecurityAction.Add_ClientGroup))
     85        return clientManager.AddClientGroup(clientGroup);
     86      else
     87        throw new PermissionException();
    7288    }
    7389
    7490    public Response AddResourceToGroup(Guid clientGroupId, Resource resource) {
    75       return clientManager.AddResourceToGroup(clientGroupId, resource);
     91      if (hasPermission(PermissiveSecurityAction.Add_Resource))
     92        return clientManager.AddResourceToGroup(clientGroupId, resource);
     93      else
     94        throw new PermissionException();
    7695    }
    7796
    7897    public Response DeleteResourceFromGroup(Guid clientGroupId, Guid resourceId) {
    79       return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
     98      if (hasPermission(PermissiveSecurityAction.Delete_Resource))
     99        return clientManager.DeleteResourceFromGroup(clientGroupId, resourceId);
     100      else
     101        throw new PermissionException();
    80102    }
    81103
     
    85107
    86108    public ResponseList<HeuristicLab.Hive.Contracts.BusinessObjects.Job> GetAllJobs() {
    87       return jobManager.GetAllJobs();
     109      if (hasPermission(PermissiveSecurityAction.Get_AllJobs))
     110        return jobManager.GetAllJobs();
     111      else
     112        throw new PermissionException();
    88113    }
     114
    89115    public ResponseObject<Job> AddNewJob(Job job) {
    90       return jobManager.AddNewJob(job);
     116      if (hasPermission(PermissiveSecurityAction.Add_Job))
     117        return jobManager.AddNewJob(job);
     118      else
     119        throw new PermissionException();
    91120    }
    92121
    93122    public ResponseObject<JobResult> GetLastJobResultOf(Guid jobId, bool requested) {
    94       return jobManager.GetLastJobResultOf(jobId, requested);
     123      if (hasPermission(PermissiveSecurityAction.Get_LastJobResult))
     124        return jobManager.GetLastJobResultOf(jobId, requested);
     125      else
     126        throw new PermissionException();
     127    }
     128
     129    public ResponseObject<List<JobResult>> GetAllJobResults(Guid jobId) {
     130      if (hasPermission(PermissiveSecurityAction.Get_AllJobResults))
     131        return jobManager.GetAllJobResults(jobId);
     132      else
     133        throw new PermissionException();
    95134    }
    96135
    97136    public Response RemoveJob(Guid jobId) {
    98       return jobManager.RemoveJob(jobId);
     137      if (hasPermission(PermissiveSecurityAction.Remove_Job))
     138        return jobManager.RemoveJob(jobId);
     139      else
     140        throw new PermissionException();
    99141    }
    100142
    101143    public Response RequestSnapshot(Guid jobId) {
    102       return jobManager.RequestSnapshot(jobId);
     144      if (hasPermission(PermissiveSecurityAction.Request_Snapshot))
     145        return jobManager.RequestSnapshot(jobId);
     146      else
     147        throw new PermissionException();
    103148    }
    104149
    105150    public Response AbortJob(Guid jobId) {
    106       return jobManager.AbortJob(jobId);
     151      if (hasPermission(PermissiveSecurityAction.Abort_Job))
     152        return jobManager.AbortJob(jobId);
     153      else
     154        throw new PermissionException();
    107155    }
    108156
    109     public ResponseObject<List<JobResult>> GetAllJobResults(Guid jobId) {
    110       throw new NotImplementedException();
     157    private bool hasPermission(Guid action) {
     158      return true;
     159      /*
     160      if (sessionID == Guid.Empty)
     161        throw new Exception("sessionID is not set! Please check if user is successfully logged on!");
     162      return permManager.CheckPermission(sessionID, action, Guid.Empty);
     163       */
     164    }
     165
     166    public class PermissionException : Exception {
     167      public PermissionException()
     168        : base("Current user has insufficent rights for this action!") {
     169      }
     170
     171      public PermissionException(string msg)
     172        : base(msg) {
     173      }
     174
     175
    111176    }
    112177
    113178    #endregion
     179
    114180  }
    115181}
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ServiceLocator.cs

    r1530 r1648  
    2828using HeuristicLab.DataAccess.Interfaces;
    2929using System.Data.SqlClient;
     30using HeuristicLab.Security.Contracts.Interfaces;
    3031
    3132/// <summary>
     
    4748
    4849  private static IScheduler scheduler = null;
     50
     51  private static IPermissionManager permManager = null;
    4952
    5053  /// <summary>
     
    129132    return scheduler;
    130133  }
     134
     135  /// <summary>
     136  /// Gets the permission manager
     137  /// </summary>
     138  /// <returns></returns>
     139  [MethodImpl(MethodImplOptions.Synchronized)] 
     140  public static IPermissionManager GetPermissionManager() {
     141    if (permManager == null)
     142      permManager = discoveryService.GetInstances<IPermissionManager>()[0];
     143    return permManager;
     144   
     145  }
    131146}
Note: See TracChangeset for help on using the changeset viewer.