You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Loren Cahlander <lo...@gmail.com> on 2010/05/12 18:13:32 UTC
Authentication error while using httpclient code to access a subversion server
I have a subversion server that is configured through apache with the following:
<Location "/testsvn/">
DAV svn
AuthName "svntest"
SVNParentPath /Library/Subversion/RepositoryTest
SVNAutoversioning on
<Limit GET HEAD OPTIONS CONNECT POST PROPFIND PUT DELETE PROPPATCH MKCOL COPY MOVE LOCK UNLOCK>
Require user xxxx yyyyy zzzzzzz
</Limit>
AuthType Digest
</Location>
I can authenticate to the repository fine through the FireFox and Safari browsers, so I know that it my problem is not a configuration issue on the server. I have the attached code to do a put to the subversion repository. I know that the put works, because I am able to authenticate to the repository through the Transmit application and drop a file into the repository. I have highlighted the most relevant sections of the code. Can someone please tell me what I need to add to fix the CredentialsProvider issue?
Thank you,
Loren Cahlander
public Sequence eval( Sequence[] args, Sequence contextSequence ) throws XPathException
{
Sequence response = null;
// must be a URL
if( args[0].isEmpty() ) {
return( Sequence.EMPTY_SEQUENCE );
}
//get the url
String url = args[0].itemAt( 0 ).getStringValue();
//get the payload
Item payload = args[1].itemAt( 0 );
//get the persist state
boolean persistState = args[2].effectiveBooleanValue();
//serialize the node to SAX
ByteArrayOutputStream baos = new ByteArrayOutputStream();
OutputStreamWriter osw = null;
try {
osw = new OutputStreamWriter( baos, "UTF-8" );
}
catch( UnsupportedEncodingException e ) {
throw( new XPathException( this, "Internal error" ) );
}
XMLWriter xmlWriter = new XMLWriter( osw );
SAXSerializer sax = new SAXSerializer();
sax.setReceiver( xmlWriter );
try {
payload.toSAX( context.getBroker(), sax, new Properties() );
osw.flush();
osw.close();
}
catch( Exception e ) {
e.printStackTrace();
}
//setup PUT request
PutMethod put = new PutMethod( url );
RequestEntity entity = new ByteArrayRequestEntity( baos.toByteArray(), "application/xml; charset=utf-8" );
put.setRequestEntity( entity );
//setup PUT Request Headers
if( !args[3].isEmpty() ) {
setHeaders( put, ( ( NodeValue )args[3].itemAt( 0 ) ).getNode() );
}
try {
if(args.length > 4)
{
//with authentication
String host = null; //i.e. any host
int port = -1; //i.e. any port
String username = args[4].itemAt(0).getStringValue();
String password = args[5].itemAt(0).getStringValue();
String realm = args[6].itemAt(0).getStringValue();
Credentials userPass = new UsernamePasswordCredentials(username, password); //note - could use NTCredentials for NTLM auth
AuthScope authScope = new AuthScope(host, port, realm);
//execute the request
response = doRequest(context, put, persistState, userPass, authScope);
}
else
{
//without authentication
//execute the request
response = doRequest( context, put, persistState );
}
}
catch( IOException ioe ) {
throw( new XPathException( this, ioe.getMessage(), ioe ) );
}
finally {
put.releaseConnection();
}
return( response );
}
protected Sequence doRequest( XQueryContext context, HttpMethod method, boolean persistState, Credentials credentials, AuthScope authScope) throws IOException, XPathException
{
int statusCode = 0;
Sequence encodedResponse = null;
HttpClient http = new HttpClient();
if(credentials != null && authScope != null)
{
http.getState().setCredentials(authScope, credentials);
method.setDoAuthentication(true);
}
//execute the request
try
{
//use existing state?
if(persistState)
{
//get existing state
HttpState state = (HttpState)context.getXQueryContextVar( HTTP_MODULE_PERSISTENT_STATE );
if(state != null)
{
http.setState( state );
}
}
//set the proxy server (if any)
String proxyHost = System.getProperty( "http.proxyHost" );
if( proxyHost != null )
{
//TODO: support for http.nonProxyHosts e.g. -Dhttp.nonProxyHosts="*.devonline.gov.uk|*.devon.gov.uk"
ProxyHost proxy = new ProxyHost( proxyHost, Integer.parseInt( System.getProperty( "http.proxyPort" ) ) );
http.getHostConfiguration().setProxyHost( proxy );
}
//perform the request
statusCode = http.executeMethod( method );
encodedResponse = encodeResponseAsXML( context, method, statusCode );
//persist state?
if( persistState )
{
context.setXQueryContextVar( HTTP_MODULE_PERSISTENT_STATE, http.getState() );
}
}
catch( Exception e )
{
encodedResponse = encodeErrorResponse( context, e.getMessage() );
}
return encodedResponse;
}
12 May 2010 06:27:31,665 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.useragent = Jakarta Commons-HttpClient/3.1
12 May 2010 06:27:31,667 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.protocol.version = HTTP/1.1
12 May 2010 06:27:31,668 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.connection-manager.class = class org.apache.commons.httpclient.SimpleHttpConnectionManager
12 May 2010 06:27:31,669 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.protocol.cookie-policy = default
12 May 2010 06:27:31,670 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.protocol.element-charset = US-ASCII
12 May 2010 06:27:31,670 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.protocol.content-charset = ISO-8859-1
12 May 2010 06:27:31,671 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.method.retry-handler = org.apache.commons.httpclient.DefaultHttpMethodRetryHandler@af4627
12 May 2010 06:27:31,672 [qtp2038015135-28] DEBUG (DefaultHttpParams.java [setParameter]:151) - Set parameter http.dateparser.patterns = [EEE, dd MMM yyyy HH:mm:ss zzz, EEEE, dd-MMM-yy HH:mm:ss zzz, EEE MMM d HH:mm:ss yyyy, EEE, dd-MMM-yyyy HH:mm:ss z, EEE, dd-MMM-yyyy HH-mm-ss z, EEE, dd MMM yy HH:mm:ss z, EEE dd-MMM-yyyy HH:mm:ss z, EEE dd MMM yyyy HH:mm:ss z, EEE dd-MMM-yyyy HH-mm-ss z, EEE dd-MMM-yy HH:mm:ss z, EEE dd MMM yy HH:mm:ss z, EEE,dd-MMM-yy HH:mm:ss z, EEE,dd-MMM-yyyy HH:mm:ss z, EEE, dd-MM-yyyy HH:mm:ss z]
12 May 2010 06:27:31,720 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:72) - Java version: 1.6.0_17
12 May 2010 06:27:31,721 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:73) - Java vendor: Apple Inc.
12 May 2010 06:27:31,722 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:74) - Java class path: /Users/lcahlander/Documents/workspace/paho-exist/src/web/start.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/exist.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/exist-optional.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/endorsed/resolver-1.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/endorsed/serializer-2.9.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/endorsed/xalan-2.7.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/endorsed/xercesImpl-2.9.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/endorsed/xml-apis-1.4.01.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/antlr-2.7.7.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/commons-pool-1.5.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/log4j-1.2.15.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/sunxacml-1.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/xmldb.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/xmlrpc-common-3.1.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/xmlrpc-server-3.1.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/xmlrpc-client-3.1.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/ws-commons-util-1.0.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/jgroups-all-2.2.6.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/quartz-1.7.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/jta-1.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/commons-collections-3.2.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/core/commons-logging-1.1.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/axis-1.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/axis-ant-1.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/axis-schema-1.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-codec-1.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-compress-1.0.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-discovery-0.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-fileupload-1.2.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-httpclient-3.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/commons-io-1.4.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/isorelax-20041111.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/jaxrpc-1.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/jing-20091111.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/jsp-api-2.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/saaj-1.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/servlet-api-2.5.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/optional/wsdl4j-1.5.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-cocoon.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-lucene-module.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-modules.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-ngram-module.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-security-openid.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-sort-module.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-versioning.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-xqdoc.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/exist-xslt.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/extensions/xprocxq.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/extensions/security/openid/lib/openid4java-0.9.5.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/extensions/indexes/lucene/lib/lucene-core-2.9.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/extensions/indexes/lucene/lib/lucene-regex-2.9.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/extensions/xprocxq/main/lib/expath.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/extensions/xqdoc/lib/xqdoc_conv.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/ant/lib/ant.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/ant/lib/xmlunit-1.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-continuation-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-http-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-io-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-plus-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-security-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-server-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-servlet-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-servlets-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-util-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-webapp-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jetty-xml-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jsp/jetty-jsp-2.1-7.0.1.v20091125.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jsp/jsp-2.1-glassfish-9.1.1.B60.25.p2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/tools/jetty/lib/jsp/jsp-api-2.1-glassfish-9.1.1.B60.25.p2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/activation-1.1.1.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/avalon-framework-api-4.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/avalon-framework-impl-4.3.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/batik-all-1.7.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/fop.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/jcommon-1.0.16.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/jfreechart-1.0.13.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/mail-1.4.2.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/nekohtml-1.9.11.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/svnkit.jar:/Users/lcahlander/Documents/workspace/paho-exist/src/web/lib/user/xmlgraphics-commons-1.3.1.jar
12 May 2010 06:27:31,723 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:75) - Operating system name: Mac OS X
12 May 2010 06:27:31,742 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:76) - Operating system architecture: x86_64
12 May 2010 06:27:31,743 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:77) - Operating system version: 10.6.3
12 May 2010 06:27:31,743 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SUN 1.6: SUN (DSA key/parameter generation; DSA signing; SHA-1, MD5 digests; SecureRandom; X.509 certificates; JKS keystore; PKIX CertPathValidator; PKIX CertPathBuilder; LDAP, Collection CertStores, JavaPolicy Policy; JavaLoginConfig Configuration)
12 May 2010 06:27:31,744 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - Apple 1.0: Apple Provider (implements DES, Triple DES, AES, Blowfish, PBE, Diffie-Hellman, HMAC/MD5, HMAC/SHA1)
12 May 2010 06:27:31,744 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunRsaSign 1.5: Sun RSA signature provider
12 May 2010 06:27:31,744 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunJSSE 1.6: Sun JSSE provider(PKCS12, SunX509 key/trust factories, SSLv3, TLSv1)
12 May 2010 06:27:31,745 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunJCE 1.6: SunJCE Provider (implements RSA, DES, Triple DES, AES, Blowfish, ARCFOUR, RC2, PBE, Diffie-Hellman, HMAC)
12 May 2010 06:27:31,745 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunJGSS 1.0: Sun (Kerberos v5, SPNEGO)
12 May 2010 06:27:31,745 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunSASL 1.5: Sun SASL provider(implements client mechanisms for: DIGEST-MD5, GSSAPI, EXTERNAL, PLAIN, CRAM-MD5; server mechanisms for: DIGEST-MD5, GSSAPI, CRAM-MD5)
12 May 2010 06:27:31,746 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - XMLDSig 1.0: XMLDSig (DOM XMLSignatureFactory; DOM KeyInfoFactory)
12 May 2010 06:27:31,746 [qtp2038015135-28] DEBUG (HttpClient.java [<clinit>]:82) - SunPCSC 1.6: Sun PC/SC provider
12 May 2010 06:27:31,793 [qtp2038015135-28] DEBUG (HttpConnection.java [open]:692) - Open connection to support.syntactica.com:80
12 May 2010 06:27:31,821 [qtp2038015135-28] DEBUG (HttpMethodBase.java [addHostRequestHeader]:1352) - Adding Host request header
12 May 2010 06:27:31,832 [qtp2038015135-28] DEBUG (EntityEnclosingMethod.java [writeRequestBody]:508) - Request body sent
12 May 2010 06:27:31,897 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [isAuthenticationNeeded]:843) - Authorization required
12 May 2010 06:27:31,904 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [selectAuthScheme]:90) - Supported authentication schemes in the order of preference: [ntlm, digest, basic]
12 May 2010 06:27:31,904 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [selectAuthScheme]:111) - Challenge for ntlm authentication scheme not available
12 May 2010 06:27:31,905 [qtp2038015135-28] INFO (AuthChallengeProcessor.java [selectAuthScheme]:101) - digest authentication scheme selected
12 May 2010 06:27:31,905 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [processChallenge]:155) - Using authentication scheme: digest
12 May 2010 06:27:31,905 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [processChallenge]:163) - Authorization challenge processed
12 May 2010 06:27:31,906 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [processWWWAuthChallenge]:714) - Authentication scope: DIGEST 'svntest'@support.syntactica.com:80
12 May 2010 06:27:31,906 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [executeMethod]:194) - Retry authentication
12 May 2010 06:27:31,946 [qtp2038015135-28] DEBUG (HttpMethodBase.java [shouldCloseConnection]:1024) - Resorting to protocol version default close connection policy
12 May 2010 06:27:31,947 [qtp2038015135-28] DEBUG (HttpMethodBase.java [shouldCloseConnection]:1028) - Should NOT close connection, using HTTP/1.1
12 May 2010 06:27:31,947 [qtp2038015135-28] DEBUG (HttpConnection.java [releaseConnection]:1176) - Connection is locked. Call to releaseConnection() ignored.
12 May 2010 06:27:31,951 [qtp2038015135-28] DEBUG (HttpMethodBase.java [addHostRequestHeader]:1352) - Adding Host request header
12 May 2010 06:27:31,951 [qtp2038015135-28] DEBUG (EntityEnclosingMethod.java [writeRequestBody]:508) - Request body sent
12 May 2010 06:27:31,976 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [isAuthenticationNeeded]:843) - Authorization required
12 May 2010 06:27:31,977 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [processChallenge]:155) - Using authentication scheme: digest
12 May 2010 06:27:31,978 [qtp2038015135-28] DEBUG (AuthChallengeProcessor.java [processChallenge]:163) - Authorization challenge processed
12 May 2010 06:27:31,978 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [processWWWAuthChallenge]:714) - Authentication scope: DIGEST 'svntest'@support.syntactica.com:80
12 May 2010 06:27:31,978 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [promptForCredentials]:861) - Credentials required
12 May 2010 06:27:31,979 [qtp2038015135-28] DEBUG (HttpMethodDirector.java [promptForCredentials]:879) - Credentials provider not available
12 May 2010 06:27:31,979 [qtp2038015135-28] INFO (HttpMethodDirector.java [processWWWAuthChallenge]:722) - Failure authenticating with DIGEST 'svntest'@support.syntactica.com:80
12 May 2010 06:27:31,982 [qtp2038015135-28] DEBUG (HttpMethodBase.java [shouldCloseConnection]:1024) - Resorting to protocol version default close connection policy
12 May 2010 06:27:31,983 [qtp2038015135-28] DEBUG (HttpMethodBase.java [shouldCloseConnection]:1028) - Should NOT close connection, using HTTP/1.1
12 May 2010 06:27:31,983 [qtp2038015135-28] DEBUG (HttpConnection.java [releaseConnection]:1178) - Releasing connection back to connection manager.