1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
package org.openecomp.sdc.itempermissions.dao.impl;
import org.openecomp.sdc.common.session.SessionContextProviderFactory;
import org.openecomp.sdc.itempermissions.PermissionsRules;
import org.openecomp.sdc.itempermissions.PermissionsServices;
import org.openecomp.sdc.itempermissions.dao.ItemPermissionsDao;
import org.openecomp.sdc.itempermissions.type.ItemPermissionsEntity;
import java.util.Collection;
import java.util.Set;
/**
* Created by ayalaben on 6/22/2017.
*/
public class PermissionsServicesImpl implements PermissionsServices {
private ItemPermissionsDao permissionsDao;
private PermissionsRules permissionsRules;
private static final String CHANGE_PERMISSIONS = "Change_Item_Permissions";
public PermissionsServicesImpl(PermissionsRules permissionsRules,
ItemPermissionsDao permissionsDao) {
this.permissionsDao = permissionsDao;
this.permissionsRules = permissionsRules;
}
@Override
public Collection<ItemPermissionsEntity> listItemPermissions(String itemId) {
return permissionsDao.listItemPermissions(itemId);
}
@Override
public void updateItemPermissions(String itemId, String permission, Set<String> addedUsersIds,
Set<String> removedUsersIds) {
String currentUserId = SessionContextProviderFactory.getInstance()
.createInterface().get().getUser().getUserId();
permissionsRules.executeAction(itemId,currentUserId,CHANGE_PERMISSIONS);
permissionsRules.updatePermission(itemId,currentUserId,permission,addedUsersIds,
removedUsersIds);
permissionsDao.updateItemPermissions(itemId, permission,
addedUsersIds, removedUsersIds);
}
@Override
public boolean isAllowed(String itemId,String userId,String action) {
String userPermission = permissionsDao.getUserItemPermiission(itemId,userId);
return permissionsRules.isAllowed(userPermission,action);
}
@Override
public void execute(String itemId,String userId,String action) {
permissionsRules.executeAction(itemId, userId, action);
}
@Override
public String getUserItemPermiission(String itemId, String userId) {
return permissionsDao.getUserItemPermiission(itemId,userId);
}
}
|