1
|
package eu.dnetlib.uoanotificationservice.utils;
|
2
|
|
3
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
4
|
import eu.dnetlib.uoanotificationservice.dao.NotificationDAO;
|
5
|
import eu.dnetlib.uoanotificationservice.entities.Notification;
|
6
|
import eu.dnetlib.uoanotificationservice.services.NotificationService;
|
7
|
import org.apache.log4j.Logger;
|
8
|
import org.springframework.beans.factory.annotation.Autowired;
|
9
|
import org.springframework.stereotype.Component;
|
10
|
|
11
|
import java.util.HashSet;
|
12
|
import java.util.Set;
|
13
|
|
14
|
@Component("Utils")
|
15
|
public class Utils {
|
16
|
|
17
|
Logger logger = Logger.getLogger(Utils.class);
|
18
|
|
19
|
@Autowired
|
20
|
private AuthorizationService authorizationService;
|
21
|
|
22
|
@Autowired
|
23
|
private NotificationDAO notificationDAO;
|
24
|
|
25
|
public boolean canRead(String id) {
|
26
|
Set<String> groups = new HashSet<>(authorizationService.getRoles());
|
27
|
groups.add("all");
|
28
|
groups.add(authorizationService.getAaiId());
|
29
|
return notificationDAO.findByIdAndUserNotAndGroupsIn(id, authorizationService.getAaiId(), groups) != null;
|
30
|
}
|
31
|
|
32
|
/*public boolean hasValidGroups(Set<String> groups) {
|
33
|
Set<String> roles = new HashSet<>(authorizationService.getRoles());
|
34
|
if(roles.contains(authorizationService.PORTAL_ADMIN)) {
|
35
|
return true;
|
36
|
}
|
37
|
for(String group : groups) {
|
38
|
|
39
|
}
|
40
|
return false;
|
41
|
}*/
|
42
|
}
|