0

I'm attempting to ping my archiva server, which isn't a problem on pages not requiring authorization. However, when I try to pingWithAutz, I cannot help but get a 403 error. Here is the relevant code snippet:

         public FormValidation doTestConnection(@QueryParameter("url") String url,
             @QueryParameter("username") String usr,
             @QueryParameter("password") String pwd)
             throws Exception {

         if (url == null || url.equals("")) {
             return FormValidation.error("Please, set a correct url");
         }
         url = url.endsWith("/") ? url.substring(0, url.length() - 1) : url;
         HttpPost post = new HttpPost(url + "/restServices/redbackServices/loginService/pingWithAutz");
         String authzHeader = "Basic " + Base64Utility.encode(( usr + ":" + pwd ).getBytes());
         post.setHeader("Authorization",authzHeader);

         HttpClientBuilder builder = HttpClientBuilder.create();
         CloseableHttpClient httpclient = builder.build();
         CloseableHttpResponse response = null;

         try {
             response = httpclient.execute(post);

             if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
                 return FormValidation.error("Cannot connect to the server. Response Code : " +
                         response.getStatusLine());
             }
         } catch(Exception e){
             System.out.println(e);
         }
         finally {
             response.close();
         }           
         return FormValidation.ok("Successfully connected to Archiva Server.");
     }

What am I doing wrong that it won't authenticate properly?

  • Note: I have verified the usr/pwd being passed into the function are correct. I use 'admin:admin' credentials that come with an archiva server for testing. The base URL is certainly correct, as nonAuthz URLS (just cutting the trailing 'withAutz' from the URL) returns a successful http response. – Russell Busch Feb 25 '15 at 21:59

1 Answers1

0

You should try with a HttpGet as this service is expected a GET http and not a POST. See http://archiva.apache.org/docs/2.2.0/rest-docs-redback-rest-api/resource_LoginService.html#path__loginService_ping.html

HTH

Olivier Lamy
  • 2,280
  • 1
  • 14
  • 12