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