Class HttpAuthenticationFilter
- java.lang.Object
-
- org.glassfish.jersey.client.authentication.HttpAuthenticationFilter
-
- All Implemented Interfaces:
javax.ws.rs.client.ClientRequestFilter
,javax.ws.rs.client.ClientResponseFilter
@Priority(1000) class HttpAuthenticationFilter extends java.lang.Object implements javax.ws.rs.client.ClientRequestFilter, javax.ws.rs.client.ClientResponseFilter
Http Authentication filter that provides basic and digest authentication (based on RFC 2617).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
HttpAuthenticationFilter.Credentials
Credentials (username + password).(package private) static class
HttpAuthenticationFilter.Type
Authentication type.
-
Field Summary
Fields Modifier and Type Field Description private BasicAuthenticator
basicAuth
(package private) static java.nio.charset.Charset
CHARACTER_SET
Encoding used for authentication calculations.private DigestAuthenticator
digestAuth
private static int
MAXIMUM_DIGEST_CACHE_SIZE
private HttpAuthenticationFeature.Mode
mode
private static java.lang.String
REQUEST_PROPERTY_FILTER_REUSED
private static java.lang.String
REQUEST_PROPERTY_OPERATION
private java.util.Map<java.lang.String,HttpAuthenticationFilter.Type>
uriCache
Cache withURI:HTTP-METHOD
keys and authentication type as values.
-
Constructor Summary
Constructors Constructor Description HttpAuthenticationFilter(HttpAuthenticationFeature.Mode mode, HttpAuthenticationFilter.Credentials basicCredentials, HttpAuthenticationFilter.Credentials digestCredentials, javax.ws.rs.core.Configuration configuration)
Create a new filter instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static HttpAuthenticationFilter.Credentials
extractCredentials(javax.ws.rs.client.ClientRequestContext request, HttpAuthenticationFilter.Type type)
void
filter(javax.ws.rs.client.ClientRequestContext request)
void
filter(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response)
private java.lang.String
getCacheKey(javax.ws.rs.client.ClientRequestContext request)
(package private) static HttpAuthenticationFilter.Credentials
getCredentials(javax.ws.rs.client.ClientRequestContext request, HttpAuthenticationFilter.Credentials defaultCredentials, HttpAuthenticationFilter.Type type)
Get credentials actual for the current request.private int
getMaximumCacheLimit(javax.ws.rs.core.Configuration configuration)
(package private) static boolean
repeatRequest(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response, java.lang.String newAuthorizationHeader)
Repeat therequest
with providednewAuthorizationHeader
and update theresponse
with newest response data.private void
updateCache(javax.ws.rs.client.ClientRequestContext request, boolean success, HttpAuthenticationFilter.Type operation)
-
-
-
Field Detail
-
REQUEST_PROPERTY_FILTER_REUSED
private static final java.lang.String REQUEST_PROPERTY_FILTER_REUSED
- See Also:
- Constant Field Values
-
REQUEST_PROPERTY_OPERATION
private static final java.lang.String REQUEST_PROPERTY_OPERATION
- See Also:
- Constant Field Values
-
CHARACTER_SET
static final java.nio.charset.Charset CHARACTER_SET
Encoding used for authentication calculations.
-
mode
private final HttpAuthenticationFeature.Mode mode
-
uriCache
private final java.util.Map<java.lang.String,HttpAuthenticationFilter.Type> uriCache
Cache withURI:HTTP-METHOD
keys and authentication type as values. Contains successful authentications already performed by the filter.
-
digestAuth
private final DigestAuthenticator digestAuth
-
basicAuth
private final BasicAuthenticator basicAuth
-
MAXIMUM_DIGEST_CACHE_SIZE
private static final int MAXIMUM_DIGEST_CACHE_SIZE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
HttpAuthenticationFilter
HttpAuthenticationFilter(HttpAuthenticationFeature.Mode mode, HttpAuthenticationFilter.Credentials basicCredentials, HttpAuthenticationFilter.Credentials digestCredentials, javax.ws.rs.core.Configuration configuration)
Create a new filter instance.- Parameters:
mode
- Mode.basicCredentials
- Basic credentials (can benull
if this filter does not work in the basic mode or if no default credentials are defined).digestCredentials
- Digest credentials (can benull
if this filter does not work in the digest mode or if no default credentials are defined).configuration
- Configuration (non-null
).
-
-
Method Detail
-
getMaximumCacheLimit
private int getMaximumCacheLimit(javax.ws.rs.core.Configuration configuration)
-
filter
public void filter(javax.ws.rs.client.ClientRequestContext request) throws java.io.IOException
- Specified by:
filter
in interfacejavax.ws.rs.client.ClientRequestFilter
- Throws:
java.io.IOException
-
filter
public void filter(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response) throws java.io.IOException
- Specified by:
filter
in interfacejavax.ws.rs.client.ClientResponseFilter
- Throws:
java.io.IOException
-
getCacheKey
private java.lang.String getCacheKey(javax.ws.rs.client.ClientRequestContext request)
-
updateCache
private void updateCache(javax.ws.rs.client.ClientRequestContext request, boolean success, HttpAuthenticationFilter.Type operation)
-
repeatRequest
static boolean repeatRequest(javax.ws.rs.client.ClientRequestContext request, javax.ws.rs.client.ClientResponseContext response, java.lang.String newAuthorizationHeader)
Repeat therequest
with providednewAuthorizationHeader
and update theresponse
with newest response data.- Parameters:
request
- Request context.response
- Response context (will be updated with the new response data).newAuthorizationHeader
-Authorization
header that should be added to the new request.- Returns:
true
is the authentication was successful (true
if 401 response code was not returned;false
otherwise).
-
extractCredentials
private static HttpAuthenticationFilter.Credentials extractCredentials(javax.ws.rs.client.ClientRequestContext request, HttpAuthenticationFilter.Type type)
-
getCredentials
static HttpAuthenticationFilter.Credentials getCredentials(javax.ws.rs.client.ClientRequestContext request, HttpAuthenticationFilter.Credentials defaultCredentials, HttpAuthenticationFilter.Type type)
Get credentials actual for the current request. Priorities in credentials selection are the following:- Basic/digest specific credentials defined in the request properties
- Common credentials defined in the request properties
defaultCredentials
- Parameters:
request
- Request from which credentials should be extracted.defaultCredentials
- Default credentials (can benull
).type
- Type of requested credentials.- Returns:
- Credentials or
null
if no credentials are found anddefaultCredentials
arenull
. - Throws:
RequestAuthenticationException
- in case theusername
orpassword
is invalid.
-
-