Revision 60490
Added by Konstantina Galouni about 3 years ago
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/handlers/utils/RolesUtils.java | ||
---|---|---|
1 |
package eu.dnetlib.uoamonitorservice.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 boolean isPortalAdmin(List<String> roles) { |
|
23 |
if(roles == null) { |
|
24 |
return false; |
|
25 |
} |
|
26 |
// log.debug(authorizationService.PORTAL_ADMIN); |
|
27 |
// log.debug("PortalAdmin: "+roles.contains(authorizationService.PORTAL_ADMIN)); |
|
28 |
return roles.contains(authorizationService.PORTAL_ADMIN); |
|
29 |
} |
|
30 |
|
|
31 |
public boolean isCurator(List<String> roles, String type) { |
|
32 |
if(roles == null) { |
|
33 |
return false; |
|
34 |
} |
|
35 |
// log.debug(authorizationService.curator(type)); |
|
36 |
// log.debug("Curator in "+type+": "+roles.contains(authorizationService.curator(type))); |
|
37 |
return roles.contains(authorizationService.curator(type)); |
|
38 |
} |
|
39 |
|
|
40 |
public boolean isManager(List<String> roles, String type, String id) { |
|
41 |
if(roles == null) { |
|
42 |
return false; |
|
43 |
} |
|
44 |
// log.debug(authorizationService.manager(type, id)); |
|
45 |
// log.debug("Manager in "+type+" - "+id+": "+roles.contains(authorizationService.manager(type, id))); |
|
46 |
return roles.contains(authorizationService.manager(type, id)); |
|
47 |
} |
|
48 |
|
|
49 |
public boolean isMember(List<String> roles, String type, String id) { |
|
50 |
if(roles == null) { |
|
51 |
return false; |
|
52 |
} |
|
53 |
// log.debug(authorizationService.member(type, id)); |
|
54 |
// log.debug("Member in "+type+" - "+id+": "+roles.contains(authorizationService.member(type, id))); |
|
55 |
return roles.contains(authorizationService.member(type, id)); |
|
56 |
} |
|
57 |
|
|
58 |
public boolean isLoggedIn(List<String> roles) { |
|
59 |
if(roles == null || roles.contains(authorizationService.ANONYMOUS_USER)) { |
|
60 |
return false; |
|
61 |
} |
|
62 |
return true; |
|
63 |
} |
|
64 |
|
|
65 |
public boolean hasUpdateAuthority(List<String> roles, String type, String id) { |
|
66 |
return isPortalAdmin(roles) || isCurator(roles, type) || isManager(roles, type, id); |
|
67 |
} |
|
68 |
|
|
69 |
public boolean hasCreateAndDeleteAuthority(List<String> roles, String type) { |
|
70 |
return isPortalAdmin(roles) || isCurator(roles, type); |
|
71 |
} |
|
72 |
} |
|
1 |
//package eu.dnetlib.uoamonitorservice.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 boolean isPortalAdmin(List<String> roles) { |
|
23 |
// if(roles == null) { |
|
24 |
// return false; |
|
25 |
// } |
|
26 |
//// log.debug(authorizationService.PORTAL_ADMIN); |
|
27 |
//// log.debug("PortalAdmin: "+roles.contains(authorizationService.PORTAL_ADMIN)); |
|
28 |
// return roles.contains(authorizationService.PORTAL_ADMIN); |
|
29 |
// } |
|
30 |
// |
|
31 |
// public boolean isCurator(List<String> roles, String type) { |
|
32 |
// if(roles == null) { |
|
33 |
// return false; |
|
34 |
// } |
|
35 |
//// log.debug(authorizationService.curator(type)); |
|
36 |
//// log.debug("Curator in "+type+": "+roles.contains(authorizationService.curator(type))); |
|
37 |
// return roles.contains(authorizationService.curator(type)); |
|
38 |
// } |
|
39 |
// |
|
40 |
// public boolean isManager(List<String> roles, String type, String id) { |
|
41 |
// if(roles == null) { |
|
42 |
// return false; |
|
43 |
// } |
|
44 |
//// log.debug(authorizationService.manager(type, id)); |
|
45 |
//// log.debug("Manager in "+type+" - "+id+": "+roles.contains(authorizationService.manager(type, id))); |
|
46 |
// return roles.contains(authorizationService.manager(type, id)); |
|
47 |
// } |
|
48 |
// |
|
49 |
// public boolean isMember(List<String> roles, String type, String id) { |
|
50 |
// if(roles == null) { |
|
51 |
// return false; |
|
52 |
// } |
|
53 |
//// log.debug(authorizationService.member(type, id)); |
|
54 |
//// log.debug("Member in "+type+" - "+id+": "+roles.contains(authorizationService.member(type, id))); |
|
55 |
// return roles.contains(authorizationService.member(type, id)); |
|
56 |
// } |
|
57 |
// |
|
58 |
// public boolean isLoggedIn(List<String> roles) { |
|
59 |
// if(roles == null || roles.contains(authorizationService.ANONYMOUS_USER)) { |
|
60 |
// return false; |
|
61 |
// } |
|
62 |
// return true; |
|
63 |
// } |
|
64 |
// |
|
65 |
// public boolean hasUpdateAuthority(List<String> roles, String type, String id) { |
|
66 |
// return isPortalAdmin(roles) || isCurator(roles, type) || isManager(roles, type, id); |
|
67 |
// } |
|
68 |
// |
|
69 |
// public boolean hasCreateAndDeleteAuthority(List<String> roles, String type) { |
|
70 |
// return isPortalAdmin(roles) || isCurator(roles, type); |
|
71 |
// } |
|
72 |
//} |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/IndicatorController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 | 3 |
|
4 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
4 | 5 |
import eu.dnetlib.uoamonitorservice.dao.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.entities.*; |
6 | 7 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
7 | 8 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
8 | 9 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
9 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
10 | 10 |
import org.apache.log4j.Logger; |
11 | 11 |
import org.springframework.beans.factory.annotation.Autowired; |
12 | 12 |
import org.springframework.security.access.AccessDeniedException; |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/CategoryController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
3 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
6 | 7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
7 | 8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
8 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
9 | 9 |
import org.apache.log4j.Logger; |
10 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 11 |
import org.springframework.security.access.AccessDeniedException; |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/TopicController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
3 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
6 | 7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
7 | 8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
8 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
9 | 9 |
import org.apache.log4j.Logger; |
10 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 11 |
import org.springframework.security.access.AccessDeniedException; |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SectionController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
3 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
6 | 7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
7 | 8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
8 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
9 | 9 |
import org.apache.log4j.Logger; |
10 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 11 |
import org.springframework.security.access.AccessDeniedException; |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/StakeholderController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
3 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
6 | 7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
7 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
8 | 8 |
import org.apache.log4j.Logger; |
9 | 9 |
import org.springframework.beans.factory.annotation.Autowired; |
10 | 10 |
|
... | ... | |
337 | 337 |
} |
338 | 338 |
|
339 | 339 |
@RequestMapping(value = "/stakeholder", method = RequestMethod.GET) |
340 |
public List<Stakeholder> getAllRealStakeholders(@RequestParam(required = false) String type) { |
|
340 |
public List<Stakeholder> getAllRealStakeholders(@RequestParam(required = false) String type, |
|
341 |
@RequestParam(required = false) String defaultId) { |
|
341 | 342 |
// log.debug("get all NOT default stakeholders" + (type != null ? " with type: "+type : "")); |
342 | 343 |
|
343 | 344 |
List<Stakeholder> stakeholders; |
344 |
if(type == null) { |
|
345 |
if(type != null && defaultId != null) { |
|
346 |
stakeholders = stakeholderDAO.findByDefaultIdAndType(defaultId, type); |
|
347 |
} else if(defaultId != null) { |
|
348 |
stakeholders = stakeholderDAO.findByDefaultId(defaultId); |
|
349 |
} else if(type != null) { |
|
350 |
stakeholders = stakeholderDAO.findByDefaultIdNotAndType(null, type); |
|
351 |
} else { |
|
345 | 352 |
stakeholders = stakeholderDAO.findByDefaultIdNot(null); |
346 |
} else { |
|
347 |
stakeholders = stakeholderDAO.findByDefaultIdNotAndType(null, type); |
|
348 | 353 |
} |
349 | 354 |
|
350 | 355 |
//List<Stakeholder> stakeholdersFull = new ArrayList<>(); |
modules/uoa-monitor-service/trunk/src/main/java/eu/dnetlib/uoamonitorservice/controllers/SubCategoryController.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.uoamonitorservice.controllers; |
2 | 2 |
|
3 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.utils.RolesUtils; |
|
3 | 4 |
import eu.dnetlib.uoamonitorservice.dao.*; |
4 | 5 |
import eu.dnetlib.uoamonitorservice.entities.*; |
5 | 6 |
import eu.dnetlib.uoamonitorservice.handlers.EntityNotFoundException; |
6 | 7 |
import eu.dnetlib.uoaadmintoolslibrary.handlers.ForbiddenException; |
7 | 8 |
import eu.dnetlib.uoamonitorservice.handlers.PathNotValidException; |
8 |
import eu.dnetlib.uoamonitorservice.handlers.utils.RolesUtils; |
|
9 | 9 |
import org.apache.log4j.Logger; |
10 | 10 |
import org.springframework.beans.factory.annotation.Autowired; |
11 | 11 |
import org.springframework.security.access.AccessDeniedException; |
Also available in: Unified diff
[Trunk | Monitor Service]:
1. RolesUtils.java: Comment all contents of this file (should be removed in next commit). This file is added in uoa-admin-tools-library.
2. StakeholderController.java & TopicController.java & CategoryController.java & SubCategoryController.java & SectionController.java & IndicatorController.java: Import RolesUtils from uoa-admin-tools-library.
3. StakeholderController.java: In "getAllRealStakeholders()" method, add optional parameter "defaultId", to get Stakeholders based on a default profile.