Revision 61371
Added by Konstantinos Spyrou almost 3 years ago
AuthoritiesMapper.java | ||
---|---|---|
21 | 21 |
|
22 | 22 |
public static Collection<GrantedAuthority> map(JsonArray entitlements) { |
23 | 23 |
HashSet<GrantedAuthority> authorities = new HashSet<>(); |
24 |
provideRoles(entitlements, authorities); |
|
25 | 24 |
entityRoles(entitlements, authorities); |
26 | 25 |
return authorities; |
27 | 26 |
} |
... | ... | |
71 | 70 |
} |
72 | 71 |
} |
73 | 72 |
|
74 |
// TODO: remove when ROLE_ADMIN and ROLE_PROVIDE_ADMIN are removed from project |
|
75 |
private static void provideRoles(JsonArray entitlements, Set<GrantedAuthority> authorities) { |
|
76 |
Map<String, String> userRoles = new HashMap() {{ |
|
77 |
put("urn:geant:openaire.eu:group:Super+Administrator:role=member#aai.openaire.eu", "ROLE_ADMIN"); |
|
78 |
put("urn:geant:openaire.eu:group:Content+Provider+Dashboard+Administrator:role=member#aai.openaire.eu", "ROLE_PROVIDE_ADMIN"); |
|
79 |
}}; |
|
80 |
Map<String, SimpleGrantedAuthority> userRolesMap = new HashMap<>(); |
|
81 |
userRoles.forEach((openaireRole, appRole) -> userRolesMap.put(openaireRole, new SimpleGrantedAuthority(appRole))); |
|
82 |
authorities.add(new SimpleGrantedAuthority("ROLE_USER")); |
|
83 |
if (entitlements != null) { |
|
84 |
entitlements.forEach(role -> { |
|
85 |
SimpleGrantedAuthority authority = userRolesMap.get(role.getAsString()); |
|
86 |
if (authority != null) { |
|
87 |
authorities.add(authority); |
|
88 |
} |
|
89 |
}); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 | 73 |
} |
Also available in: Unified diff
1. changed user roles defined in the project to authorities given by the aai.
2. created method returning user roles with desired status (active, deleted).