XQuery/Publishing to Subversion

< XQuery

Motivation

You want to have a single button on a content management system that will copy a file to a remote subversion repository.

Method

We will configure our subversion repository on a standard Apache server that is configured with an SSL certificate. This will encrypt all communication between the intranet system and the remote subversion server. We will also set the authentication to be Basic Authentication.

Apache Configuration File

<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  testuser1  testuser2  testuser3
  </Limit>
  AuthType Basic
</Location>

HTTP Put Function for Basic Authentication

HTTP Basic authentication requires the user to concatinate the user and password with a colon seperating the strings and then do a base64-encoding on that string. This is then send in the HTTP header with the key of "Authorization". The HTTP header must look like the following:

  Authorization = Basic BASE64-ENCODED-USER-PASSWORD

The following XQuery function performs this process.

declare function http:put-basic-auth($url, $content, $username, $password, $in-header) as node(){
  let $credentials := concat($username, ':', $password)
  let $encode := util:base64-encode($credentials)
  let $value := concat('Basic ', $encode)
  let $new-headers :=
  <headers>
     {$in-header/header}
     <header name="Authorization" value="{$value}"/>
  </headers>
  let $response := httpclient:put($url, $content, false(), $new-headers)
return $response
};

To put the file you just need to put the URL to the correct content area, and the content to be inserted, the user name and password and

Monitoring HTTP Client Libraries

Debugging authentication protocols is very difficult if you do not have the correct tools. One of the most useful tools is to enable logging for the httpclient module.

  <category name="org.apache.commons.httpclient" additivity="false">
        <priority value="debug"/>
        <appender-ref ref="console"/>
    </category>

References

Wikipedia entry on Basic access authentication

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.