Package org.forgerock.http.header
Class AuthorizationHeader
- java.lang.Object
-
- org.forgerock.http.protocol.Header
-
- org.forgerock.http.header.AuthorizationHeader
-
public class AuthorizationHeader extends Header
A header class representing theAuthorization
HTTP header.The
Authorization
header is made up of<type><space><credentials>
, where credentials can be any text that fulfils the requirements of the type. e.g. for a type ofBasic
, the credentials will bebase64encode(username + ":" + password)
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
AuthorizationHeader.Factory
A factory for creatingAuthorizationHeader
instances.
-
Constructor Summary
Constructors Constructor Description AuthorizationHeader()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getCredentials()
Get the credentials component of the header value.String
getName()
Returns the name of the header, as it would canonically appear within an HTTP message.String
getRawValue()
Get the raw value of the header.String
getType()
Get the type of the authorization being presented, e.g.List<String>
getValues()
Returns the header as a list of strings.<C> Optional<C>
parseCredentials(CredentialsParser<C> parser)
Parse the credentials to a rich type.AuthorizationHeader
setRawValue(String rawValue)
Set the raw value of the header.static AuthorizationHeader
valueOf(String value)
Parse a string as anAuthorization
header value.static AuthorizationHeader
valueOf(Message<?> message)
Constructs a new header, initialized from the specified message.-
Methods inherited from class org.forgerock.http.protocol.Header
equals, getFirstValue, hashCode, toString
-
-
-
-
Field Detail
-
NAME
public static final String NAME
A constant for the name of the Authorization header.- See Also:
- Constant Field Values
-
-
Method Detail
-
getName
public String getName()
Description copied from class:Header
Returns the name of the header, as it would canonically appear within an HTTP message.
-
getValues
public List<String> getValues()
Description copied from class:Header
Returns the header as a list of strings. If the header has no values then it must return an empty list, never null. EachString
should represent the value component of the key-value pair that makes up the HTTP header - as such, for someHeader
implementations each String in thisList
may contain multiple token-separated values.The
List
returned from this method should not be expected to be mutable. However, some subclasses ofHeader
may choose to implement it as such.
-
setRawValue
public AuthorizationHeader setRawValue(String rawValue) throws MalformedHeaderException
Set the raw value of the header.- Parameters:
rawValue
- The raw value.- Returns:
- The header.
- Throws:
MalformedHeaderException
- If the value is malformed.
-
getRawValue
public String getRawValue()
Get the raw value of the header.- Returns:
- The raw value.
-
getType
public String getType()
Get the type of the authorization being presented, e.g.Basic
- Returns:
- The type.
-
getCredentials
public String getCredentials()
Get the credentials component of the header value.- Returns:
- The credentials string.
-
parseCredentials
public <C> Optional<C> parseCredentials(CredentialsParser<C> parser) throws MalformedHeaderException
Parse the credentials to a rich type.- Type Parameters:
C
- The rich type for the credentials.- Parameters:
parser
- The parser that can parse to the rich type.- Returns:
- An optional of the parsed credentials, or an empty optional if the type is not supported by the
provided
parser
. - Throws:
MalformedHeaderException
- If the credentials are not valid for the type.
-
valueOf
public static AuthorizationHeader valueOf(String value) throws MalformedHeaderException
Parse a string as anAuthorization
header value.- Parameters:
value
- The value.- Returns:
- The header.
- Throws:
MalformedHeaderException
- If the header cannot be parsed as anAuthorization
header.
-
valueOf
public static AuthorizationHeader valueOf(Message<?> message) throws MalformedHeaderException
Constructs a new header, initialized from the specified message.- Parameters:
message
- The message to initialize the header from.- Returns:
- The parsed header.
- Throws:
MalformedHeaderException
- If theAuthorization
header is present but malformed.
-
-