Search in sources :

Example 1 with ProviderBundle

use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.

the class EICAuthoritiesMapper method mapAuthorities.

private void mapAuthorities(String admins) {
    userRolesMap = new HashMap<>();
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    try {
        List<ProviderBundle> providers = providerService.getAll(ff, securityService.getAdminAccess()).getResults();
        providers.addAll(pendingProviderService.getAll(ff, null).getResults());
        userRolesMap = providers.stream().distinct().map(providerBundle -> {
            if (providerBundle.getProvider() != null && providerBundle.getProvider().getUsers() != null) {
                return providerBundle.getProvider();
            }
            return null;
        }).filter(Objects::nonNull).flatMap((Function<Provider, Stream<String>>) provider -> provider.getUsers().stream().filter(Objects::nonNull).map(u -> {
            if (u.getId() != null && !"".equals(u.getId())) {
                return u.getId();
            }
            return u.getEmail().toLowerCase();
        })).filter(Objects::nonNull).distinct().collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_PROVIDER")));
    } catch (Exception e) {
        logger.warn("There are no Provider entries in DB");
    }
    userRolesMap.putAll(Arrays.stream(epotAdmins.replace(" ", "").split(",")).map(String::toLowerCase).collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_EPOT"))));
    userRolesMap.putAll(Arrays.stream(admins.replace(" ", "").split(",")).map(String::toLowerCase).collect(Collectors.toMap(Function.identity(), a -> new SimpleGrantedAuthority("ROLE_ADMIN"))));
}
Also used : SecurityService(eu.einfracentral.service.SecurityService) java.util(java.util) Provider(eu.einfracentral.domain.Provider) Autowired(org.springframework.beans.factory.annotation.Autowired) PropertySource(org.springframework.context.annotation.PropertySource) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) UnauthorizedUserException(org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException) OIDCAuthoritiesMapper(org.mitre.openid.connect.client.OIDCAuthoritiesMapper) Function(java.util.function.Function) AuthoritiesMapper(eu.einfracentral.service.AuthoritiesMapper) ServiceException(eu.openminted.registry.core.service.ServiceException) Value(org.springframework.beans.factory.annotation.Value) JWT(com.nimbusds.jwt.JWT) ProviderService(eu.einfracentral.registry.service.ProviderService) UserInfo(org.mitre.openid.connect.model.UserInfo) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Collectors(java.util.stream.Collectors) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Component(org.springframework.stereotype.Component) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Logger(org.apache.logging.log4j.Logger) Stream(java.util.stream.Stream) PendingResourceService(eu.einfracentral.registry.service.PendingResourceService) Authentication(org.springframework.security.core.Authentication) LogManager(org.apache.logging.log4j.LogManager) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Stream(java.util.stream.Stream) UnauthorizedUserException(org.springframework.security.oauth2.common.exceptions.UnauthorizedUserException) ServiceException(eu.openminted.registry.core.service.ServiceException) Provider(eu.einfracentral.domain.Provider)

Example 2 with ProviderBundle

use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.

the class CSVController method providersToCSV.

// Downloads a csv file with Provider entries
@GetMapping(path = "providers", produces = { MediaType.APPLICATION_OCTET_STREAM_VALUE })
@PreAuthorize("hasRole('ROLE_ADMIN') or hasRole('ROLE_EPOT')")
public ResponseEntity<String> providersToCSV(@ApiIgnore Authentication auth, HttpServletResponse response) {
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    Paging<ProviderBundle> providers = providerService.getAll(ff, auth);
    String csvData = listProvidersToCSV(providers.getResults());
    response.setHeader("Content-disposition", "attachment; filename=" + "providers.csv");
    return ResponseEntity.ok(csvData);
}
Also used : FacetFilter(eu.openminted.registry.core.domain.FacetFilter) ProviderBundle(eu.einfracentral.domain.ProviderBundle) GetMapping(org.springframework.web.bind.annotation.GetMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 3 with ProviderBundle

use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.

the class PendingProviderController method temporarySavePending.

@PutMapping(path = "/pending", produces = { MediaType.APPLICATION_JSON_VALUE })
@PreAuthorize("hasRole('ROLE_USER')")
public ResponseEntity<Provider> temporarySavePending(@RequestBody Provider provider, @ApiIgnore Authentication auth) {
    ProviderBundle bundle = new ProviderBundle();
    if (provider.getId() == null || provider.getId().equals("")) {
        provider.setId(idCreator.createProviderId(provider));
    }
    try {
        bundle = pendingProviderService.get(provider.getId());
        bundle.setProvider(provider);
        bundle = pendingProviderService.update(bundle, auth);
    } catch (ResourceException e) {
        logger.debug("Pending Provider with id '{}' does not exist. Creating it...", provider.getId());
        bundle.setProvider(provider);
        bundle = pendingProviderService.add(bundle, auth);
    }
    return new ResponseEntity<>(bundle.getProvider(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ProviderBundle(eu.einfracentral.domain.ProviderBundle) ResourceException(eu.einfracentral.exception.ResourceException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 4 with ProviderBundle

use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.

the class OIDCSecurityService method providerIsActiveAndUserIsAdmin.

public boolean providerIsActiveAndUserIsAdmin(Authentication auth, String serviceId) {
    InfraService service = infraServiceService.get(serviceId);
    // List<String> providerIds = service.getService().getResourceProviders();
    // providerIds.add(service.getService().getResourceOrganisation());
    List<String> providerIds = Collections.singletonList(service.getService().getResourceOrganisation());
    for (String providerId : providerIds) {
        ProviderBundle provider = providerManager.get(providerId);
        if (provider != null && provider.isActive()) {
            if (isProviderAdmin(auth, providerId)) {
                return true;
            }
        }
    }
    return false;
}
Also used : InfraService(eu.einfracentral.domain.InfraService) ProviderBundle(eu.einfracentral.domain.ProviderBundle)

Example 5 with ProviderBundle

use of eu.einfracentral.domain.ProviderBundle in project resource-catalogue by madgeek-arc.

the class FacetLabelService method createLabels.

@SuppressWarnings("unchecked")
public List<Facet> createLabels(List<Facet> facets) {
    // unchecked warning here
    List<Facet> enrichedFacets = new TreeList();
    FacetFilter ff = new FacetFilter();
    ff.setQuantity(maxQuantity);
    // ff.addFilter("active", "true");
    Map<String, String> providerNames = providerService.getAll(ff, null).getResults().stream().collect(Collectors.toMap(ProviderBundle::getId, p -> p.getProvider().getName()));
    Map<String, Vocabulary> allVocabularies = vocabularyService.getVocabulariesMap();
    Facet superCategories;
    Facet categories;
    Facet scientificDomains;
    for (Facet facet : facets) {
        if (facet.getField().equals("subcategories")) {
            categories = createCategoriesFacet(facet);
            superCategories = createSupercategoriesFacet(categories);
            enrichedFacets.add(superCategories);
            enrichedFacets.add(categories);
        }
        if (facet.getField().equals("scientific_subdomains")) {
            scientificDomains = createScientificDomainsFacet(facet);
            enrichedFacets.add(scientificDomains);
        }
        for (Value value : facet.getValues()) {
            switch(facet.getField()) {
                case "resource_providers":
                case "resource_organisation":
                    value.setLabel(providerNames.get(value.getValue()));
                    break;
                default:
                    if (allVocabularies.containsKey(value.getValue())) {
                        value.setLabel(allVocabularies.get(value.getValue()).getName());
                    } else {
                        try {
                            value.setLabel(toProperCase(toProperCase(value.getValue(), "-", "-"), "_", " "));
                        } catch (StringIndexOutOfBoundsException e) {
                            logger.info(e);
                        }
                    }
            }
        }
    }
    enrichedFacets.addAll(facets);
    // Swap position according to front-ends needs
    try {
        Collections.swap(enrichedFacets, 4, 5);
    } catch (IndexOutOfBoundsException e) {
        logger.info(e);
    }
    return enrichedFacets;
}
Also used : java.util(java.util) ProviderService(eu.einfracentral.registry.service.ProviderService) Facet(eu.openminted.registry.core.domain.Facet) Autowired(org.springframework.beans.factory.annotation.Autowired) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Collectors(java.util.stream.Collectors) Vocabulary(eu.einfracentral.domain.Vocabulary) Value(eu.openminted.registry.core.domain.Value) Component(org.springframework.stereotype.Component) ProviderBundle(eu.einfracentral.domain.ProviderBundle) Logger(org.apache.logging.log4j.Logger) TreeList(org.apache.commons.collections.list.TreeList) Authentication(org.springframework.security.core.Authentication) VocabularyService(eu.einfracentral.registry.service.VocabularyService) LogManager(org.apache.logging.log4j.LogManager) Vocabulary(eu.einfracentral.domain.Vocabulary) FacetFilter(eu.openminted.registry.core.domain.FacetFilter) Value(eu.openminted.registry.core.domain.Value) TreeList(org.apache.commons.collections.list.TreeList) Facet(eu.openminted.registry.core.domain.Facet)

Aggregations

ProviderBundle (eu.einfracentral.domain.ProviderBundle)11 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 ResponseEntity (org.springframework.http.ResponseEntity)3 InfraService (eu.einfracentral.domain.InfraService)2 ProviderService (eu.einfracentral.registry.service.ProviderService)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 LogManager (org.apache.logging.log4j.LogManager)2 Logger (org.apache.logging.log4j.Logger)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 Async (org.springframework.scheduling.annotation.Async)2 Authentication (org.springframework.security.core.Authentication)2 Component (org.springframework.stereotype.Component)2 JWT (com.nimbusds.jwt.JWT)1 Provider (eu.einfracentral.domain.Provider)1 ProviderRequest (eu.einfracentral.domain.ProviderRequest)1 Vocabulary (eu.einfracentral.domain.Vocabulary)1 ResourceException (eu.einfracentral.exception.ResourceException)1 PendingResourceService (eu.einfracentral.registry.service.PendingResourceService)1