Class DuoSupport
- java.lang.Object
-
- net.shibboleth.idp.authn.duo.impl.DuoSupport
-
public final class DuoSupport extends Object
Helpers for DuoWeb and Duo AuthAPI operations.- Since:
- 3.3.0
-
-
Field Summary
Fields Modifier and Type Field Description static DateTimeFormatterRFC_2822_DATE_FORMATRFC 2822 formatter for date/time.
-
Constructor Summary
Constructors Modifier Constructor Description privateDuoSupport()Constructor.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static StringcanonRequest(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 StringcreateQueryString(List<org.apache.http.NameValuePair> params)Builds a string representation of the query string with the parameter names is alphabetical order.static StringgenerateSignedRequestToken(DuoIntegration duo, String username)Created a signed request to Duo for a user.static voidsignRequest(org.apache.http.client.methods.RequestBuilder request, DuoIntegration duo)Sign a Duo AuthAPI request.static StringvalidateSignedResponseToken(DuoIntegration duo, String signedResponseToken)Verify a signed response from Duo and extract the username.
-
-
-
Field Detail
-
RFC_2822_DATE_FORMAT
public static final DateTimeFormatter RFC_2822_DATE_FORMAT
RFC 2822 formatter for date/time.
-
-
Method Detail
-
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
-
-