2021-07-06 16:47:39 +02:00
|
|
|
package eu.dnetlib.dnetrolemanagement.utils;
|
|
|
|
|
|
|
|
import org.mitre.openid.connect.model.OIDCAuthenticationToken;
|
|
|
|
import org.springframework.security.core.Authentication;
|
|
|
|
import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
|
|
|
|
|
public class AuthoritiesUtils {
|
|
|
|
|
2021-10-18 15:46:38 +02:00
|
|
|
public static String PORTAL_ADMIN = "PORTAL_ADMINISTRATOR";
|
|
|
|
|
|
|
|
public static String portalAdminRole() {
|
|
|
|
return "Portal Administrator";
|
|
|
|
}
|
|
|
|
|
2021-07-07 16:38:58 +02:00
|
|
|
/**
|
2021-07-15 14:00:06 +02:00
|
|
|
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc.
|
|
|
|
*/
|
2021-07-07 16:38:58 +02:00
|
|
|
public static String curator(String type) {
|
2021-09-09 18:54:31 +02:00
|
|
|
return "CURATOR_" + type.replaceAll("[.]", "_").toUpperCase();
|
2021-07-07 16:38:58 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 14:00:06 +02:00
|
|
|
public static String curatorRole(String type) {
|
2021-09-09 18:54:31 +02:00
|
|
|
return "Curator - " + Character.toString(type.replaceAll("[.]", "_").charAt(0)).toUpperCase() + type.substring(1);
|
2021-07-15 14:00:06 +02:00
|
|
|
}
|
|
|
|
|
2021-07-07 16:38:58 +02:00
|
|
|
/**
|
2021-07-15 14:00:06 +02:00
|
|
|
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc.
|
|
|
|
* <p>
|
2021-07-07 16:38:58 +02:00
|
|
|
* Id = EE, EGI, etc
|
2021-07-15 14:00:06 +02:00
|
|
|
*/
|
2021-07-07 16:38:58 +02:00
|
|
|
public static String manager(String type, String id) {
|
2021-09-09 18:54:31 +02:00
|
|
|
return type.replaceAll("[.]", "_").toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
|
2021-07-07 16:38:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-15 14:00:06 +02:00
|
|
|
* Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT etc.
|
|
|
|
* <p>
|
2021-07-07 16:38:58 +02:00
|
|
|
* Id = EE, EGI, etc
|
2021-07-15 14:00:06 +02:00
|
|
|
*/
|
2021-07-06 16:47:39 +02:00
|
|
|
public static String member(String type, String id) {
|
2021-09-09 18:54:31 +02:00
|
|
|
return type.replaceAll("[.]", "_").toUpperCase() + "_" + id.toUpperCase();
|
2021-07-06 16:47:39 +02:00
|
|
|
}
|
|
|
|
|
2021-07-15 14:00:06 +02:00
|
|
|
public static String memberRole(String type, String id) {
|
|
|
|
return type + "." + id;
|
|
|
|
}
|
|
|
|
|
2021-07-06 16:47:39 +02:00
|
|
|
public static String getAaiId() {
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
2021-07-15 14:00:06 +02:00
|
|
|
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken) authentication).getSub() : null;
|
2021-07-06 16:47:39 +02:00
|
|
|
}
|
|
|
|
}
|