Ejemplo n.º 1
0
  /**
   * Produces basic authorization header for the given set of {@link Credentials}.
   *
   * @param credentials The set of credentials to be used for authentication
   * @param request The request being authenticated
   * @throws InvalidCredentialsException if authentication credentials are not valid or not
   *     applicable for this authentication scheme
   * @throws AuthenticationException if authorization string cannot be generated due to an
   *     authentication failure
   * @return a basic authorization string
   */
  public Header authenticate(final Credentials credentials, final HttpRequest request)
      throws AuthenticationException {

    if (credentials == null) {
      throw new IllegalArgumentException("Credentials may not be null");
    }
    if (request == null) {
      throw new IllegalArgumentException("HTTP request may not be null");
    }

    String charset = AuthParams.getCredentialCharset(request.getParams());
    return authenticate(credentials, charset, isProxy());
  }
Ejemplo n.º 2
0
  /**
   * Produces a digest authorization string for the given set of {@link Credentials}, method name
   * and URI.
   *
   * @param credentials A set of credentials to be used for athentication
   * @param request The request being authenticated
   * @throws org.apache.http.auth.InvalidCredentialsException if authentication credentials are not
   *     valid or not applicable for this authentication scheme
   * @throws AuthenticationException if authorization string cannot be generated due to an
   *     authentication failure
   * @return a digest authorization string
   */
  public Header authenticate(final Credentials credentials, final HttpRequest request)
      throws AuthenticationException {

    if (credentials == null) {
      throw new IllegalArgumentException("Credentials may not be null");
    }
    if (request == null) {
      throw new IllegalArgumentException("HTTP request may not be null");
    }

    // Add method name and request-URI to the parameter map
    getParameters().put("methodname", request.getRequestLine().getMethod());
    getParameters().put("uri", request.getRequestLine().getUri());
    String charset = getParameter("charset");
    if (charset == null) {
      charset = AuthParams.getCredentialCharset(request.getParams());
      getParameters().put("charset", charset);
    }
    return createDigestHeader(credentials);
  }