1 |
60495
|
konstantin
|
package eu.dnetlib.uoaadmintoolslibrary.handlers.utils;
|
2 |
|
|
|
3 |
|
|
import eu.dnetlib.uoaauthorizationlibrary.security.AuthorizationService;
|
4 |
|
|
import org.apache.log4j.Logger;
|
5 |
|
|
|
6 |
|
|
import java.util.List;
|
7 |
|
|
|
8 |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
9 |
|
|
import org.springframework.stereotype.Component;
|
10 |
|
|
|
11 |
|
|
@Component
|
12 |
|
|
public class RolesUtils {
|
13 |
|
|
@Autowired
|
14 |
|
|
private AuthorizationService authorizationService;
|
15 |
|
|
|
16 |
|
|
private final Logger log = Logger.getLogger(this.getClass());
|
17 |
|
|
|
18 |
|
|
public List<String> getRoles() {
|
19 |
|
|
return authorizationService.getRoles();
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
public String getEmail() {
|
23 |
|
|
return authorizationService.getAaiId();
|
24 |
|
|
}
|
25 |
|
|
|
26 |
|
|
public String getAaiId() {
|
27 |
|
|
return authorizationService.getAaiId();
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
public boolean isPortalAdmin(List<String> roles) {
|
31 |
|
|
if(roles == null) {
|
32 |
|
|
return false;
|
33 |
|
|
}
|
34 |
|
|
// log.debug(authorizationService.PORTAL_ADMIN);
|
35 |
|
|
// log.debug("PortalAdmin: "+roles.contains(authorizationService.PORTAL_ADMIN));
|
36 |
|
|
return roles.contains(authorizationService.PORTAL_ADMIN);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
public boolean isCurator(List<String> roles, String type) {
|
40 |
|
|
if(roles == null) {
|
41 |
|
|
return false;
|
42 |
|
|
}
|
43 |
|
|
// log.debug(authorizationService.curator(type));
|
44 |
|
|
// log.debug("Curator in "+type+": "+roles.contains(authorizationService.curator(type)));
|
45 |
|
|
return roles.contains(authorizationService.curator(type));
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
public boolean isManager(List<String> roles, String type, String id) {
|
49 |
|
|
if(roles == null) {
|
50 |
|
|
return false;
|
51 |
|
|
}
|
52 |
|
|
// log.debug(authorizationService.manager(type, id));
|
53 |
|
|
// log.debug("Manager in "+type+" - "+id+": "+roles.contains(authorizationService.manager(type, id)));
|
54 |
|
|
return roles.contains(authorizationService.manager(type, id));
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
public boolean isMember(List<String> roles, String type, String id) {
|
58 |
|
|
if(roles == null) {
|
59 |
|
|
return false;
|
60 |
|
|
}
|
61 |
|
|
// log.debug(authorizationService.member(type, id));
|
62 |
|
|
// log.debug("Member in "+type+" - "+id+": "+roles.contains(authorizationService.member(type, id)));
|
63 |
|
|
return roles.contains(authorizationService.member(type, id));
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
public boolean isLoggedIn(List<String> roles) {
|
67 |
|
|
if(roles == null || roles.contains(authorizationService.ANONYMOUS_USER)) {
|
68 |
|
|
return false;
|
69 |
|
|
}
|
70 |
|
|
return true;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
|
|
public boolean hasUpdateAuthority(List<String> roles, String type, String id) {
|
74 |
|
|
return isPortalAdmin(roles) || isCurator(roles, type) || isManager(roles, type, id);
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
public boolean hasCreateAndDeleteAuthority(List<String> roles, String type) {
|
78 |
|
|
return isPortalAdmin(roles) || isCurator(roles, type);
|
79 |
|
|
}
|
80 |
|
|
}
|