Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Security.Core/3.2/SecurityManager.cs @ 1601

Last change on this file since 1601 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 2.9 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Security.Contracts.Interfaces;
6using HeuristicLab.Security.Contracts.BusinessObjects;
7using HeuristicLab.Security.DataAccess;
8using HeuristicLab.PluginInfrastructure;
9
10namespace HeuristicLab.Security.Core {
11  public class SecurityManager : ISecurityManager {
12
13    private static DiscoveryService discoveryService =
14      new DiscoveryService();
15
16    private static IUserAdapter userAdapter = discoveryService.GetInstances<IUserAdapter>()[0];
17    private static IUserGroupAdapter userGroupAdapter = discoveryService.GetInstances<IUserGroupAdapter>()[0];
18    private static IPermissionOwnerAdapter permOwnerAdapter = discoveryService.GetInstances<IPermissionOwnerAdapter>()[0];
19    private static IPermissionAdapter permissionAdapter = discoveryService.GetInstances<IPermissionAdapter>()[0];
20
21    public User AddNewUser(User user) {
22      userAdapter.Update(user);
23      return user;
24    }
25
26    public User UpdateUser(User user) {
27      userAdapter.Update(user);
28      return user;
29    }
30
31    public bool RemoveUser(Guid userId) {
32      User user = userAdapter.GetById(userId);
33      if ( user != null )       // do we check this ?
34        return userAdapter.Delete(user);
35      return false;
36    }
37
38    public UserGroup AddNewUserGroup(UserGroup group) {
39      userGroupAdapter.Update(group);
40      return group;
41    }
42
43    public UserGroup UpdateUserGroup(UserGroup group) {
44      userGroupAdapter.Update(group);
45      return group;
46    }
47
48    public bool RemoveUserGroup(Guid groupId) {
49      UserGroup userGroup = userGroupAdapter.GetById(groupId);
50      if (userGroup != null)
51        return userGroupAdapter.Delete(userGroup);
52      return false;
53    }
54
55    public bool AddPermissionOwnerToGroup(Guid groupId, Guid permissionOwnerId) {
56      UserGroup userGroup = userGroupAdapter.GetById(groupId);
57      PermissionOwner permissionOwner = permOwnerAdapter.GetById(permissionOwnerId);
58      userGroup.Members.Add(permissionOwner);
59      userGroupAdapter.Update(userGroup);
60      return true;
61    }
62
63    public bool RemovePermissionOwnerFromGroup(Guid groupId, Guid permissionOwnerId) {
64      UserGroup userGroup = userGroupAdapter.GetById(groupId);
65      PermissionOwner permissionOwner = permOwnerAdapter.GetById(permissionOwnerId);
66      userGroup.Members.Add(permissionOwner);
67      userGroupAdapter.Delete(userGroup);
68      return true;
69    }
70
71    public bool GrantPermission(Guid permissionOwnerId, Guid permissionId, Guid entityId) {
72      return permissionAdapter.addPermission(permissionOwnerId, permissionId, entityId);
73    }
74
75    public bool RevokePermission(Guid permissionOwnerId, Guid permissionId, Guid entityId) {
76      return permissionAdapter.removePermission(permissionOwnerId, permissionId, entityId);
77    }
78 
79  }
80}
Note: See TracBrowser for help on using the repository browser.