Project

General

Profile

« Previous | Next » 

Revision 60490

[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.

View differences:

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
//}

Also available in: Unified diff