001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.http.header; 018 019import java.util.function.*; 020 021import org.apache.juneau.http.annotation.*; 022 023/** 024 * Represents a parsed <l>Authorization</l> HTTP request header. 025 * 026 * <p> 027 * Authentication credentials for HTTP authentication. 028 * 029 * <h5 class='figure'>Example</h5> 030 * <p class='bcode'> 031 * Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ== 032 * </p> 033 * 034 * <h5 class='topic'>RFC2616 Specification</h5> 035 * 036 * A user agent that wishes to authenticate itself with a server--usually, but not necessarily, after receiving a 401 037 * response--does so by including an Authorization request-header field with the request. 038 * 039 * <p> 040 * The Authorization field value consists of credentials containing the authentication information of the user agent for 041 * the realm of the resource being requested. 042 * 043 * <p class='bcode'> 044 * Authorization = "Authorization" ":" credentials 045 * </p> 046 * 047 * <p> 048 * HTTP access authentication is described in "HTTP Authentication: Basic and Digest Access Authentication". 049 * 050 * <p> 051 * If a request is authenticated and a realm specified, the same credentials SHOULD be valid for all other requests 052 * within this realm (assuming that the authentication scheme itself does not require otherwise, such as credentials 053 * that vary according to a challenge value or using synchronized clocks). 054 * 055 * <p> 056 * When a shared cache (see section 13.7) receives a request containing an Authorization field, it MUST NOT return the 057 * corresponding response as a reply to any other request, unless one of the following specific exceptions holds: 058 * <ol> 059 * <li>If the response includes the "s-maxage" cache-control directive, the cache MAY use that response in replying 060 * to a subsequent request. 061 * But (if the specified maximum age has passed) a proxy cache MUST first revalidate it with the origin 062 * server, using the request-headers from the new request to allow the origin server to authenticate the new 063 * request. 064 * (This is the defined behavior for s-maxage.) 065 * If the response includes "s-maxage=0", the proxy MUST always revalidate it before re-using it. 066 * <li>If the response includes the "must-revalidate" cache-control directive, the cache MAY use that response in 067 * replying to a subsequent request. 068 * But if the response is stale, all caches MUST first revalidate it with the origin server, using the 069 * request-headers from the new request to allow the origin server to authenticate the new request. 070 * <li>If the response includes the "public" cache-control directive, it MAY be returned in reply to any subsequent 071 * request. 072 * </ol> 073 * 074 * <h5 class='section'>See Also:</h5><ul> 075 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/JuneauRestCommonBasics">juneau-rest-common Basics</a> 076 * <li class='extlink'><a class="doclink" href="https://www.w3.org/Protocols/rfc2616/rfc2616.html">Hypertext Transfer Protocol -- HTTP/1.1</a> 077 * </ul> 078 * 079 * @serial exclude 080 */ 081@Header("Authorization") 082public class Authorization extends BasicStringHeader { 083 private static final long serialVersionUID = 1L; 084 private static final String NAME = "Authorization"; 085 086 /** 087 * Static creator. 088 * 089 * @param value 090 * The header value. 091 * <br>Can be <jk>null</jk>. 092 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 093 */ 094 public static Authorization of(String value) { 095 return value == null ? null : new Authorization(value); 096 } 097 098 /** 099 * Static creator with delayed value. 100 * 101 * <p> 102 * Header value is re-evaluated on each call to {@link #getValue()}. 103 * 104 * @param value 105 * The supplier of the header value. 106 * <br>Can be <jk>null</jk>. 107 * @return A new header bean, or <jk>null</jk> if the value is <jk>null</jk>. 108 */ 109 public static Authorization of(Supplier<String> value) { 110 return value == null ? null : new Authorization(value); 111 } 112 113 /** 114 * Constructor. 115 * 116 * @param value 117 * The header value. 118 * <br>Can be <jk>null</jk>. 119 */ 120 public Authorization(String value) { 121 super(NAME, value); 122 } 123 124 /** 125 * Constructor with delayed value. 126 * 127 * <p> 128 * Header value is re-evaluated on each call to {@link #getValue()}. 129 * 130 * @param value 131 * The supplier of the header value. 132 * <br>Can be <jk>null</jk>. 133 */ 134 public Authorization(Supplier<String> value) { 135 super(NAME, value); 136 } 137}