1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 package org.apache.hc.client5.http.auth; 28 29 import org.apache.hc.core5.http.HttpHost; 30 31 /** 32 * This interface represents an cache of {@link AuthScheme} state information 33 * that can be re-used for preemptive authentication by subsequent requests. 34 * 35 * @since 4.1 36 */ 37 public interface AuthCache { 38 39 /** 40 * Stores the authentication state with the given authentication scope in the cache. 41 * 42 * @param host the authentication authority. 43 * @param authScheme the cacheable authentication state. 44 */ 45 void put(HttpHost host, AuthScheme authScheme); 46 47 /** 48 * Returns the authentication state with the given authentication scope from the cache 49 * if available. 50 * 51 * @param host the authentication authority. 52 * @return the authentication state ir {@code null} if not available in the cache. 53 */ 54 AuthScheme get(HttpHost host); 55 56 /** 57 * Removes the authentication state with the given authentication scope from the cache 58 * if found. 59 * 60 * @param host the authentication authority. 61 */ 62 void remove(HttpHost host); 63 64 void clear(); 65 66 /** 67 * Stores the authentication state with the given authentication scope in the cache. 68 * 69 * @param host the authentication authority. 70 * @param pathPrefix the path prefix (the path component up to the last segment separator). 71 * Can be {@code null}. 72 * @param authScheme the cacheable authentication state. 73 * 74 * @since 5.2 75 */ 76 default void put(HttpHost host, String pathPrefix, AuthScheme authScheme) { 77 put(host, authScheme); 78 } 79 80 /** 81 * Returns the authentication state with the given authentication scope from the cache 82 * if available. 83 * @param host the authentication authority. 84 * @param pathPrefix the path prefix (the path component up to the last segment separator). 85 * Can be {@code null}. 86 * @return the authentication state ir {@code null} if not available in the cache. 87 * 88 * @since 5.2 89 */ 90 default AuthScheme get(HttpHost host, String pathPrefix) { 91 return get(host); 92 } 93 94 /** 95 * Removes the authentication state with the given authentication scope from the cache 96 * if found. 97 * 98 * @param host the authentication authority. 99 * @param pathPrefix the path prefix (the path component up to the last segment separator). 100 * Can be {@code null}. 101 * 102 * @since 5.2 103 */ 104 default void remove(HttpHost host, String pathPrefix) { 105 remove(host); 106 } 107 108 }