Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone2/sources/HeuristicLab.Hive.Server.Core/3.2/HivePermissionManager.cs @ 6911

Last change on this file since 6911 was 1764, checked in by mbecirov, 16 years ago

#586 Controls the service access

File size: 2.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Security.Contracts.Interfaces;
6using HeuristicLab.DataAccess;
7using HeuristicLab.Security.Contracts.BusinessObjects;
8using HeuristicLab.Hive.Contracts.BusinessObjects;
9using HeuristicLab.Hive.Contracts.Interfaces;
10using HeuristicLab.Hive.Contracts;
11using HeuristicLab.Hive.Server.Core.InternalInterfaces;
12
13namespace HeuristicLab.Hive.Server.Core {
14  public class HivePermissionManager : IHivePermissionManager {
15   
16    private IPermissionManager permManager = ServiceLocator.GetPermissionManager();
17
18    private IClientManager clientManager = ServiceLocator.GetClientManager();
19
20    /// <summary>
21    /// Authenticates a user and returns a valid guid if success.
22    /// </summary>
23    /// <param name="username"></param>
24    /// <param name="password"></param>
25    /// <returns></returns>
26    public Guid Login(string username, string password) {
27      return permManager.Authenticate(username, password);
28    }
29
30    /// <summary>
31    /// Checks if a user has permission for a specified action.
32    /// </summary>
33    /// <param name="sessionID">The current session.</param>
34    /// <param name="actionID">A pre-defined action that requires permission.</param>
35    /// <param name="entityID">A resource (Job,...)</param>
36    /// <returns></returns>
37    public bool CheckPermission(Guid sessionID, Guid actionID, Guid entityId) {
38      bool hasPerm = permManager.CheckPermission(sessionID, actionID, entityId);
39     
40      if (!hasPerm) {
41        if ((actionID == PermissiveSecurityAction.Add_Job) ||
42            (actionID == PermissiveSecurityAction.Remove_Job) ||
43            (actionID == PermissiveSecurityAction.Request_Snapshot)||
44            (actionID==PermissiveSecurityAction.Abort_Job))
45          if (CheckPermissionHelper(sessionID, actionID, entityId)) return true;
46      }
47
48      return hasPerm;     
49    }
50
51    private bool CheckPermissionHelper(Guid sessionId, Guid actionId, Guid entityId) {
52      IList<ClientGroup> groups = clientManager.GetAllGroupsOfResource(entityId).Obj;
53      foreach (ClientGroup group in groups)
54        if (CheckPermission(sessionId, actionId, group.Id)) return true;
55      return false;
56    }
57  }
58}
Note: See TracBrowser for help on using the repository browser.