1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
6 | using HeuristicLab.Security.Contracts.BusinessObjects;
|
---|
7 | using HeuristicLab.Security.DataAccess;
|
---|
8 | using HeuristicLab.PluginInfrastructure;
|
---|
9 |
|
---|
10 | namespace 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 | }
|
---|