dnet-role-management/src/main/java/eu/dnetlib/dnetrolemanagement/utils/AuthoritiesUtils.java

40 lines
1.2 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
*
* */
public static String curator(String type) {
return "CURATOR_" + type.toUpperCase();
}
/**
* Type = FUNDER | COMMUNITY | INSTITUTION | PROJECT
*
* Id = EE, EGI, etc
* */
public static String manager(String type, String id) {
return type.toUpperCase() + "_" + id.toUpperCase() + "_MANAGER";
}
/**
* Type = FUNDER | COMMUNITY | RI | INSTITUTION | PROJECT
*
* Id = EE, EGI, etc
* */
public static String member(String type, String id) {
return type.toUpperCase() + "_" + id.toUpperCase();
}
public static String getAaiId() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
return authentication instanceof OIDCAuthenticationToken ? ((OIDCAuthenticationToken)authentication).getSub() : null;
}
}