Class DuoSupport
java.lang.Object
net.shibboleth.idp.authn.duo.impl.DuoSupport
Helpers for DuoWeb and Duo AuthAPI operations.
- Since:
- 3.3.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DateTimeFormatter
RFC 2822 formatter for date/time. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String
canonRequest
(org.apache.http.client.methods.RequestBuilder request, String date, int sigVersion) The signature requires that the request parameters being in a particular order as specified in the API.private static String
createQueryString
(List<org.apache.http.NameValuePair> params) Builds a string representation of the query string with the parameter names is alphabetical order.static String
generateSignedRequestToken
(DuoIntegration duo, String username) Created a signed request to Duo for a user.static void
signRequest
(org.apache.http.client.methods.RequestBuilder request, DuoIntegration duo) Sign a Duo AuthAPI request.static String
validateSignedResponseToken
(DuoIntegration duo, String signedResponseToken) Verify a signed response from Duo and extract the username.
-
Field Details
-
RFC_2822_DATE_FORMAT
RFC 2822 formatter for date/time.
-
-
Constructor Details
-
DuoSupport
private DuoSupport()Constructor.
-
-
Method Details
-
generateSignedRequestToken
@Nonnull @NotEmpty public static String generateSignedRequestToken(@Nonnull DuoIntegration duo, @Nonnull @NotEmpty String username) throws com.duosecurity.duoweb.DuoWebException Created a signed request to Duo for a user.- Parameters:
duo
- integration parameters to useusername
- user to authenticate- Returns:
- the signed request string
- Throws:
com.duosecurity.duoweb.DuoWebException
- if an error occurs
-
validateSignedResponseToken
@Nonnull @NotEmpty public static String validateSignedResponseToken(@Nonnull DuoIntegration duo, @Nonnull @NotEmpty String signedResponseToken) throws com.duosecurity.duoweb.DuoWebException, InvalidKeyException, IOException, NoSuchAlgorithmException Verify a signed response from Duo and extract the username.- Parameters:
duo
- integration parameters to usesignedResponseToken
- response to validate- Returns:
- the username from the response
- Throws:
com.duosecurity.duoweb.DuoWebException
- if a Duo failure occursInvalidKeyException
- if a key is invalidIOException
- if an I/O error occursNoSuchAlgorithmException
- if the hashing algorithm is unavailable
-
signRequest
@Nonnull @NotEmpty public static void signRequest(@Nonnull org.apache.http.client.methods.RequestBuilder request, @Nonnull DuoIntegration duo) throws InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException Sign a Duo AuthAPI request.- Parameters:
request
- the request to be signedduo
- integration parameters to use- Throws:
InvalidKeyException
- bad skey valueNoSuchAlgorithmException
- unknown encryption algorithmUnsupportedEncodingException
- failure fromURLEncoder
- Since:
- 3.4.0
-
canonRequest
private static String canonRequest(@Nonnull org.apache.http.client.methods.RequestBuilder request, @Nonnull String date, int sigVersion) throws UnsupportedEncodingException The signature requires that the request parameters being in a particular order as specified in the API.- Parameters:
request
- the requestdate
- the datesigVersion
- the signature version- Returns:
- the parameters to be signed in their canonical order
- Throws:
UnsupportedEncodingException
- failure fromURLEncoder
-
createQueryString
private static String createQueryString(@Nonnull List<org.apache.http.NameValuePair> params) throws UnsupportedEncodingException Builds a string representation of the query string with the parameter names is alphabetical order. The names and values are URL encoded and then they are concatenated with '&' in between.- Parameters:
params
- the name/value pairs to be joined- Returns:
- the canonical query string
- Throws:
UnsupportedEncodingException
- failure fromURLEncoder
-