47 lines
1.4 KiB
Java
47 lines
1.4 KiB
Java
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 {
|
|
|
|
/**
|
|
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc.
|
|
*/
|
|
public static String curator(String type) {
|
|
return "CURATOR_" + type.toUpperCase();
|
|
}
|
|
|
|
public static String curatorRole(String type) {
|
|
return "Curator - " + Character.toString(type.charAt(0)).toUpperCase() + type.substring(1);
|
|
}
|
|
|
|
/**
|
|
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT etc.
|
|
* <p>
|
|
* Id = EE, EGI, etc
|
|
*/
|
|
public static String manager(String type, String id) {
|
|
return type.toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
|
|
}
|
|
|
|
/**
|
|
* Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT etc.
|
|
* <p>
|
|
* Id = EE, EGI, etc
|
|
*/
|
|
public static String member(String type, String id) {
|
|
return type.toUpperCase() + "_" + id.toUpperCase();
|
|
}
|
|
|
|
public static String memberRole(String type, String id) {
|
|
return type + "." + id;
|
|
}
|
|
|
|
public static String getAaiId() {
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken) authentication).getSub() : null;
|
|
}
|
|
}
|