001/*-
002 * #%L
003 * HAPI FHIR - Server Framework
004 * %%
005 * Copyright (C) 2014 - 2024 Smile CDR, Inc.
006 * %%
007 * Licensed under the Apache License, Version 2.0 (the "License");
008 * you may not use this file except in compliance with the License.
009 * You may obtain a copy of the License at
010 *
011 *      http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 * #L%
019 */
020package ca.uhn.fhir.rest.server.tenant;
021
022import ca.uhn.fhir.rest.api.server.RequestDetails;
023import ca.uhn.fhir.util.UrlPathTokenizer;
024
025public interface ITenantIdentificationStrategy {
026
027        /**
028         * Implementations should use this method to determine the tenant ID
029         * based on the incoming request and populate it in the
030         * {@link RequestDetails#setTenantId(String)}.
031         *
032         * @param theUrlPathTokenizer The tokenizer which is used to parse the request path
033         * @param theRequestDetails   The request details object which can be used to access headers and to populate the tenant ID to
034         */
035        void extractTenant(UrlPathTokenizer theUrlPathTokenizer, RequestDetails theRequestDetails);
036
037        /**
038         * Implementations may use this method to tweak the server base URL
039         * if necessary based on the tenant ID
040         */
041        String massageServerBaseUrl(String theFhirServerBase, RequestDetails theRequestDetails);
042
043        /**
044         * Implementations may use this method to resolve relative URL based on the tenant ID from RequestDetails.
045         *
046         * @param theRelativeUrl    URL that only includes the path, e.g. "Patient/123"
047         * @param theRequestDetails The request details object which can be used to access tenant ID
048         * @return Resolved relative URL that starts with tenant ID (if tenant ID present in RequestDetails). Example: "TENANT-A/Patient/123".
049         */
050        String resolveRelativeUrl(String theRelativeUrl, RequestDetails theRequestDetails);
051}