Class DuoSupport


  • public final class DuoSupport
    extends Object
    Helpers for DuoWeb and Duo AuthAPI operations.
    Since:
    3.3.0
    • Field Detail

      • RFC_2822_DATE_FORMAT

        public static final DateTimeFormatter RFC_2822_DATE_FORMAT
        RFC 2822 formatter for date/time.
    • Constructor Detail

      • DuoSupport

        private DuoSupport()
        Constructor.
    • Method Detail

      • generateSignedRequestToken

        @Nonnull
        @NotEmpty
        public static String generateSignedRequestToken​(@Nonnull
                                                        net.shibboleth.idp.authn.duo.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 use
        username - 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
                                                         net.shibboleth.idp.authn.duo.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 use
        signedResponseToken - response to validate
        Returns:
        the username from the response
        Throws:
        com.duosecurity.duoweb.DuoWebException - if a Duo failure occurs
        InvalidKeyException - if a key is invalid
        IOException - if an I/O error occurs
        NoSuchAlgorithmException - if the hashing algorithm is unavailable
      • 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 request
        date - the date
        sigVersion - the signature version
        Returns:
        the parameters to be signed in their canonical order
        Throws:
        UnsupportedEncodingException - failure from URLEncoder
      • 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 from URLEncoder