Project

General

Profile

« Previous | Next » 

Revision 60487

[Authorization-libary | Redis]: Merge from trunk

View differences:

modules/uoa-authorization-library/branches/redis/src/main/java/eu/dnetlib/uoaauthorizationlibrary/security/AuthorizationService.java
18 18

  
19 19
    public final String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
20 20
    public final String ANONYMOUS_USER = "ROLE_ANONYMOUS";
21
    public final String REGISTERED_USER = "REGISTERED_USER";
21 22

  
22
    private String mapType(String type) {
23
        if(type.equals("organization")) {
23

  
24
    private String mapType(String type, boolean communityMap) {
25
        if (type.equals("organization")) {
24 26
            type = "institution";
25
        }
26
        if(type.equals("ri")) {
27
        } else if (type.equals("ri") && communityMap) {
27 28
            type = "community";
28 29
        }
29 30
        return type;
......
31 32

  
32 33
    /**
33 34
     * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
34
     *
35
     * */
35
     */
36 36
    public String curator(String type) {
37
        return "CURATOR_"+mapType(type).toUpperCase();
37
        return "CURATOR_" + mapType(type, true).toUpperCase();
38 38
    }
39 39

  
40 40
    /**
41 41
     * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
42
     *
42
     * <p>
43 43
     * Id = EE, EGI, etc
44
     * */
44
     */
45 45
    public String manager(String type, String id) {
46
        return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
46
        return mapType(type, true).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
47 47
    }
48 48

  
49 49
    /**
50
     * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
51
     *
50
     * Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
51
     * <p>
52 52
     * Id = EE, EGI, etc
53
     * */
53
     */
54 54
    public String member(String type, String id) {
55
        return mapType(type).toUpperCase() + "_" + id.toUpperCase();
55
        return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
56 56
    }
57 57

  
58 58
    public List<String> getRoles() {
59 59
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
60
        if(authentication != null) {
60
        if (authentication != null) {
61 61
            List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
62
            if(authorities != null) {
62
            if (authorities != null) {
63 63
                List<String> roles = new ArrayList<>();
64 64
                authorities.forEach((authority) -> {
65 65
                    roles.add(authority.getAuthority());
......
72 72

  
73 73
    public String getAaiId() {
74 74
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
75
        if(authentication instanceof OIDCAuthenticationToken) {
76
            return ((OIDCAuthenticationToken) authentication).getSub();
77
        }
78
        return null;
75
        return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null;
79 76
    }
80 77
}

Also available in: Unified diff