Search in sources :

Example 1 with Provider

use of eu.einfracentral.domain.Provider 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 Provider

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

the class AbstractSyncService method syncVerify.

@Override
public void syncVerify(T t) {
    boolean retryKey = true;
    if (active) {
        HttpEntity<T> request = new HttpEntity<>(t, createHeaders());
        URI uri;
        logger.info("Verifying resource with id: {} - Host: {}", t.getId(), host);
        try {
            if (t instanceof Provider) {
                uri = new URI(host + controller + "/verifyProvider/" + t.getId() + "?active=true&status=approved%20provider").normalize();
            } else {
                uri = new URI(host + controller + "/verifyResource/" + t.getId() + "?active=true&status=approved%20resource").normalize();
            }
            HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
            restTemplate.setRequestFactory(requestFactory);
            ResponseEntity<?> re = restTemplate.exchange(uri.normalize(), HttpMethod.PATCH, request, t.getClass());
            if (re.getStatusCode() != HttpStatus.OK) {
                logger.error("Verifying {} with id '{}' from host '{}' returned code '{}'\nResponse body:\n{}", t.getClass(), t.getId(), host, re.getStatusCodeValue(), re.getBody());
            } else {
                retryKey = false;
            }
        } catch (URISyntaxException e) {
            logger.error("could not create URI for host: {}", host, e);
        } catch (HttpServerErrorException e) {
            logger.error("Failed to patch {} with id {} to host {}\nMessage: {}", t.getClass(), t.getId(), host, e.getResponseBodyAsString());
        } catch (RuntimeException re) {
            logger.error("syncVerify failed, check if token has expired!\n{}: {}", t.getClass(), t, re);
        }
        if (retryKey) {
            try {
                queue.add(Pair.with(t, "verify"));
            } catch (IllegalStateException e) {
                logger.info("No space is currently available in the Queue");
            }
        }
    }
}
Also used : HttpComponentsClientHttpRequestFactory(org.springframework.http.client.HttpComponentsClientHttpRequestFactory) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) HttpServerErrorException(org.springframework.web.client.HttpServerErrorException) Provider(eu.einfracentral.domain.Provider)

Aggregations

Provider (eu.einfracentral.domain.Provider)2 JWT (com.nimbusds.jwt.JWT)1 ProviderBundle (eu.einfracentral.domain.ProviderBundle)1 PendingResourceService (eu.einfracentral.registry.service.PendingResourceService)1 ProviderService (eu.einfracentral.registry.service.ProviderService)1 AuthoritiesMapper (eu.einfracentral.service.AuthoritiesMapper)1 SecurityService (eu.einfracentral.service.SecurityService)1 FacetFilter (eu.openminted.registry.core.domain.FacetFilter)1 ServiceException (eu.openminted.registry.core.service.ServiceException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 java.util (java.util)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 OIDCAuthoritiesMapper (org.mitre.openid.connect.client.OIDCAuthoritiesMapper)1 UserInfo (org.mitre.openid.connect.model.UserInfo)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1