001package ca.cdr.api.security; 002 003import ca.cdr.api.annotations.CdrPublicAPI; 004import ca.uhn.fhir.rest.client.api.IClientInterceptor; 005 006/** 007 * Factory class for creating and configuring instances of {@link ClientAuthInterceptor}. 008 */ 009@CdrPublicAPI 010public class ClientAuthInterceptorFactory { 011 012 private static IClientAuthSelector ourIClientAuthSelector; 013 014 /** 015 * Creates an instance of {@link IClientInterceptor} initialized with the given client authentication state. 016 * 017 * @param theClientAuthParams The {@link ClientAuthParams} object containing the parameters 018 * to be used for configuring the interceptor. 019 * @return An instance of {@link IClientInterceptor} configured from the provided parameters. 020 */ 021 public static IClientInterceptor create(ClientAuthParams theClientAuthParams) { 022 if (ourIClientAuthSelector == null) { 023 throw new IllegalStateException("IClientAuthSelector was not set"); 024 } 025 ClientAuthState clientAuthState = new ClientAuthState(theClientAuthParams); 026 return new ClientAuthInterceptor(ourIClientAuthSelector, clientAuthState); 027 } 028 029 public static void setClientAuthSelector(IClientAuthSelector theClientAuthSelector) { 030 ourIClientAuthSelector = theClientAuthSelector; 031 } 032}