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