Project

General

Profile

« Previous | Next » 

Revision 61526

[Users | Trunk]: Merge user info method of members and managers (Keep old paths). Add create member role for a type.id.

View differences:

AuthorizationService.java
8 8

  
9 9
import java.util.ArrayList;
10 10
import java.util.List;
11
import java.util.stream.Collectors;
11 12

  
12 13
@Component("AuthorizationService")
13 14
public class AuthorizationService {
......
55 56
        return mapType(type, false).equals("community");
56 57
    }
57 58

  
59
    public boolean isPortalAdmin() {
60
        return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(PORTAL_ADMIN));
61
    }
58 62

  
63
    public boolean isCurator(String type) {
64
        return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(curator(type)));
65
    }
66

  
67
    public boolean isManager(String type, String id) {
68
        return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(manager(type, id)));
69
    }
70

  
71
    public boolean isMember(String type, String id) {
72
        return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(member(type, id)));
73
    }
74

  
59 75
    public List<String> getRoles() {
60 76
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
61
        if (authentication != null) {
62
            List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
63
            if (authorities != null) {
64
                List<String> roles = new ArrayList<>();
65
                authorities.forEach((authority) -> {
66
                    roles.add(authority.getAuthority());
67
                });
68
                return roles;
69
            }
77
        if (authentication instanceof OIDCAuthenticationToken) {
78
            return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
70 79
        }
71
        return null;
80
        return new ArrayList<>();
72 81
    }
73 82

  
74 83
    public String getAaiId() {

Also available in: Unified diff