public class AuthUtil extends Object
Modifier and Type | Field and Description |
---|---|
static AuthScheme[] |
ALL_SCHEMES
List of all known authentication schemes.
|
static String |
AUTH_HEADER
RFC7235 Authorization header key "Authorization" (RFC 7235 sec 4.2).
|
static String |
AUTHID_HEADER
Header giving user authenticated ID "X-VO-Authenticated" (SSO_next).
|
static String |
CHALLENGE_HEADER
RFC 7235 challenge header key "WWW-Authenticate" (RFC 7235 sec 4.1).
|
static AuthScheme[] |
DFLT_SCHEMES
Default list of authentication schemes in order of preference.
|
static boolean |
LOG_SECRETS
Global config: if true, passwords etc may be logged by logger.
|
static String |
LOGSECRETS_PROP
Name of system property "auth.logsecrets" which if set "true"
will allow reporting of sensitive information such as passwords
through the logging system.
|
static String |
SCHEMES_PROP
Name of system property "auth.schemes" giving a comma-separated list of
AuthScheme instances or classnames, which overrides the default list
of authentication schemes in order of preference.
|
static Charset |
UTF8
UTF-8 charset, guaranteed present.
|
Modifier and Type | Method and Description |
---|---|
static String |
authFailureMessage(HttpURLConnection hconn)
Prepares a short user-readable message indicating the state of a
connection that failed because of auth issues.
|
static String |
cookieLogText(HttpCookie cookie)
Returns a string suitable for reporting through the logging system
to represent a cookie.
|
static String |
getAuthenticatedId(AuthConnection aconn)
Returns the authenticated user ID recorded in the headers of
a URL connection.
|
static Challenge[] |
getChallenges(URLConnection conn)
Extracts challenges from an HTTP response.
|
static AuthScheme[] |
getDefaultSchemes()
Returns a default list of AuthSchemes in order of preference.
|
static int |
getResponseCode(URLConnection conn)
Returns the HTTP response code from a URL connection.
|
static void |
postForm(HttpURLConnection hconn,
Map<String,String> params)
Posts name=value pairs to an HTTP connection
in
application/x-www-form-urlencoded format. |
static HttpURLConnection |
postForm(URL url,
Map<String,String> params)
Posts name=value pairs over HTTP in
application/x-www-form-urlencoded format. |
static String |
unNullString(String txt)
Returns the input string, unless it's null, in which case it
returns the empty string.
|
public static final Charset UTF8
public static final String CHALLENGE_HEADER
public static final String AUTH_HEADER
public static final String AUTHID_HEADER
public static final String LOGSECRETS_PROP
public static boolean LOG_SECRETS
public static final String SCHEMES_PROP
public static final AuthScheme[] DFLT_SCHEMES
public static final AuthScheme[] ALL_SCHEMES
public static int getResponseCode(URLConnection conn)
conn
- URL connectionpublic static Challenge[] getChallenges(URLConnection conn)
conn
- open URL connection (typically, but not necessarily, 401)public static String getAuthenticatedId(AuthConnection aconn)
aconn
- connection to endpoint expected to yield an auth IDpublic static String authFailureMessage(HttpURLConnection hconn)
hconn
- open connection, should usually be 401 or 403public static String unNullString(String txt)
txt
- stringpublic static String cookieLogText(HttpCookie cookie)
LOG_SECRETS
,
it will or will not contain sensitive information.cookie
- cookie to representpublic static AuthScheme[] getDefaultSchemes()
SCHEMES_PROP
system property;
if that is not set, it will take the value of DFLT_SCHEMES
.public static HttpURLConnection postForm(URL url, Map<String,String> params) throws IOException
application/x-www-form-urlencoded
format.url
- destination URLparams
- map of name->value pairsIOException
public static void postForm(HttpURLConnection hconn, Map<String,String> params) throws IOException
application/x-www-form-urlencoded
format.
The supplied connection can be the result of a call to
URL.openConnection()
, with or without some customization.hconn
- unopened connectionparams
- map of name->value pairsIOException
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.