1

I'm trying to generate a temporary URL from one of my openstack swift container. But when I access the url it gives me 401 Unauthorized: Temp URL invalid

Here is a sample version of how I'm doing it.

package com.raja.openstack;

import org.javaswift.joss.client.factory.AccountConfig;
import org.javaswift.joss.client.factory.AccountFactory;
import org.javaswift.joss.client.factory.AuthenticationMethod;
import org.javaswift.joss.model.Account;
import org.javaswift.joss.model.Container;
import org.javaswift.joss.model.StoredObject;

import java.io.File;
import java.util.Map;

/**
 * Created by raja on 04-05-2017.
 */
public class OpenStackSwiftTest {
    public static void main(String[] args) {
        //create config
        AccountConfig config = new AccountConfig();
        config.setAuthUrl("myhosting.url/auth/v1.0/");
        config.setAuthenticationMethod(AuthenticationMethod.BASIC);
        config.setUsername("admin");
        config.setPassword("PasswordDuh");
        config.setHashPassword("blah"); //The API documentation insists this

        //create account from config
        Account account = new AccountFactory(config).createAccount();

        Map<String, Object> metadata1 = account.getMetadata();
        metadata1.forEach((s, o) -> {
            System.out.println(s+":"+o);
        });

        Container container = account.getContainer("mycontainer");


        //open a stored object handle
        StoredObject storedObject = container.getObject("TEST.txt");

        //upload something
        storedObject.uploadObject("Hello World!!".getBytes());

        //get the temporary URL.
        String tempGetUrl = storedObject.getTempGetUrl(1000);

        System.out.println(tempGetUrl);

    }
}

The above code prints something like the following

Quota-Bytes:107374182400
Temp-Url-Key:blah
myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt?temp_url_sig=5e38222a1b74fe1ae874a946ccb6f4cce043dcdb&temp_url_expires=1501517432

When I try to access the URL, I'm getting 401 Unauthorized: Temp URL invalid

However, when I run the below command, The generated URL can be accessed directly on the browser and the content gets downloaded.

swift tempurl GET 60 myhosting.url/v1/AUTH_admin/mycontainer/TEST.txt blah -U admin -K PasswordDuh

Here is the server configuration when I do a stat

                          StorageURL: myhosting.url/v1/AUTH_admin
                          Auth Token: AUTH_tkbd65506826b12317a7a3e03e0f547c78
                             Account: AUTH_admin
                          Containers: 10
                             Objects: 147553
                               Bytes: 26544582500
Containers in policy "del-resilient": 1
   Objects in policy "del-resilient": 571
     Bytes in policy "del-resilient": 12312
                    Meta Quota-Bytes: 4182400
                   Meta Temp-Url-Key: blah
              X-Openstack-Request-Id: tx69915eb0be0f43e89333e-00597f525c
                       Accept-Ranges: bytes
                          Connection: Keep-alive
                                 Via: 1.1 ID-0314217254230750 uproxy-3
                         X-Timestamp: 1493105849.12206
                          X-Trans-Id: tx69915eb03456u3e89222e-00597f525c
                        Content-Type: text/plain; charset=utf-8

What am I missing in my Java code? The below is the joss dependency

   <dependency>
      <groupId>org.javaswift</groupId>
      <artifactId>joss</artifactId>
      <version>0.9.15</version>
    </dependency>
Raja Anbazhagan
  • 4,092
  • 1
  • 44
  • 64

1 Answers1

0

It is a bug. The solution is here: https://github.com/javaswift/joss/pull/90/commits/105f70c8d4a3409b5de3504ba3eb07444f8b607c

It is a pull request, but it is not approved yet.

kosbr
  • 388
  • 2
  • 11