karu karu - 7 months ago 22
Java Question

Maven Cargo plugin deploying to tomcat using digest authentication

I'm having trouble using the maven cargo plugin to deploy to a hosted tomcat server. I understand the server expects digest authentication. I am able to deploy to my vanilla test server with no problems.

curl -u username --digest http://hostname/manager/text/list
returns the list of apps.

Is there a config I am missing?

Answer

Update: Cargo 1.4.10 added support for digest authentication.

I don't think so. I ran into the same problem with Jenkins' Deploy Plugin. After diving into the source AFAICT Cargo only supports Basic authentication for Tomcat: http://svn.codehaus.org/cargo/core/trunk/containers/tomcat/src/main/java/org/codehaus/cargo/container/tomcat/internal/TomcatManager.java

protected String invoke(String path, InputStream data) throws TomcatManagerException,
    IOException
{
    ...

    if (this.username != null)
    {
        String authorization = toAuthorization(this.username, this.password);
        connection.setRequestProperty("Authorization", authorization);
    }
    ...
/**
 * Gets the HTTP Basic Authorization header value for the supplied username and password.
 * 
 * @param username the username to use for authentication
 * @param password the password to use for authentication
 * @return the HTTP Basic Authorization header value
 */
private static String toAuthorization(String username, String password)
{
    StringBuilder buffer = new StringBuilder();
    buffer.append(username).append(':');
    if (password != null)
    {
        buffer.append(password);
    }
    return "Basic " + new String(Base64.encodeBase64(buffer.toString().getBytes()));
}

I'm guessing that this is because the connection is implemented with a plain HttpUrlConnection, so adding support for DIGEST would be a pain.