
001/*- 002 * #%L 003 * HAPI FHIR - Server Framework 004 * %% 005 * Copyright (C) 2014 - 2023 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.interceptor.auth; 021 022import org.hl7.fhir.instance.model.api.IBaseResource; 023 024import javax.annotation.Nonnull; 025import javax.annotation.Nullable; 026 027/** 028 * Adapt the InMemoryMatcher to support authorization filters in {@link FhirQueryRuleTester}. 029 * Exists because filters may be applied to resources that don't support all paramters, and UNSUPPORTED 030 * has a different meaning during authorization. 031 */ 032public interface IAuthorizationSearchParamMatcher { 033 /** 034 * Calculate if the resource would match the fhir query parameters. 035 * @param theQueryParameters e.g. "category=laboratory" 036 * @param theResource the target of the comparison 037 */ 038 MatchResult match(String theQueryParameters, IBaseResource theResource); 039 040 /** 041 * Match outcomes. 042 */ 043 enum Match { 044 MATCH, 045 NO_MATCH, 046 /** Used for contexts without matcher infrastructure like hybrid providers */ 047 UNSUPPORTED 048 } 049 050 class MatchResult { 051 // fake record pattern 052 /** match result */ 053 @Nonnull public final Match match; 054 /** the reason for the UNSUPPORTED result */ 055 @Nullable public final String unsupportedReason; 056 057 public static MatchResult buildMatched() { 058 return new MatchResult(Match.MATCH, null); 059 } 060 061 public static MatchResult buildUnmatched() { 062 return new MatchResult(Match.NO_MATCH, null); 063 } 064 065 public static MatchResult buildUnsupported(@Nonnull String theReason) { 066 return new MatchResult(Match.UNSUPPORTED, theReason); 067 } 068 069 private MatchResult(Match myMatch, String myUnsupportedReason) { 070 this.match = myMatch; 071 this.unsupportedReason = myUnsupportedReason; 072 } 073 074 } 075}