diff --git a/src/main/java/eu/h2020/symbiote/client/AbstractSymbIoTeClientFactory.java b/src/main/java/eu/h2020/symbiote/client/AbstractSymbIoTeClientFactory.java index 7ba5f07..6b4eb7e 100644 --- a/src/main/java/eu/h2020/symbiote/client/AbstractSymbIoTeClientFactory.java +++ b/src/main/java/eu/h2020/symbiote/client/AbstractSymbIoTeClientFactory.java @@ -48,6 +48,61 @@ public static AbstractSymbIoTeClientFactory getFactory(Config config) public abstract IAAMClient getAAMClient(); + /** + * Get a configuration for home token symbIoTeClient factory. In this configuration, getting guest token is also possible + * + * @param coreAddress the base address of the symbIoTe core + * @param keystorePath the keystore path + * @param keystorePassword the keystore password + * @param type the type of factory + * @return the factory configuration + */ + public static Config getGuestTokenConfiguration(String coreAddress, String keystorePath, String keystorePassword, Type type) { + return new Config( + coreAddress, + keystorePath, + keystorePassword, + null, + null, + null, + null, + type + ); + } + + /** + * Get a configuration for guest token symbIoTeClient factory. In this configuration, getting home token is not possible + * + * @param coreAddress the base address of the symbIoTe core + * @param keystorePath the keystore path + * @param keystorePassword the keystore password + * @param homePlatformId the home Platform Id + * @param username the username in the home platform + * @param password the password in the home platform + * @param clientId the client id + * @param type the type of factory + * @return the factory configuration + */ + public static Config getHomeTokenConfiguration(String coreAddress, + String keystorePath, + String keystorePassword, + String homePlatformId, + String username, + String password, + String clientId, + Type type) { + return new Config( + coreAddress, + keystorePath, + keystorePassword, + homePlatformId, + username, + password, + clientId, + type + ); + } + /** * The type of factory. For now there is just one type but we followed the abstract factory pattern to facilitate * future extension diff --git a/src/main/java/eu/h2020/symbiote/client/feign/FeignCRAMClient.java b/src/main/java/eu/h2020/symbiote/client/feign/FeignCRAMClient.java index 43bd69c..0282137 100644 --- a/src/main/java/eu/h2020/symbiote/client/feign/FeignCRAMClient.java +++ b/src/main/java/eu/h2020/symbiote/client/feign/FeignCRAMClient.java @@ -29,7 +29,9 @@ public class FeignCRAMClient implements CRAMClient { private static final String GET_RESOURCE_URLS_BASE_PATH = CORE_INTERFACE_PATH + "/resourceUrls?"; private final CRAMI cramClient; + private final CRAMI cramClientAsGuest; private final CRAMI cramClientWithoutValidation; + private final CRAMI cramClientAsGuestWithoutValidation; /** * @@ -63,6 +65,18 @@ public FeignCRAMClient(ISecurityHandler securityHandler, true)) .target(CRAMI.class, coreAddress); + this.cramClientAsGuest = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.CORE_RESOURCE_ACCESS_MONITOR, + SecurityConstants.CORE_AAM_INSTANCE_ID, + true)) + .target(CRAMI.class, coreAddress); + this.cramClientWithoutValidation = Feign.builder() .decoder(new JacksonDecoder()) .encoder(new JacksonEncoder()) @@ -79,26 +93,46 @@ public FeignCRAMClient(ISecurityHandler securityHandler, false)) .target(CRAMI.class, coreAddress); + this.cramClientAsGuestWithoutValidation = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.CORE_RESOURCE_ACCESS_MONITOR, + SecurityConstants.CORE_AAM_INSTANCE_ID, + false)) + .target(CRAMI.class, coreAddress); + } @Override - public ResourceUrlsResponse getResourceUrl(String resourceId) { - return cramClient.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))); + public ResourceUrlsResponse getResourceUrl(String resourceId, boolean serverValidation) { + return serverValidation ? + cramClient.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))) : + cramClientWithoutValidation.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))); } @Override - public ResourceUrlsResponse getResourceUrl(List resourceIds) { - return cramClient.getResourceUrls(resourceIds); + public ResourceUrlsResponse getResourceUrl(List resourceIds, boolean serverValidation) { + return serverValidation ? + cramClient.getResourceUrls(resourceIds) : + cramClientWithoutValidation.getResourceUrls(resourceIds); } @Override - public ResourceUrlsResponse getResourceUrlWithoutValidation(String resourceId) { - return cramClientWithoutValidation.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))); + public ResourceUrlsResponse getResourceUrlAsGuest(String resourceId, boolean serverValidation) { + return serverValidation ? + cramClientAsGuest.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))) : + cramClientAsGuestWithoutValidation.getResourceUrls(new ArrayList<>(Collections.singleton(resourceId))); } @Override - public ResourceUrlsResponse getResourceUrlWithoutValidation(List resourceIds) { - return cramClientWithoutValidation.getResourceUrls(resourceIds); + public ResourceUrlsResponse getResourceUrlAsGuest(List resourceIds, boolean serverValidation) { + return serverValidation ? + cramClientAsGuest.getResourceUrls(resourceIds) : + cramClientAsGuestWithoutValidation.getResourceUrls(resourceIds); } private interface CRAMI { diff --git a/src/main/java/eu/h2020/symbiote/client/feign/FeignPRClient.java b/src/main/java/eu/h2020/symbiote/client/feign/FeignPRClient.java index ae27538..955acc0 100644 --- a/src/main/java/eu/h2020/symbiote/client/feign/FeignPRClient.java +++ b/src/main/java/eu/h2020/symbiote/client/feign/FeignPRClient.java @@ -26,7 +26,9 @@ public class FeignPRClient implements PRClient { private static final Log logger = LogFactory.getLog(FeignPRClient.class); private PlatformRegistryI prClient; + private PlatformRegistryI prClientAsGuest; private PlatformRegistryI prClientWithoutValidation; + private PlatformRegistryI prClientAsGuestWithoutValidation; /** * @@ -62,6 +64,18 @@ public FeignPRClient(ISecurityHandler securityHandler, true)) .target(PlatformRegistryI.class, prUrl); + this.prClientAsGuest = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.PLATFORM_REGISTRY, + homePlatformId, + true)) + .target(PlatformRegistryI.class, prUrl); + this.prClientWithoutValidation = Feign.builder() .decoder(new JacksonDecoder()) .encoder(new JacksonEncoder()) @@ -77,6 +91,18 @@ public FeignPRClient(ISecurityHandler securityHandler, homePlatformId, false)) .target(PlatformRegistryI.class, prUrl); + + this.prClientAsGuestWithoutValidation = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.PLATFORM_REGISTRY, + homePlatformId, + false)) + .target(PlatformRegistryI.class, prUrl); } catch (SecurityHandlerException e) { logger.error("Could not create FeignPRClient", e); } @@ -84,13 +110,17 @@ public FeignPRClient(ISecurityHandler securityHandler, } @Override - public FederationSearchResult search(PlatformRegistryQuery query) { - return prClient.query(query.buildRequestParametersMap()); + public FederationSearchResult search(PlatformRegistryQuery query, boolean serverValidation) { + return serverValidation ? + prClient.query(query.buildRequestParametersMap()) : + prClientWithoutValidation.query(query.buildRequestParametersMap()); } @Override - public FederationSearchResult searchWithoutValidation(PlatformRegistryQuery query) { - return prClientWithoutValidation.query(query.buildRequestParametersMap()); + public FederationSearchResult searchAsGuest(PlatformRegistryQuery query, boolean serverValidation) { + return serverValidation ? + prClientAsGuest.query(query.buildRequestParametersMap()) : + prClientAsGuestWithoutValidation.query(query.buildRequestParametersMap()); } private interface PlatformRegistryI { diff --git a/src/main/java/eu/h2020/symbiote/client/feign/FeignRAPClient.java b/src/main/java/eu/h2020/symbiote/client/feign/FeignRAPClient.java index 876342d..9be7640 100644 --- a/src/main/java/eu/h2020/symbiote/client/feign/FeignRAPClient.java +++ b/src/main/java/eu/h2020/symbiote/client/feign/FeignRAPClient.java @@ -3,7 +3,9 @@ import eu.h2020.symbiote.client.interfaces.RAPClient; import eu.h2020.symbiote.model.cim.Observation; import eu.h2020.symbiote.security.commons.ComponentIdentifiers; +import eu.h2020.symbiote.security.commons.exceptions.custom.SecurityHandlerException; import eu.h2020.symbiote.security.communication.ApacheCommonsLogger4Feign; +import eu.h2020.symbiote.security.communication.payloads.AAM; import eu.h2020.symbiote.security.handler.ISecurityHandler; import feign.*; import feign.jackson.JacksonDecoder; @@ -12,6 +14,7 @@ import org.apache.commons.logging.LogFactory; import java.util.List; +import java.util.stream.Collectors; /** * symbIoTe RAP client based on Feign @@ -51,43 +54,81 @@ public FeignRAPClient(ISecurityHandler securityHandler, } @Override - public Observation getLatestObservation(String resourceUrl, String targetPlatformId) { - return getClient(resourceUrl, targetPlatformId).getTopObservations(1).get(0); + public Observation getLatestObservation(String resourceUrl, boolean serverValidation) { + try { + return getClient(resourceUrl, serverValidation).getTopObservations(1).get(0); + } catch (SecurityHandlerException e) { + logger.error("Could not get latest Observation", e); + return null; + } } @Override - public List getTopObservations(String resourceUrl, int top, String targetPlatformId) { - return getClient(resourceUrl, targetPlatformId).getTopObservations(top); + public List getTopObservations(String resourceUrl, int top, boolean serverValidation) { + try { + return getClient(resourceUrl, serverValidation).getTopObservations(top); + } catch (SecurityHandlerException e) { + logger.error("Could not get Observations", e); + return null; + } } @Override - public void actuate(String resourceUrl, String body, String targetPlatformId) { - getClient(resourceUrl, targetPlatformId).actuate(body); + public void actuate(String resourceUrl, String body, boolean serverValidation) { + try { + getClient(resourceUrl, serverValidation).actuate(body); + } catch (SecurityHandlerException e) { + logger.error("Could not send actuation request", e); + } } @Override - public String invokeService(String resourceUrl, String body, String targetPlatformId) { - return getClient(resourceUrl, targetPlatformId).invokeService(body); + public String invokeService(String resourceUrl, String body, boolean serverValidation) { + try { + return getClient(resourceUrl, serverValidation).invokeService(body); + } catch (SecurityHandlerException e) { + logger.error("Could not invoke service", e); + return "Could not invoke service : " + e.getMessage(); + } } @Override - public Observation getLatestObservationWithoutValidation(String resourceUrl) { - return getClientWithoutValidation(resourceUrl).getTopObservations(1).get(0); + public Observation getLatestObservationAsGuest(String resourceUrl, boolean serverValidation) { + try { + return getGuestClient(resourceUrl, serverValidation).getTopObservations(1).get(0); + } catch (SecurityHandlerException e) { + logger.error("Could not get latest Observation", e); + return null; + } } @Override - public List getTopObservationsWithoutValidation(String resourceUrl, int top) { - return getClientWithoutValidation(resourceUrl).getTopObservations(top); + public List getTopObservationsAsGuest(String resourceUrl, int top, boolean serverValidation) { + try { + return getGuestClient(resourceUrl, serverValidation).getTopObservations(top); + } catch (SecurityHandlerException e) { + logger.error("Could not get Observations", e); + return null; + } } @Override - public void actuateWithoutValidation(String resourceUrl, String body) { - getClientWithoutValidation(resourceUrl).actuate(body); + public void actuateAsGuest(String resourceUrl, String body, boolean serverValidation) { + try { + getGuestClient(resourceUrl, serverValidation).actuate(body); + } catch (SecurityHandlerException e) { + logger.error("Could not send actuation request", e); + } } @Override - public String invokeServiceWithoutValidation(String resourceUrl, String body) { - return getClientWithoutValidation(resourceUrl).invokeService(body); + public String invokeServiceAsGuest(String resourceUrl, String body, boolean serverValidation) { + try { + return getGuestClient(resourceUrl, serverValidation).invokeService(body); + } catch (SecurityHandlerException e) { + logger.error("Could not invoke service", e); + return "Could not invoke service : " + e.getMessage(); + } } private interface RAPI { @@ -107,7 +148,10 @@ private interface RAPI { String invokeService(@Param("body") String body); } - private RAPI getClient(String resourceUrl, String targetPlatformId) { + private RAPI getClient(String resourceUrl, boolean serverValidation) throws SecurityHandlerException { + + List filteredAAMs = findAAMS(resourceUrl); + return Feign.builder() .decoder(new JacksonDecoder()) .encoder(new JacksonEncoder()) @@ -120,12 +164,15 @@ private RAPI getClient(String resourceUrl, String targetPlatformId) { password, clientId, ComponentIdentifiers.RESOURCE_ACCESS_PROXY, - targetPlatformId, - true)) + filteredAAMs.get(0).getAamInstanceId(), + serverValidation)) .target(RAPI.class, resourceUrl); } - private RAPI getClientWithoutValidation(String resourceUrl) { + private RAPI getGuestClient(String resourceUrl, boolean serverValidation) throws SecurityHandlerException { + + List filteredAAMs = findAAMS(resourceUrl); + return Feign.builder() .decoder(new JacksonDecoder()) .encoder(new JacksonEncoder()) @@ -133,13 +180,24 @@ private RAPI getClientWithoutValidation(String resourceUrl) { .logLevel(Logger.Level.FULL) .client(new SymbIoTeSecurityHandlerFeignClient( securityHandler, - homePlatformId, - username, - password, - clientId, ComponentIdentifiers.RESOURCE_ACCESS_PROXY, - "", - false)) + filteredAAMs.get(0).getAamInstanceId(), + serverValidation)) .target(RAPI.class, resourceUrl); } + + private List findAAMS(String resourceUrl) throws SecurityHandlerException { + String aamUrl = resourceUrl.replaceAll("/rap.*", "/paam"); + List filteredAAMs; + + filteredAAMs = securityHandler.getAvailableAAMs().values().stream() + .filter(aam -> aam.getAamAddress().equals(aamUrl)) + .collect(Collectors.toList()); + + if (filteredAAMs.size() != 1) { + throw new SecurityHandlerException(String.format("Found %d possible targets instead of only 1", filteredAAMs.size())); + } + + return filteredAAMs; + } } diff --git a/src/main/java/eu/h2020/symbiote/client/feign/FeignSearchClient.java b/src/main/java/eu/h2020/symbiote/client/feign/FeignSearchClient.java index 8f094b5..a1853ea 100644 --- a/src/main/java/eu/h2020/symbiote/client/feign/FeignSearchClient.java +++ b/src/main/java/eu/h2020/symbiote/client/feign/FeignSearchClient.java @@ -29,6 +29,8 @@ public class FeignSearchClient implements SearchClient { private final SearchI searchClient; private final SearchI searchClientWithoutValidation; + private final SearchI searchClientAsGuest; + private final SearchI searchClientAsGuestWithoutValidation; /** * @@ -78,16 +80,44 @@ public FeignSearchClient(ISecurityHandler securityHandler, false)) .target(SearchI.class, coreAddress); + this.searchClientAsGuest = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.CORE_SEARCH, + SecurityConstants.CORE_AAM_INSTANCE_ID, + true)) + .target(SearchI.class, coreAddress); + + this.searchClientAsGuestWithoutValidation = Feign.builder() + .decoder(new JacksonDecoder()) + .encoder(new JacksonEncoder()) + .logger(new ApacheCommonsLogger4Feign(logger)) + .logLevel(Logger.Level.FULL) + .client(new SymbIoTeSecurityHandlerFeignClient( + securityHandler, + ComponentIdentifiers.CORE_SEARCH, + SecurityConstants.CORE_AAM_INSTANCE_ID, + false)) + .target(SearchI.class, coreAddress); + } @Override - public QueryResponse search(CoreQueryRequest request) { - return searchClient.query(request.buildRequestParametersMap()); + public QueryResponse search(CoreQueryRequest request, boolean serverValidation) { + return serverValidation ? + searchClient.query(request.buildRequestParametersMap()) : + searchClientWithoutValidation.query(request.buildRequestParametersMap()); } @Override - public QueryResponse searchWithoutValidation(CoreQueryRequest request) { - return searchClientWithoutValidation.query(request.buildRequestParametersMap()); + public QueryResponse searchAsGuest(CoreQueryRequest request, boolean serverValidation) { + return serverValidation ? + searchClientWithoutValidation.query(request.buildRequestParametersMap()) : + searchClientAsGuestWithoutValidation.query(request.buildRequestParametersMap()); } private interface SearchI { diff --git a/src/main/java/eu/h2020/symbiote/client/feign/SymbIoTeSecurityHandlerFeignClient.java b/src/main/java/eu/h2020/symbiote/client/feign/SymbIoTeSecurityHandlerFeignClient.java index 10710b0..a95aa1b 100644 --- a/src/main/java/eu/h2020/symbiote/client/feign/SymbIoTeSecurityHandlerFeignClient.java +++ b/src/main/java/eu/h2020/symbiote/client/feign/SymbIoTeSecurityHandlerFeignClient.java @@ -39,23 +39,9 @@ public class SymbIoTeSecurityHandlerFeignClient implements Client { private final boolean validateResponse; private final Client client = new Client.Default(null, null); - /** - * Constructor for creating a security-disabled client - */ - public SymbIoTeSecurityHandlerFeignClient() { - this.securityHandler = null; - this.homePlatformId = null; - this.username = null; - this.password = null; - this.clientId = null; - this.serviceComponentId = null; - this.servicePlatformId = null; - this.validateResponse = false; - } - /** - * Constructor for creating a security-enabled client + * Constructor for creating a security-enabled client with HOME Token * * @param securityHandler configured for this component * @param homePlatformId the home Platform Id @@ -85,6 +71,28 @@ public SymbIoTeSecurityHandlerFeignClient(ISecurityHandler securityHandler, this.validateResponse = validateResponse; } + /** + * Constructor for creating a security-disabled client + */ + public SymbIoTeSecurityHandlerFeignClient() { + this(null, null, null, null, null, null, null, false); + } + + /** + * Constructor for creating a security-enabled client with GUEST Token + * + * @param securityHandler configured for this component + * @param serviceComponentId id of the component this client is used to communicate with ({@link ComponentIdentifiers}) + * @param servicePlatformId id of the platform which the component belongs to ({@link SecurityConstants#CORE_AAM_INSTANCE_ID} + * for Symbiote core components) + * @param validateResponse indicated if the component will be validated + */ + public SymbIoTeSecurityHandlerFeignClient(ISecurityHandler securityHandler, + String serviceComponentId, + String servicePlatformId, + boolean validateResponse) { + this(securityHandler, null, null, null, null, serviceComponentId, servicePlatformId, validateResponse); + } @Override public Response execute(Request request, Request.Options options) throws IOException { @@ -94,24 +102,39 @@ public Response execute(Request request, Request.Options options) throws IOExcep try { if (securityHandler != null) { + SecurityRequest securityRequest; + // Get the available AAMs from the Core AAM Map availableAAMs = securityHandler.getAvailableAAMs(); - // Acquiring application certificate - securityHandler.getCertificate(availableAAMs.get(homePlatformId), username, password, clientId); + if (homePlatformId == null || username == null || password == null || clientId == null) { + // Operate with GUEST Token from Core AAM + + // Acquiring GUEST token + Token guestToken = securityHandler.loginAsGuest(availableAAMs.get(SecurityConstants.CORE_AAM_INSTANCE_ID)); + + // Create Security Request with GUEST Token + securityRequest = new SecurityRequest(guestToken.getToken()); - // Acquiring HOME token - Token homeToken = securityHandler.login(availableAAMs.get(homePlatformId)); + } else { + // Operate with HOME Token + + // Acquiring application certificate + securityHandler.getCertificate(availableAAMs.get(homePlatformId), username, password, clientId); - // Acquiring HOME credentials - HomeCredentials homeCredentials = securityHandler.getAcquiredCredentials().get(homePlatformId).homeCredentials; + // Acquiring HOME token + Token homeToken = securityHandler.login(availableAAMs.get(homePlatformId)); - // Populate the authorization credentials. From now on we do not need the password - Set authorizationCredentialsSet = new HashSet<>(); - authorizationCredentialsSet.add(new AuthorizationCredentials(homeToken, homeCredentials.homeAAM, homeCredentials)); + // Acquiring HOME credentials + HomeCredentials homeCredentials = securityHandler.getAcquiredCredentials().get(homePlatformId).homeCredentials; - // Create Security Request - SecurityRequest securityRequest = MutualAuthenticationHelper.getSecurityRequest(authorizationCredentialsSet, false); + // Populate the authorization credentials. From now on we do not need the password + Set authorizationCredentialsSet = new HashSet<>(); + authorizationCredentialsSet.add(new AuthorizationCredentials(homeToken, homeCredentials.homeAAM, homeCredentials)); + + // Create Security Request with HOME Token + securityRequest = MutualAuthenticationHelper.getSecurityRequest(authorizationCredentialsSet, false); + } // Insert it to the headers diff --git a/src/main/java/eu/h2020/symbiote/client/interfaces/CRAMClient.java b/src/main/java/eu/h2020/symbiote/client/interfaces/CRAMClient.java index c9ee582..77b3944 100644 --- a/src/main/java/eu/h2020/symbiote/client/interfaces/CRAMClient.java +++ b/src/main/java/eu/h2020/symbiote/client/interfaces/CRAMClient.java @@ -5,41 +5,45 @@ import java.util.List; /** - * Interface for querying the Core Resource Access Manager component + * Interface for querying the Core Resource Access Manager (CRAM) component * * @author Vasilis Glykantzis */ public interface CRAMClient { /** - * Queries and validates the Core Resource Access Manager component + * Queries CRAM with home token for getting the url of a single resource * - * @param resourceId the id of the resource - * @return the Core Resource Access Manager response + * @param resourceId the id of the resource + * @param serverValidation if true it will validate CRAM + * @return the CRAM response */ - ResourceUrlsResponse getResourceUrl(String resourceId); + ResourceUrlsResponse getResourceUrl(String resourceId, boolean serverValidation); /** - * Queries and validates the Core Resource Access Manager component + * Queries CRAM with home token for getting the urls of a list of resources * - * @param resourceIds a list containing the ids of the resources - * @return the Core Resource Access Manager response + * @param resourceIds a list containing the ids of the resources + * @param serverValidation if true it will validate CRAM + * @return the CRAM response */ - ResourceUrlsResponse getResourceUrl(List resourceIds); + ResourceUrlsResponse getResourceUrl(List resourceIds, boolean serverValidation); /** - * Queries the Core Resource Access Manager component component without validating it + * Queries CRAM with guest token for getting the url of a single resource * - * @param resourceId the id of the resource - * @return the Core Resource Access Manager response + * @param resourceId the id of the resource + * @param serverValidation if true it will validate CRAM + * @return the CRAM response */ - ResourceUrlsResponse getResourceUrlWithoutValidation(String resourceId); + ResourceUrlsResponse getResourceUrlAsGuest(String resourceId, boolean serverValidation); /** - * Queries the Core Resource Access Manager component component without validating it + * Queries CRAM with guest token for getting the urls of a list of resources * - * @param resourceIds a list containing the ids of the resources - * @return the Core Resource Access Manager response + * @param resourceIds a list containing the ids of the resources + * @param serverValidation if true it will validate CRAM + * @return the CRAM response */ - ResourceUrlsResponse getResourceUrlWithoutValidation(List resourceIds); + ResourceUrlsResponse getResourceUrlAsGuest(List resourceIds, boolean serverValidation); } diff --git a/src/main/java/eu/h2020/symbiote/client/interfaces/PRClient.java b/src/main/java/eu/h2020/symbiote/client/interfaces/PRClient.java index b48bb96..3b9641d 100644 --- a/src/main/java/eu/h2020/symbiote/client/interfaces/PRClient.java +++ b/src/main/java/eu/h2020/symbiote/client/interfaces/PRClient.java @@ -11,19 +11,21 @@ public interface PRClient { /** - * Queries and validates the Platform Registry component + * Queries the Platform Registry component with home token * - * @param query the request send to the Platform Registry - * @return the search response + * @param query the request send to the Platform Registry + * @param serverValidation if true it will validate the Platform Registry Component + * @return the search result */ - FederationSearchResult search(PlatformRegistryQuery query); + FederationSearchResult search(PlatformRegistryQuery query, boolean serverValidation); /** - * Queries the Platform Registry component without validating it + * Queries the Platform Registry component with guest token * - * @param query the request send to the Platform Registry - * @return the search response + * @param query the request send to the Platform Registry + * @param serverValidation if true it will validate the Platform Registry Component + * @return the search result */ - FederationSearchResult searchWithoutValidation(PlatformRegistryQuery query); + FederationSearchResult searchAsGuest(PlatformRegistryQuery query, boolean serverValidation); } diff --git a/src/main/java/eu/h2020/symbiote/client/interfaces/RAPClient.java b/src/main/java/eu/h2020/symbiote/client/interfaces/RAPClient.java index 0db8525..bca9b82 100644 --- a/src/main/java/eu/h2020/symbiote/client/interfaces/RAPClient.java +++ b/src/main/java/eu/h2020/symbiote/client/interfaces/RAPClient.java @@ -5,7 +5,7 @@ import java.util.List; /** - * Interface for querying the Platform Resource Access Proxy component + * Interface for querying the Platform Resource Access Proxy (RAP) component * * @author Vasilis Glykantzis */ @@ -15,70 +15,74 @@ public interface RAPClient { * Get the latest observation * * @param resourceUrl the resource url - * @param targetPlatformId the id of the platform owning the resource; used for validation + * @param serverValidation if true it will validate RAP * @return an {@link Observation} */ - Observation getLatestObservation(String resourceUrl, String targetPlatformId); + Observation getLatestObservation(String resourceUrl, boolean serverValidation); /** * Get the latest top observations * * @param resourceUrl the resource url * @param top the number of observations - * @param targetPlatformId the id of the platform owning the resource; used for validation + * @param serverValidation if true it will validate RAP * @return a list of {@link Observation} */ - List getTopObservations(String resourceUrl, int top, String targetPlatformId); + List getTopObservations(String resourceUrl, int top, boolean serverValidation); /** * Send actuation request * * @param resourceUrl the resource url * @param body the message that will be sent - * @param targetPlatformId the id of the platform owning the resource; used for validation + * @param serverValidation if true it will validate RAP */ - void actuate(String resourceUrl, String body, String targetPlatformId); + void actuate(String resourceUrl, String body, boolean serverValidation); /** * Invoke Service * * @param resourceUrl the resource url * @param body the message that will be sent - * @param targetPlatformId the id of the platform owning the resource; used for validation + * @param serverValidation if true it will validate RAP * @return a response of the service invocation in json format */ - String invokeService(String resourceUrl, String body, String targetPlatformId); + String invokeService(String resourceUrl, String body, boolean serverValidation); /** * Get the latest observation without validating RAP * * @param resourceUrl the resource url + * @param serverValidation if true it will validate RAP * @return an {@link Observation} */ - Observation getLatestObservationWithoutValidation(String resourceUrl); + Observation getLatestObservationAsGuest(String resourceUrl, boolean serverValidation); /** * Get the latest top observations without validating RAP * * @param resourceUrl the resource url * @param top the number of observations + * @param serverValidation if true it will validate RAP * @return a list of {@link Observation} */ - List getTopObservationsWithoutValidation(String resourceUrl, int top); + List getTopObservationsAsGuest(String resourceUrl, int top, boolean serverValidation); /** * Send actuation request without validating RAP * * @param resourceUrl the resource url * @param body the message that will be sent + * @param serverValidation if true it will validate RAP */ - void actuateWithoutValidation(String resourceUrl, String body); + void actuateAsGuest(String resourceUrl, String body, boolean serverValidation); /** * Invoke Service without validating RAP * * @param resourceUrl the resource url * @param body the message that will be sent + * @param serverValidation if true it will validate RAP */ - String invokeServiceWithoutValidation(String resourceUrl, String body); + String invokeServiceAsGuest(String resourceUrl, String body, boolean serverValidation); } diff --git a/src/main/java/eu/h2020/symbiote/client/interfaces/SearchClient.java b/src/main/java/eu/h2020/symbiote/client/interfaces/SearchClient.java index a2b9003..9dbc40c 100644 --- a/src/main/java/eu/h2020/symbiote/client/interfaces/SearchClient.java +++ b/src/main/java/eu/h2020/symbiote/client/interfaces/SearchClient.java @@ -11,18 +11,20 @@ public interface SearchClient { /** - * Queries and validates the Core Search component + * Queries the Core Search with home token * - * @param request the request send to the Search - * @return the search response + * @param request the request sent to the Search + * @param serverValidation if true it will validate the Search Component + * @return the search response */ - QueryResponse search(CoreQueryRequest request); + QueryResponse search(CoreQueryRequest request, boolean serverValidation); /** - * Queries the Core Search component without validating it + * Queries the Core Search with guest token * - * @param request the request send to the Search - * @return the search response + * @param request the request send to the Search + * @param serverValidation if true it will validate the Search Component + * @return the search response */ - QueryResponse searchWithoutValidation(CoreQueryRequest request); + QueryResponse searchAsGuest(CoreQueryRequest request, boolean serverValidation); }