[Authorization-Library | Trunk]: Authorization Service add boolean communityMap on mapType

This commit is contained in:
Konstantinos Triantafyllou 2021-01-27 13:47:55 +00:00
parent cc70806ad2
commit 89e87dea27
1 changed files with 15 additions and 17 deletions

View File

@ -19,11 +19,10 @@ public class AuthorizationService {
public final String REGISTERED_USER = "REGISTERED_USER"; public final String REGISTERED_USER = "REGISTERED_USER";
private String mapType(String type) { private String mapType(String type, boolean communityMap) {
if(type.equals("organization")) { if (type.equals("organization")) {
type = "institution"; type = "institution";
} } else if (type.equals("ri") && communityMap) {
if(type.equals("ri")) {
type = "community"; type = "community";
} }
return type; return type;
@ -31,35 +30,34 @@ public class AuthorizationService {
/** /**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
* */
* */
public String curator(String type) { public String curator(String type) {
return "CURATOR_"+mapType(type).toUpperCase(); return "CURATOR_" + mapType(type, true).toUpperCase();
} }
/** /**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT * Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
* * <p>
* Id = EE, EGI, etc * Id = EE, EGI, etc
* */ */
public String manager(String type, String id) { public String manager(String type, String id) {
return mapType(type).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER"; return mapType(type, true).toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
} }
/** /**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT * Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
* * <p>
* Id = EE, EGI, etc * Id = EE, EGI, etc
* */ */
public String member(String type, String id) { public String member(String type, String id) {
return mapType(type).toUpperCase() + "_" + id.toUpperCase(); return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
} }
public List<String> getRoles() { public List<String> getRoles() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null) { if (authentication != null) {
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities(); List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
if(authorities != null) { if (authorities != null) {
List<String> roles = new ArrayList<>(); List<String> roles = new ArrayList<>();
authorities.forEach((authority) -> { authorities.forEach((authority) -> {
roles.add(authority.getAuthority()); roles.add(authority.getAuthority());
@ -72,7 +70,7 @@ public class AuthorizationService {
public String getAaiId() { public String getAaiId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if(authentication != null) { if (authentication != null) {
User user = (User) authentication.getPrincipal(); User user = (User) authentication.getPrincipal();
return user.getPassword(); return user.getPassword();
} }