Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

storedObject.getTempGetUrl(Long seconds) always generates invalid URL #136

Open
raja-anbazhagan opened this issue Aug 1, 2017 · 1 comment

Comments

@raja-anbazhagan
Copy link

raja-anbazhagan commented Aug 1, 2017

Here is how to regenerate the issue

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("https://blr1.ipstorage.tatacommunications.com/auth/v1.0/");
        config.setAuthenticationMethod(AuthenticationMethod.BASIC);
        config.setUsername("admin");
        config.setPassword("admin");
        config.setHashPassword("secret");

        //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);
        });
       // account.saveMetadata();
        //get the container
        Container container = account.getContainer("my-container");


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

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

        String tempGetUrl = storedObject.getTempGetUrl(24*60*60);

        System.out.println(tempGetUrl);

    }
}

The output from the debug logs of the above program is
2017-08-01 14:29:11 DEBUG TempURL:44 - Text to hash for the signature (CRLF replaced by readable \n): GETn1501664401nhttps://my.full.url/v1/AUTH_admin/my-container/TEST

Here you can see that the full url is used to create the hash. however, The example in the this documentaion, only the relative path of the resource is used to generate the Hash.

The following method under TempURL.java may need changes as per my understanding.

 protected String getSignaturePlainText() {
        // Note that we're not making use here of the standard getPath() because we don't want the URL encoded names,
        // but the pure names. Swift uses the same approach to compose a signature plaintext with container/object names.
        String objectPath = this.prefix + "/" + this.object.getContainer().getName() + "/" + this.object.getName();
        return this.method + "\n" + this.expiry + "\n" + objectPath;
    }
@ferrys
Copy link
Contributor

ferrys commented Sep 13, 2017

Hi @raja-anbazhagan, I've run into this issue before and I'm going to work on fixing it. I see some other related issues, such as issue #102 and PR #90 so there might be a solution there if you're desperate for a fix now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants