|
|
|
@ -9,6 +9,7 @@ import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Component(value = "AuthorizationService")
|
|
|
|
|
public class AuthorizationService {
|
|
|
|
@ -53,19 +54,28 @@ public class AuthorizationService {
|
|
|
|
|
return mapType(type, false).toUpperCase() + "_" + id.toUpperCase();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isPortalAdmin() {
|
|
|
|
|
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(PORTAL_ADMIN));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isCurator(String type) {
|
|
|
|
|
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(curator(type)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isManager(String type, String id) {
|
|
|
|
|
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(manager(type, id)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isMember(String type, String id) {
|
|
|
|
|
return getRoles().stream().anyMatch(authority -> authority.equalsIgnoreCase(member(type, id)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<String> getRoles() {
|
|
|
|
|
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
|
|
|
|
|
if (authentication != null) {
|
|
|
|
|
List<GrantedAuthority> authorities = (List<GrantedAuthority>) authentication.getAuthorities();
|
|
|
|
|
if (authorities != null) {
|
|
|
|
|
List<String> roles = new ArrayList<>();
|
|
|
|
|
authorities.forEach((authority) -> {
|
|
|
|
|
roles.add(authority.getAuthority());
|
|
|
|
|
});
|
|
|
|
|
return roles;
|
|
|
|
|
}
|
|
|
|
|
return authentication.getAuthorities().stream().map(GrantedAuthority::getAuthority).collect(Collectors.toList());
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
return new ArrayList<>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getAaiId() {
|
|
|
|
|